@tonappchain/sdk 0.5.6 → 0.6.1-v3.0.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.
Files changed (49) hide show
  1. package/LICENSE +20 -20
  2. package/README.md +189 -1276
  3. package/package.json +67 -67
  4. package/dist/adapters/contractOpener.d.ts +0 -19
  5. package/dist/adapters/contractOpener.js +0 -94
  6. package/dist/errors/errors.d.ts +0 -34
  7. package/dist/errors/errors.js +0 -80
  8. package/dist/errors/index.d.ts +0 -2
  9. package/dist/errors/index.js +0 -30
  10. package/dist/errors/instances.d.ts +0 -16
  11. package/dist/errors/instances.js +0 -28
  12. package/dist/index.d.ts +0 -10
  13. package/dist/index.js +0 -35
  14. package/dist/sdk/Consts.d.ts +0 -6
  15. package/dist/sdk/Consts.js +0 -10
  16. package/dist/sdk/OperationTracker.d.ts +0 -14
  17. package/dist/sdk/OperationTracker.js +0 -151
  18. package/dist/sdk/StartTracking.d.ts +0 -8
  19. package/dist/sdk/StartTracking.js +0 -126
  20. package/dist/sdk/TacSdk.d.ts +0 -36
  21. package/dist/sdk/TacSdk.js +0 -364
  22. package/dist/sdk/Utils.d.ts +0 -18
  23. package/dist/sdk/Utils.js +0 -126
  24. package/dist/sender/RawSender.d.ts +0 -13
  25. package/dist/sender/RawSender.js +0 -37
  26. package/dist/sender/SenderAbstraction.d.ts +0 -19
  27. package/dist/sender/SenderAbstraction.js +0 -5
  28. package/dist/sender/SenderFactory.d.ts +0 -33
  29. package/dist/sender/SenderFactory.js +0 -55
  30. package/dist/sender/TonConnectSender.d.ts +0 -11
  31. package/dist/sender/TonConnectSender.js +0 -33
  32. package/dist/sender/index.d.ts +0 -2
  33. package/dist/sender/index.js +0 -18
  34. package/dist/structs/InternalStruct.d.ts +0 -54
  35. package/dist/structs/InternalStruct.js +0 -8
  36. package/dist/structs/Struct.d.ts +0 -227
  37. package/dist/structs/Struct.js +0 -38
  38. package/dist/wrappers/ContentUtils.d.ts +0 -25
  39. package/dist/wrappers/ContentUtils.js +0 -160
  40. package/dist/wrappers/HighloadQueryId.d.ts +0 -17
  41. package/dist/wrappers/HighloadQueryId.js +0 -72
  42. package/dist/wrappers/HighloadWalletV3.d.ts +0 -61
  43. package/dist/wrappers/HighloadWalletV3.js +0 -161
  44. package/dist/wrappers/JettonMaster.d.ts +0 -24
  45. package/dist/wrappers/JettonMaster.js +0 -53
  46. package/dist/wrappers/JettonWallet.d.ts +0 -46
  47. package/dist/wrappers/JettonWallet.js +0 -103
  48. package/dist/wrappers/Settings.d.ts +0 -10
  49. package/dist/wrappers/Settings.js +0 -38
@@ -1,55 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SenderFactory = exports.wallets = void 0;
4
- const ton_1 = require("@ton/ton");
5
- const ton_crypto_1 = require("ton-crypto");
6
- const RawSender_1 = require("./RawSender");
7
- const TonConnectSender_1 = require("./TonConnectSender");
8
- const errors_1 = require("../errors");
9
- const Struct_1 = require("../structs/Struct");
10
- const HighloadWalletV3_1 = require("../wrappers/HighloadWalletV3");
11
- exports.wallets = {
12
- V2R1: ton_1.WalletContractV2R1,
13
- V2R2: ton_1.WalletContractV2R2,
14
- V3R1: ton_1.WalletContractV3R1,
15
- V3R2: ton_1.WalletContractV3R2,
16
- V4: ton_1.WalletContractV4,
17
- V5R1: ton_1.WalletContractV5R1,
18
- HIGHLOAD_V3: HighloadWalletV3_1.HighloadWalletV3,
19
- };
20
- class SenderFactory {
21
- static async getSender(params) {
22
- if ('tonConnect' in params) {
23
- return new TonConnectSender_1.TonConnectSender(params.tonConnect);
24
- }
25
- if (!(params.version in exports.wallets)) {
26
- throw (0, errors_1.unknownWalletError)(params.version);
27
- }
28
- const keypair = await (0, ton_crypto_1.mnemonicToWalletKey)(params.mnemonic.split(' '));
29
- const config = {
30
- workchain: 0,
31
- publicKey: keypair.publicKey,
32
- walletId: undefined, // for w5
33
- subwalletId: undefined, // for highload v3
34
- timeout: undefined, // for highload v3
35
- };
36
- if (params.version === 'V5R1') {
37
- // manual setup of wallet id required to support wallet w5 both on mainnet and testnet
38
- config.walletId = {
39
- networkGlobalId: params.network === Struct_1.Network.TESTNET ? -3 : -239,
40
- context: {
41
- walletVersion: 'v5r1',
42
- workchain: 0,
43
- subwalletNumber: params.options?.v5r1?.subwalletNumber ?? 0,
44
- },
45
- };
46
- }
47
- if (params.version === 'HIGHLOAD_V3') {
48
- config.subwalletId = params.options?.highloadV3?.subwalletId ?? HighloadWalletV3_1.DEFAULT_SUBWALLET_ID;
49
- config.timeout = params.options?.highloadV3?.timeout ?? HighloadWalletV3_1.DEFAULT_TIMEOUT;
50
- }
51
- const wallet = exports.wallets[params.version].create(config);
52
- return new RawSender_1.RawSender(wallet, keypair.secretKey);
53
- }
54
- }
55
- exports.SenderFactory = SenderFactory;
@@ -1,11 +0,0 @@
1
- import { TonConnectUI } from '@tonconnect/ui';
2
- import type { ShardTransaction } from '../structs/InternalStruct';
3
- import { Network } from '../structs/Struct';
4
- import { SenderAbstraction } from './SenderAbstraction';
5
- import { SendTransactionResponse } from '@tonconnect/sdk';
6
- export declare class TonConnectSender implements SenderAbstraction {
7
- readonly tonConnect: TonConnectUI;
8
- constructor(tonConnect: TonConnectUI);
9
- getSenderAddress(): string;
10
- sendShardTransaction(shardTransaction: ShardTransaction, delay: number, chain: Network): Promise<SendTransactionResponse>;
11
- }
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TonConnectSender = void 0;
4
- const protocol_1 = require("@tonconnect/protocol");
5
- const ui_1 = require("@tonconnect/ui");
6
- const Struct_1 = require("../structs/Struct");
7
- const SenderAbstraction_1 = require("./SenderAbstraction");
8
- class TonConnectSender {
9
- constructor(tonConnect) {
10
- this.tonConnect = tonConnect;
11
- }
12
- getSenderAddress() {
13
- return this.tonConnect.account?.address?.toString() || '';
14
- }
15
- async sendShardTransaction(shardTransaction, delay, chain) {
16
- const messages = [];
17
- for (const message of shardTransaction.messages) {
18
- messages.push({
19
- address: message.address,
20
- amount: message.value.toString(),
21
- payload: protocol_1.Base64.encode(message.payload.toBoc()).toString(),
22
- });
23
- }
24
- const transaction = {
25
- validUntil: shardTransaction.validUntil,
26
- messages,
27
- network: chain == Struct_1.Network.TESTNET ? ui_1.CHAIN.TESTNET : ui_1.CHAIN.MAINNET,
28
- };
29
- await (0, SenderAbstraction_1.sleep)(delay * 1000);
30
- return this.tonConnect.sendTransaction(transaction);
31
- }
32
- }
33
- exports.TonConnectSender = TonConnectSender;
@@ -1,2 +0,0 @@
1
- export * from './SenderAbstraction';
2
- export * from './SenderFactory';
@@ -1,18 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./SenderAbstraction"), exports);
18
- __exportStar(require("./SenderFactory"), exports);
@@ -1,54 +0,0 @@
1
- import { Cell } from '@ton/ton';
2
- import { ContractOpener, TACSimulationResults, ExecutionStagesByOperationId, Network, OperationIdsByShardsKey, RawAssetBridgingData, StatusInfosByOperationId, OperationType } from './Struct';
3
- import { AbstractProvider, ethers, Interface, InterfaceAbi } from 'ethers';
4
- export type ShardMessage = {
5
- address: string;
6
- value: bigint;
7
- payload: Cell;
8
- };
9
- export type ShardTransaction = {
10
- validUntil: number;
11
- messages: ShardMessage[];
12
- network: Network;
13
- };
14
- export declare enum AssetOpType {
15
- JETTON_BURN = "JETTON_BURN",
16
- JETTON_TRANSFER = "JETTON_TRANSFER"
17
- }
18
- export type RandomNumberByTimestamp = {
19
- timestamp: number;
20
- randomNumber: number;
21
- };
22
- export type JettonBridgingData = RawAssetBridgingData & {
23
- address: string;
24
- };
25
- export type JettonTransferData = JettonBridgingData;
26
- export type JettonBurnData = JettonBridgingData & {
27
- notificationReceiverAddress: string;
28
- };
29
- export type InternalTONParams = {
30
- contractOpener: ContractOpener;
31
- jettonProxyAddress: string;
32
- crossChainLayerAddress: string;
33
- jettonMinterCode: Cell;
34
- jettonWalletCode: Cell;
35
- };
36
- export type InternalTACParams = {
37
- provider: AbstractProvider;
38
- settingsAddress: string;
39
- tokenUtilsAddress: string;
40
- abiCoder: ethers.AbiCoder;
41
- crossChainLayerABI: Interface | InterfaceAbi;
42
- crossChainLayerAddress: string;
43
- crossChainLayerTokenABI: Interface | InterfaceAbi;
44
- crossChainLayerTokenBytecode: string;
45
- };
46
- export type ResponseBase<T> = {
47
- response: T;
48
- };
49
- export type StringResponse = ResponseBase<string>;
50
- export type OperationTypeResponse = ResponseBase<OperationType>;
51
- export type StatusesResponse = ResponseBase<StatusInfosByOperationId>;
52
- export type OperationIdsByShardsKeyResponse = ResponseBase<OperationIdsByShardsKey>;
53
- export type StageProfilingResponse = ResponseBase<ExecutionStagesByOperationId>;
54
- export type TACSimulationResponse = ResponseBase<TACSimulationResults>;
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetOpType = void 0;
4
- var AssetOpType;
5
- (function (AssetOpType) {
6
- AssetOpType["JETTON_BURN"] = "JETTON_BURN";
7
- AssetOpType["JETTON_TRANSFER"] = "JETTON_TRANSFER";
8
- })(AssetOpType || (exports.AssetOpType = AssetOpType = {}));
@@ -1,227 +0,0 @@
1
- import { SandboxContract } from '@ton/sandbox';
2
- import type { Address, Contract, OpenedContract } from '@ton/ton';
3
- import { AbstractProvider, Addressable, Interface, InterfaceAbi } from 'ethers';
4
- export interface ContractOpener {
5
- open<T extends Contract>(src: T): OpenedContract<T> | SandboxContract<T>;
6
- getContractState(address: Address): Promise<{
7
- balance: bigint;
8
- state: 'active' | 'uninitialized' | 'frozen';
9
- code: Buffer | null;
10
- }>;
11
- closeConnections?: () => unknown;
12
- }
13
- export declare enum SimplifiedStatuses {
14
- PENDING = "PENDING",
15
- FAILED = "FAILED",
16
- SUCCESSFUL = "SUCCESSFUL",
17
- OPERATION_ID_NOT_FOUND = "OPERATION_ID_NOT_FOUND"
18
- }
19
- export declare enum Network {
20
- TESTNET = "testnet",
21
- MAINNET = "mainnet"
22
- }
23
- export declare enum BlockchainType {
24
- TAC = "TAC",
25
- TON = "TON"
26
- }
27
- export declare enum OperationType {
28
- PENDING = "PENDING",
29
- TON_TAC_TON = "TON-TAC-TON",
30
- ROLLBACK = "ROLLBACK",
31
- TON_TAC = "TON-TAC",
32
- TAC_TON = "TAC-TON",
33
- UNKNOWN = "UNKNOWN"
34
- }
35
- export type TACParams = {
36
- /**
37
- * Provider for TAC side. Use your own provider for tests or to increase ratelimit
38
- */
39
- provider?: AbstractProvider;
40
- /**
41
- * Address of TAC settings contract. Use only for tests.
42
- */
43
- settingsAddress?: string | Addressable;
44
- /**
45
- * ABI of TAC settings contract. Use only for tests.
46
- */
47
- settingsABI?: Interface | InterfaceAbi;
48
- /**
49
- * ABI of TAC CCL contract. Use only for tests.
50
- */
51
- crossChainLayerABI?: Interface | InterfaceAbi;
52
- /**
53
- * ABI of TAC CrossChainLayerToken contract. Use only for tests.
54
- */
55
- crossChainLayerTokenABI?: Interface | InterfaceAbi;
56
- /**
57
- * bytecode of TAC CrossChainLayerToken contract. Use only for tests.
58
- */
59
- crossChainLayerTokenBytecode?: string;
60
- };
61
- export type TONParams = {
62
- /**
63
- * Provider for TON side. Use your own provider for tests or to increase ratelimit
64
- */
65
- contractOpener?: ContractOpener;
66
- /**
67
- * Address of TON settings contract. Use only for tests.
68
- */
69
- settingsAddress?: string;
70
- };
71
- export type SDKParams = {
72
- /**
73
- * TON CHAIN. For your network use Сustom
74
- */
75
- network: Network;
76
- /**
77
- * Delay in requests to provider
78
- */
79
- delay?: number;
80
- /**
81
- * Custom parameters for the TAC blockchain
82
- */
83
- TACParams?: TACParams;
84
- /**
85
- * Custom parameters for the TON blockchain
86
- */
87
- TONParams?: TONParams;
88
- /**
89
- * URLs of lite sequencers
90
- */
91
- customLiteSequencerEndpoints?: string[];
92
- };
93
- export type WithAddress = {
94
- /**
95
- * Address of TAC or TON token.
96
- * Empty if sending native TON coin.
97
- */
98
- address?: string;
99
- };
100
- export type RawAssetBridgingData = {
101
- /** Raw format, e.g. 12340000000 (=12.34 tokens if decimals is 9) */
102
- rawAmount: bigint;
103
- } & WithAddress;
104
- export type UserFriendlyAssetBridgingData = {
105
- /**
106
- * User friendly format, e.g. 12.34 tokens
107
- * Specified value will be converted automatically to raw format: 12.34 * (10^decimals).
108
- * No decimals should be specified.
109
- */
110
- amount: number;
111
- /**
112
- * Decimals may be specified manually.
113
- * Otherwise, SDK tries to extract them from chain.
114
- */
115
- decimals?: number;
116
- } & WithAddress;
117
- export type AssetBridgingData = RawAssetBridgingData | UserFriendlyAssetBridgingData;
118
- export type UserWalletBalanceExtended = {
119
- exists: true;
120
- amount: number;
121
- rawAmount: bigint;
122
- decimals: number;
123
- } | {
124
- exists: false;
125
- };
126
- export type EvmProxyMsg = {
127
- evmTargetAddress: string;
128
- methodName?: string;
129
- encodedParameters?: string;
130
- gasLimit?: bigint;
131
- };
132
- export type TransactionLinker = {
133
- caller: string;
134
- shardCount: number;
135
- shardsKey: string;
136
- timestamp: number;
137
- sendTransactionResult?: unknown;
138
- };
139
- export type TACSimulationRequest = {
140
- tacCallParams: {
141
- arguments: string;
142
- methodName: string;
143
- target: string;
144
- };
145
- extraData: string;
146
- feeAssetAddress: string;
147
- shardsKey: string;
148
- tonAssets: {
149
- amount: string;
150
- tokenAddress: string;
151
- }[];
152
- tonCaller: string;
153
- };
154
- export declare enum StageName {
155
- COLLECTED_IN_TAC = "collectedInTAC",
156
- INCLUDED_IN_TAC_CONSENSUS = "includedInTACConsensus",
157
- EXECUTED_IN_TAC = "executedInTAC",
158
- COLLECTED_IN_TON = "collectedInTON",
159
- INCLUDED_IN_TON_CONSENSUS = "includedInTONConsensus",
160
- EXECUTED_IN_TON = "executedInTON"
161
- }
162
- export type TransactionData = {
163
- hash: string;
164
- blockchainType: BlockchainType;
165
- };
166
- export type NoteInfo = {
167
- content: string;
168
- errorName: string;
169
- internalMsg: string;
170
- internalBytesError: string;
171
- };
172
- export type StageData = {
173
- success: boolean;
174
- timestamp: number;
175
- transactions: TransactionData[] | null;
176
- note: NoteInfo | null;
177
- };
178
- export type StatusInfo = StageData & {
179
- stage: StageName;
180
- };
181
- export type ProfilingStageData = {
182
- exists: boolean;
183
- stageData: StageData | null;
184
- };
185
- export type ExecutionStages = {
186
- operationType: OperationType;
187
- } & Record<StageName, ProfilingStageData>;
188
- export type ExecutionStagesByOperationId = Record<string, ExecutionStages>;
189
- export type StatusInfosByOperationId = Record<string, StatusInfo>;
190
- export type OperationIds = {
191
- operationIds: string[];
192
- };
193
- export type OperationIdsByShardsKey = Record<string, OperationIds>;
194
- export type TACSimulationResults = {
195
- estimatedGas: bigint;
196
- estimatedJettonFeeAmount: string;
197
- feeParams: {
198
- currentBaseFee: string;
199
- isEip1559: boolean;
200
- suggestedGasPrice: string;
201
- suggestedGasTip: string;
202
- };
203
- message: string;
204
- outMessages: {
205
- callerAddress: string;
206
- operationId: string;
207
- payload: string;
208
- queryId: number;
209
- targetAddress: string;
210
- tokensBurned: {
211
- amount: string;
212
- tokenAddress: string;
213
- }[];
214
- tokensLocked: {
215
- amount: string;
216
- tokenAddress: string;
217
- }[];
218
- }[] | null;
219
- simulationError: string;
220
- simulationStatus: boolean;
221
- debugInfo: {
222
- from: string;
223
- to: string;
224
- callData: string;
225
- blockNumber: number;
226
- };
227
- };
@@ -1,38 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.StageName = exports.OperationType = exports.BlockchainType = exports.Network = exports.SimplifiedStatuses = void 0;
4
- var SimplifiedStatuses;
5
- (function (SimplifiedStatuses) {
6
- SimplifiedStatuses["PENDING"] = "PENDING";
7
- SimplifiedStatuses["FAILED"] = "FAILED";
8
- SimplifiedStatuses["SUCCESSFUL"] = "SUCCESSFUL";
9
- SimplifiedStatuses["OPERATION_ID_NOT_FOUND"] = "OPERATION_ID_NOT_FOUND";
10
- })(SimplifiedStatuses || (exports.SimplifiedStatuses = SimplifiedStatuses = {}));
11
- var Network;
12
- (function (Network) {
13
- Network["TESTNET"] = "testnet";
14
- Network["MAINNET"] = "mainnet";
15
- })(Network || (exports.Network = Network = {}));
16
- var BlockchainType;
17
- (function (BlockchainType) {
18
- BlockchainType["TAC"] = "TAC";
19
- BlockchainType["TON"] = "TON";
20
- })(BlockchainType || (exports.BlockchainType = BlockchainType = {}));
21
- var OperationType;
22
- (function (OperationType) {
23
- OperationType["PENDING"] = "PENDING";
24
- OperationType["TON_TAC_TON"] = "TON-TAC-TON";
25
- OperationType["ROLLBACK"] = "ROLLBACK";
26
- OperationType["TON_TAC"] = "TON-TAC";
27
- OperationType["TAC_TON"] = "TAC-TON";
28
- OperationType["UNKNOWN"] = "UNKNOWN";
29
- })(OperationType || (exports.OperationType = OperationType = {}));
30
- var StageName;
31
- (function (StageName) {
32
- StageName["COLLECTED_IN_TAC"] = "collectedInTAC";
33
- StageName["INCLUDED_IN_TAC_CONSENSUS"] = "includedInTACConsensus";
34
- StageName["EXECUTED_IN_TAC"] = "executedInTAC";
35
- StageName["COLLECTED_IN_TON"] = "collectedInTON";
36
- StageName["INCLUDED_IN_TON_CONSENSUS"] = "includedInTONConsensus";
37
- StageName["EXECUTED_IN_TON"] = "executedInTON";
38
- })(StageName || (exports.StageName = StageName = {}));
@@ -1,25 +0,0 @@
1
- import { Cell } from '@ton/ton';
2
- export declare const ONCHAIN_CONTENT_PREFIX = 0;
3
- export declare const OFFCHAIN_CONTENT_PREFIX = 1;
4
- export interface JettonMetadata {
5
- uri?: string;
6
- name: string;
7
- description: string;
8
- image?: string;
9
- image_data?: string;
10
- symbol: string;
11
- decimals?: string;
12
- }
13
- export type JettonExtendedMetadata = {
14
- persistenceType: persistenceType;
15
- metadata: {
16
- [s in JettonMetaDataKeys]?: string;
17
- };
18
- isJettonDeployerFaultyOnChainData?: boolean;
19
- contentUri?: string;
20
- };
21
- export declare function buildJettonOffChainMetadata(contentUri: string): Cell;
22
- export type JettonMetaDataKeys = 'uri' | 'name' | 'description' | 'image' | 'symbol' | 'image_data' | 'decimals';
23
- export declare function buildJettonOnchainMetadata(data: JettonMetadata): Cell;
24
- export type persistenceType = 'none' | 'onchain' | 'offchain_private_domain' | 'offchain_ipfs';
25
- export declare function readJettonMetadata(contentCell: Cell): Promise<JettonExtendedMetadata>;
@@ -1,160 +0,0 @@
1
- "use strict";
2
- // noinspection TypeScriptValidateTypes
3
- var __importDefault = (this && this.__importDefault) || function (mod) {
4
- return (mod && mod.__esModule) ? mod : { "default": mod };
5
- };
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.OFFCHAIN_CONTENT_PREFIX = exports.ONCHAIN_CONTENT_PREFIX = void 0;
8
- exports.buildJettonOffChainMetadata = buildJettonOffChainMetadata;
9
- exports.buildJettonOnchainMetadata = buildJettonOnchainMetadata;
10
- exports.readJettonMetadata = readJettonMetadata;
11
- const sha256_js_1 = require("@aws-crypto/sha256-js");
12
- const ton_1 = require("@ton/ton");
13
- const axios_1 = __importDefault(require("axios"));
14
- const bn_js_1 = __importDefault(require("bn.js"));
15
- const errors_1 = require("../errors");
16
- exports.ONCHAIN_CONTENT_PREFIX = 0x00;
17
- exports.OFFCHAIN_CONTENT_PREFIX = 0x01;
18
- const SNAKE_PREFIX = 0x00;
19
- function buildJettonOffChainMetadata(contentUri) {
20
- return (0, ton_1.beginCell)().storeInt(exports.OFFCHAIN_CONTENT_PREFIX, 8).storeBuffer(Buffer.from(contentUri, 'ascii')).endCell();
21
- }
22
- const jettonOnChainMetadataSpec = {
23
- uri: 'ascii',
24
- name: 'utf8',
25
- description: 'utf8',
26
- image: 'ascii',
27
- image_data: 'ascii',
28
- symbol: 'utf8',
29
- decimals: 'utf8',
30
- };
31
- const sha256 = (str) => {
32
- const sha = new sha256_js_1.Sha256();
33
- sha.update(str);
34
- return Buffer.from(sha.digestSync());
35
- };
36
- function storeSnakeContent(content, isFirst) {
37
- const CELL_MAX_SIZE_BYTES = Math.floor((1023 - 8) / 8);
38
- const cell = new ton_1.Builder();
39
- if (isFirst) {
40
- cell.storeUint(SNAKE_PREFIX, 8);
41
- }
42
- cell.storeBuffer(content.subarray(0, CELL_MAX_SIZE_BYTES));
43
- const remainingContent = content.subarray(CELL_MAX_SIZE_BYTES);
44
- if (remainingContent.length > 0) {
45
- cell.storeRef(storeSnakeContent(remainingContent, false));
46
- }
47
- return cell.endCell();
48
- }
49
- function buildJettonOnchainMetadata(data) {
50
- const dict = ton_1.Dictionary.empty();
51
- Object.entries(data).forEach(([k, v]) => {
52
- if (!jettonOnChainMetadataSpec[k]) {
53
- throw (0, errors_1.unsupportedKeyError)(k);
54
- }
55
- if (!v || v == '' || v == null) {
56
- return;
57
- }
58
- const bufferToStore = Buffer.from(v, jettonOnChainMetadataSpec[k]);
59
- dict.set(sha256(k), storeSnakeContent(bufferToStore, true));
60
- });
61
- return (0, ton_1.beginCell)()
62
- .storeInt(exports.ONCHAIN_CONTENT_PREFIX, 8)
63
- .storeDict(dict, ton_1.Dictionary.Keys.Buffer(32), ton_1.Dictionary.Values.Cell())
64
- .endCell();
65
- }
66
- function readSnakeContent(slice, isFirst) {
67
- if (isFirst && slice.loadUint(8) !== SNAKE_PREFIX) {
68
- throw errors_1.unsupportedFormatError;
69
- }
70
- if (slice.remainingBits % 8 !== 0) {
71
- throw errors_1.notMultiplyOf8Error;
72
- }
73
- let remainingBytes = Buffer.from('');
74
- if (slice.remainingBits != 0) {
75
- remainingBytes = slice.loadBuffer(slice.remainingBits / 8);
76
- }
77
- if (slice.remainingRefs != 0) {
78
- const newCell = slice.loadRef();
79
- remainingBytes = Buffer.concat([remainingBytes, readSnakeContent(newCell.beginParse(), false)]);
80
- }
81
- return remainingBytes;
82
- }
83
- function parseJettonOnchainMetadata(contentSlice) {
84
- // Note that this relies on what is (perhaps) an internal implementation detail:
85
- // "sdk" library dict parser converts: key (provided as buffer) => BN(base10)
86
- // and upon parsing, it reads it back to a BN(base10)
87
- // tl;dr if we want to read the map back to a JSON with string keys, we have to convert BN(10) back to hex
88
- const toKey = (str) => BigInt(new bn_js_1.default(str, 'hex').toString(10));
89
- const isJettonDeployerFaultyOnChainData = false;
90
- const cellDict = contentSlice.loadDict(ton_1.Dictionary.Keys.BigUint(256), ton_1.Dictionary.Values.Cell());
91
- const dict = new Map();
92
- cellDict.values().forEach((item, index) => {
93
- dict.set(cellDict.keys()[index], readSnakeContent(item.beginParse(), true));
94
- });
95
- const res = {};
96
- Object.keys(jettonOnChainMetadataSpec).forEach((k) => {
97
- const val = dict
98
- .get(toKey(sha256(k).toString('hex')))
99
- ?.toString(jettonOnChainMetadataSpec[k]);
100
- if (val) {
101
- res[k] = val;
102
- }
103
- });
104
- return {
105
- metadata: res,
106
- isJettonDeployerFaultyOnChainData,
107
- };
108
- }
109
- async function parseJettonOffchainMetadata(contentSlice) {
110
- const remainingBits = contentSlice.remainingBits;
111
- if (remainingBits % 8 !== 0) {
112
- throw errors_1.notMultiplyOf8Error;
113
- }
114
- const jsonURI = contentSlice
115
- .loadBuffer(remainingBits / 8)
116
- .toString('ascii')
117
- .replace('ipfs://', 'https://ipfs.io/ipfs/');
118
- let metadata = null;
119
- let isIpfs = null;
120
- try {
121
- metadata = (await axios_1.default.get(jsonURI)).data;
122
- isIpfs = /(^|\/)ipfs[.:]/.test(jsonURI);
123
- }
124
- catch {
125
- // nothing
126
- }
127
- return {
128
- metadata,
129
- isIpfs,
130
- contentUri: jsonURI,
131
- };
132
- }
133
- async function readJettonMetadata(contentCell) {
134
- if (contentCell.bits.length <= 0) {
135
- return {
136
- contentUri: undefined,
137
- isJettonDeployerFaultyOnChainData: false,
138
- metadata: {},
139
- persistenceType: 'none',
140
- };
141
- }
142
- const contentSlice = contentCell.beginParse();
143
- switch (contentSlice.loadUint(8)) {
144
- case exports.ONCHAIN_CONTENT_PREFIX:
145
- return {
146
- persistenceType: 'onchain',
147
- ...parseJettonOnchainMetadata(contentSlice),
148
- };
149
- case exports.OFFCHAIN_CONTENT_PREFIX: {
150
- const { metadata, isIpfs, contentUri } = await parseJettonOffchainMetadata(contentSlice);
151
- return {
152
- persistenceType: isIpfs ? 'offchain_ipfs' : 'offchain_private_domain',
153
- contentUri,
154
- metadata,
155
- };
156
- }
157
- default:
158
- throw errors_1.prefixError;
159
- }
160
- }
@@ -1,17 +0,0 @@
1
- export declare class HighloadQueryId {
2
- private shift;
3
- private bitnumber;
4
- constructor();
5
- static fromShiftAndBitNumber(shift: bigint, bitnumber: bigint): HighloadQueryId;
6
- getNext(): HighloadQueryId;
7
- hasNext(): boolean;
8
- getShift(): bigint;
9
- getBitNumber(): bigint;
10
- getQueryId(): bigint;
11
- static fromQueryId(queryId: bigint): HighloadQueryId;
12
- static fromSeqno(i: bigint): HighloadQueryId;
13
- /**
14
- * @return {bigint} [0 .. 8380415]
15
- */
16
- toSeqno(): bigint;
17
- }