@tonclient/core
Version:
TON Client for Java Script
1,332 lines • 103 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.processingEventWillFetchNextBlock = exports.processingEventSendFailed = exports.processingEventDidSend = exports.processingEventWillSend = exports.processingEventFetchFirstBlockFailed = exports.processingEventWillFetchFirstBlock = exports.ProcessingErrorCode = exports.BocModule = exports.builderOpAddress = exports.builderOpCellBoc = exports.builderOpCell = exports.builderOpBitString = exports.builderOpInteger = exports.BocErrorCode = exports.bocCacheTypeUnpinned = exports.bocCacheTypePinned = exports.AbiModule = exports.messageSourceEncodingParams = exports.messageSourceEncoded = exports.stateInitSourceTvc = exports.stateInitSourceStateInit = exports.stateInitSourceMessage = exports.MessageBodyType = exports.signerSigningBox = exports.signerKeys = exports.signerExternal = exports.signerNone = exports.abiSerialized = exports.abiHandle = exports.abiJson = exports.abiContract = exports.AbiErrorCode = exports.CryptoModule = exports.resultOfAppEncryptionBoxDecrypt = exports.resultOfAppEncryptionBoxEncrypt = exports.resultOfAppEncryptionBoxGetInfo = exports.paramsOfAppEncryptionBoxDecrypt = exports.paramsOfAppEncryptionBoxEncrypt = exports.paramsOfAppEncryptionBoxGetInfo = exports.resultOfAppSigningBoxSign = exports.resultOfAppSigningBoxGetPublicKey = exports.paramsOfAppSigningBoxSign = exports.paramsOfAppSigningBoxGetPublicKey = exports.CipherMode = exports.encryptionAlgorithmAES = exports.CryptoErrorCode = exports.ClientModule = exports.appRequestResultOk = exports.appRequestResultError = exports.ClientErrorCode = void 0;
exports.ProofsModule = exports.ProofsErrorCode = exports.DebotModule = exports.resultOfAppDebotBrowserApprove = exports.resultOfAppDebotBrowserInvokeDebot = exports.resultOfAppDebotBrowserGetSigningBox = exports.resultOfAppDebotBrowserInput = exports.paramsOfAppDebotBrowserApprove = exports.paramsOfAppDebotBrowserSend = exports.paramsOfAppDebotBrowserInvokeDebot = exports.paramsOfAppDebotBrowserGetSigningBox = exports.paramsOfAppDebotBrowserInput = exports.paramsOfAppDebotBrowserShowAction = exports.paramsOfAppDebotBrowserSwitchCompleted = exports.paramsOfAppDebotBrowserSwitch = exports.paramsOfAppDebotBrowserLog = exports.debotActivityTransaction = exports.DebotErrorCode = exports.NetModule = exports.AggregationFn = exports.paramsOfQueryOperationQueryCounterparties = exports.paramsOfQueryOperationAggregateCollection = exports.paramsOfQueryOperationWaitForCollection = exports.paramsOfQueryOperationQueryCollection = exports.SortDirection = exports.NetErrorCode = exports.TvmModule = exports.accountForExecutorAccount = exports.accountForExecutorUninit = exports.accountForExecutorNone = exports.TvmErrorCode = exports.UtilsModule = exports.AccountAddressType = exports.addressStringFormatBase64 = exports.addressStringFormatHex = exports.addressStringFormatAccountId = exports.ProcessingModule = exports.processingEventMessageExpired = exports.processingEventFetchNextBlockFailed = void 0;
// client module
var ClientErrorCode;
(function (ClientErrorCode) {
ClientErrorCode[ClientErrorCode["NotImplemented"] = 1] = "NotImplemented";
ClientErrorCode[ClientErrorCode["InvalidHex"] = 2] = "InvalidHex";
ClientErrorCode[ClientErrorCode["InvalidBase64"] = 3] = "InvalidBase64";
ClientErrorCode[ClientErrorCode["InvalidAddress"] = 4] = "InvalidAddress";
ClientErrorCode[ClientErrorCode["CallbackParamsCantBeConvertedToJson"] = 5] = "CallbackParamsCantBeConvertedToJson";
ClientErrorCode[ClientErrorCode["WebsocketConnectError"] = 6] = "WebsocketConnectError";
ClientErrorCode[ClientErrorCode["WebsocketReceiveError"] = 7] = "WebsocketReceiveError";
ClientErrorCode[ClientErrorCode["WebsocketSendError"] = 8] = "WebsocketSendError";
ClientErrorCode[ClientErrorCode["HttpClientCreateError"] = 9] = "HttpClientCreateError";
ClientErrorCode[ClientErrorCode["HttpRequestCreateError"] = 10] = "HttpRequestCreateError";
ClientErrorCode[ClientErrorCode["HttpRequestSendError"] = 11] = "HttpRequestSendError";
ClientErrorCode[ClientErrorCode["HttpRequestParseError"] = 12] = "HttpRequestParseError";
ClientErrorCode[ClientErrorCode["CallbackNotRegistered"] = 13] = "CallbackNotRegistered";
ClientErrorCode[ClientErrorCode["NetModuleNotInit"] = 14] = "NetModuleNotInit";
ClientErrorCode[ClientErrorCode["InvalidConfig"] = 15] = "InvalidConfig";
ClientErrorCode[ClientErrorCode["CannotCreateRuntime"] = 16] = "CannotCreateRuntime";
ClientErrorCode[ClientErrorCode["InvalidContextHandle"] = 17] = "InvalidContextHandle";
ClientErrorCode[ClientErrorCode["CannotSerializeResult"] = 18] = "CannotSerializeResult";
ClientErrorCode[ClientErrorCode["CannotSerializeError"] = 19] = "CannotSerializeError";
ClientErrorCode[ClientErrorCode["CannotConvertJsValueToJson"] = 20] = "CannotConvertJsValueToJson";
ClientErrorCode[ClientErrorCode["CannotReceiveSpawnedResult"] = 21] = "CannotReceiveSpawnedResult";
ClientErrorCode[ClientErrorCode["SetTimerError"] = 22] = "SetTimerError";
ClientErrorCode[ClientErrorCode["InvalidParams"] = 23] = "InvalidParams";
ClientErrorCode[ClientErrorCode["ContractsAddressConversionFailed"] = 24] = "ContractsAddressConversionFailed";
ClientErrorCode[ClientErrorCode["UnknownFunction"] = 25] = "UnknownFunction";
ClientErrorCode[ClientErrorCode["AppRequestError"] = 26] = "AppRequestError";
ClientErrorCode[ClientErrorCode["NoSuchRequest"] = 27] = "NoSuchRequest";
ClientErrorCode[ClientErrorCode["CanNotSendRequestResult"] = 28] = "CanNotSendRequestResult";
ClientErrorCode[ClientErrorCode["CanNotReceiveRequestResult"] = 29] = "CanNotReceiveRequestResult";
ClientErrorCode[ClientErrorCode["CanNotParseRequestResult"] = 30] = "CanNotParseRequestResult";
ClientErrorCode[ClientErrorCode["UnexpectedCallbackResponse"] = 31] = "UnexpectedCallbackResponse";
ClientErrorCode[ClientErrorCode["CanNotParseNumber"] = 32] = "CanNotParseNumber";
ClientErrorCode[ClientErrorCode["InternalError"] = 33] = "InternalError";
ClientErrorCode[ClientErrorCode["InvalidHandle"] = 34] = "InvalidHandle";
ClientErrorCode[ClientErrorCode["LocalStorageError"] = 35] = "LocalStorageError";
})(ClientErrorCode = exports.ClientErrorCode || (exports.ClientErrorCode = {}));
function appRequestResultError(text) {
return {
type: 'Error',
text,
};
}
exports.appRequestResultError = appRequestResultError;
function appRequestResultOk(result) {
return {
type: 'Ok',
result,
};
}
exports.appRequestResultOk = appRequestResultOk;
/**
* Provides information about library.
*/
class ClientModule {
constructor(client) {
this.client = client;
}
/**
* Returns Core Library API reference
* @returns ResultOfGetApiReference
*/
get_api_reference() {
return this.client.request('client.get_api_reference');
}
/**
* Returns Core Library version
* @returns ResultOfVersion
*/
version() {
return this.client.request('client.version');
}
/**
* Returns detailed information about this build.
* @returns ResultOfBuildInfo
*/
build_info() {
return this.client.request('client.build_info');
}
/**
* Resolves application request processing result
*
* @param {ParamsOfResolveAppRequest} params
* @returns
*/
resolve_app_request(params) {
return this.client.request('client.resolve_app_request', params);
}
}
exports.ClientModule = ClientModule;
// crypto module
var CryptoErrorCode;
(function (CryptoErrorCode) {
CryptoErrorCode[CryptoErrorCode["InvalidPublicKey"] = 100] = "InvalidPublicKey";
CryptoErrorCode[CryptoErrorCode["InvalidSecretKey"] = 101] = "InvalidSecretKey";
CryptoErrorCode[CryptoErrorCode["InvalidKey"] = 102] = "InvalidKey";
CryptoErrorCode[CryptoErrorCode["InvalidFactorizeChallenge"] = 106] = "InvalidFactorizeChallenge";
CryptoErrorCode[CryptoErrorCode["InvalidBigInt"] = 107] = "InvalidBigInt";
CryptoErrorCode[CryptoErrorCode["ScryptFailed"] = 108] = "ScryptFailed";
CryptoErrorCode[CryptoErrorCode["InvalidKeySize"] = 109] = "InvalidKeySize";
CryptoErrorCode[CryptoErrorCode["NaclSecretBoxFailed"] = 110] = "NaclSecretBoxFailed";
CryptoErrorCode[CryptoErrorCode["NaclBoxFailed"] = 111] = "NaclBoxFailed";
CryptoErrorCode[CryptoErrorCode["NaclSignFailed"] = 112] = "NaclSignFailed";
CryptoErrorCode[CryptoErrorCode["Bip39InvalidEntropy"] = 113] = "Bip39InvalidEntropy";
CryptoErrorCode[CryptoErrorCode["Bip39InvalidPhrase"] = 114] = "Bip39InvalidPhrase";
CryptoErrorCode[CryptoErrorCode["Bip32InvalidKey"] = 115] = "Bip32InvalidKey";
CryptoErrorCode[CryptoErrorCode["Bip32InvalidDerivePath"] = 116] = "Bip32InvalidDerivePath";
CryptoErrorCode[CryptoErrorCode["Bip39InvalidDictionary"] = 117] = "Bip39InvalidDictionary";
CryptoErrorCode[CryptoErrorCode["Bip39InvalidWordCount"] = 118] = "Bip39InvalidWordCount";
CryptoErrorCode[CryptoErrorCode["MnemonicGenerationFailed"] = 119] = "MnemonicGenerationFailed";
CryptoErrorCode[CryptoErrorCode["MnemonicFromEntropyFailed"] = 120] = "MnemonicFromEntropyFailed";
CryptoErrorCode[CryptoErrorCode["SigningBoxNotRegistered"] = 121] = "SigningBoxNotRegistered";
CryptoErrorCode[CryptoErrorCode["InvalidSignature"] = 122] = "InvalidSignature";
CryptoErrorCode[CryptoErrorCode["EncryptionBoxNotRegistered"] = 123] = "EncryptionBoxNotRegistered";
CryptoErrorCode[CryptoErrorCode["InvalidIvSize"] = 124] = "InvalidIvSize";
CryptoErrorCode[CryptoErrorCode["UnsupportedCipherMode"] = 125] = "UnsupportedCipherMode";
CryptoErrorCode[CryptoErrorCode["CannotCreateCipher"] = 126] = "CannotCreateCipher";
CryptoErrorCode[CryptoErrorCode["EncryptDataError"] = 127] = "EncryptDataError";
CryptoErrorCode[CryptoErrorCode["DecryptDataError"] = 128] = "DecryptDataError";
CryptoErrorCode[CryptoErrorCode["IvRequired"] = 129] = "IvRequired";
})(CryptoErrorCode = exports.CryptoErrorCode || (exports.CryptoErrorCode = {}));
function encryptionAlgorithmAES(params) {
return Object.assign({ type: 'AES' }, params);
}
exports.encryptionAlgorithmAES = encryptionAlgorithmAES;
var CipherMode;
(function (CipherMode) {
CipherMode["CBC"] = "CBC";
CipherMode["CFB"] = "CFB";
CipherMode["CTR"] = "CTR";
CipherMode["ECB"] = "ECB";
CipherMode["OFB"] = "OFB";
})(CipherMode = exports.CipherMode || (exports.CipherMode = {}));
function paramsOfAppSigningBoxGetPublicKey() {
return {
type: 'GetPublicKey',
};
}
exports.paramsOfAppSigningBoxGetPublicKey = paramsOfAppSigningBoxGetPublicKey;
function paramsOfAppSigningBoxSign(unsigned) {
return {
type: 'Sign',
unsigned,
};
}
exports.paramsOfAppSigningBoxSign = paramsOfAppSigningBoxSign;
function resultOfAppSigningBoxGetPublicKey(public_key) {
return {
type: 'GetPublicKey',
public_key,
};
}
exports.resultOfAppSigningBoxGetPublicKey = resultOfAppSigningBoxGetPublicKey;
function resultOfAppSigningBoxSign(signature) {
return {
type: 'Sign',
signature,
};
}
exports.resultOfAppSigningBoxSign = resultOfAppSigningBoxSign;
function paramsOfAppEncryptionBoxGetInfo() {
return {
type: 'GetInfo',
};
}
exports.paramsOfAppEncryptionBoxGetInfo = paramsOfAppEncryptionBoxGetInfo;
function paramsOfAppEncryptionBoxEncrypt(data) {
return {
type: 'Encrypt',
data,
};
}
exports.paramsOfAppEncryptionBoxEncrypt = paramsOfAppEncryptionBoxEncrypt;
function paramsOfAppEncryptionBoxDecrypt(data) {
return {
type: 'Decrypt',
data,
};
}
exports.paramsOfAppEncryptionBoxDecrypt = paramsOfAppEncryptionBoxDecrypt;
function resultOfAppEncryptionBoxGetInfo(info) {
return {
type: 'GetInfo',
info,
};
}
exports.resultOfAppEncryptionBoxGetInfo = resultOfAppEncryptionBoxGetInfo;
function resultOfAppEncryptionBoxEncrypt(data) {
return {
type: 'Encrypt',
data,
};
}
exports.resultOfAppEncryptionBoxEncrypt = resultOfAppEncryptionBoxEncrypt;
function resultOfAppEncryptionBoxDecrypt(data) {
return {
type: 'Decrypt',
data,
};
}
exports.resultOfAppEncryptionBoxDecrypt = resultOfAppEncryptionBoxDecrypt;
function dispatchAppSigningBox(obj, params, app_request_id, client) {
return __awaiter(this, void 0, void 0, function* () {
try {
let result = {};
switch (params.type) {
case 'GetPublicKey':
result = yield obj.get_public_key();
break;
case 'Sign':
result = yield obj.sign(params);
break;
}
client.resolve_app_request(app_request_id, Object.assign({ type: params.type }, result));
}
catch (error) {
client.reject_app_request(app_request_id, error);
}
});
}
function dispatchAppEncryptionBox(obj, params, app_request_id, client) {
return __awaiter(this, void 0, void 0, function* () {
try {
let result = {};
switch (params.type) {
case 'GetInfo':
result = yield obj.get_info();
break;
case 'Encrypt':
result = yield obj.encrypt(params);
break;
case 'Decrypt':
result = yield obj.decrypt(params);
break;
}
client.resolve_app_request(app_request_id, Object.assign({ type: params.type }, result));
}
catch (error) {
client.reject_app_request(app_request_id, error);
}
});
}
/**
* Crypto functions.
*/
class CryptoModule {
constructor(client) {
this.client = client;
}
/**
* Integer factorization
*
* @remarks
* Performs prime factorization – decomposition of a composite number
* into a product of smaller prime integers (factors).
* See [https://en.wikipedia.org/wiki/Integer_factorization]
*
* @param {ParamsOfFactorize} params
* @returns ResultOfFactorize
*/
factorize(params) {
return this.client.request('crypto.factorize', params);
}
/**
* Modular exponentiation
*
* @remarks
* Performs modular exponentiation for big integers (`base`^`exponent` mod `modulus`).
* See [https://en.wikipedia.org/wiki/Modular_exponentiation]
*
* @param {ParamsOfModularPower} params
* @returns ResultOfModularPower
*/
modular_power(params) {
return this.client.request('crypto.modular_power', params);
}
/**
* Calculates CRC16 using TON algorithm.
*
* @param {ParamsOfTonCrc16} params
* @returns ResultOfTonCrc16
*/
ton_crc16(params) {
return this.client.request('crypto.ton_crc16', params);
}
/**
* Generates random byte array of the specified length and returns it in `base64` format
*
* @param {ParamsOfGenerateRandomBytes} params
* @returns ResultOfGenerateRandomBytes
*/
generate_random_bytes(params) {
return this.client.request('crypto.generate_random_bytes', params);
}
/**
* Converts public key to ton safe_format
*
* @param {ParamsOfConvertPublicKeyToTonSafeFormat} params
* @returns ResultOfConvertPublicKeyToTonSafeFormat
*/
convert_public_key_to_ton_safe_format(params) {
return this.client.request('crypto.convert_public_key_to_ton_safe_format', params);
}
/**
* Generates random ed25519 key pair.
* @returns KeyPair
*/
generate_random_sign_keys() {
return this.client.request('crypto.generate_random_sign_keys');
}
/**
* Signs a data using the provided keys.
*
* @param {ParamsOfSign} params
* @returns ResultOfSign
*/
sign(params) {
return this.client.request('crypto.sign', params);
}
/**
* Verifies signed data using the provided public key. Raises error if verification is failed.
*
* @param {ParamsOfVerifySignature} params
* @returns ResultOfVerifySignature
*/
verify_signature(params) {
return this.client.request('crypto.verify_signature', params);
}
/**
* Calculates SHA256 hash of the specified data.
*
* @param {ParamsOfHash} params
* @returns ResultOfHash
*/
sha256(params) {
return this.client.request('crypto.sha256', params);
}
/**
* Calculates SHA512 hash of the specified data.
*
* @param {ParamsOfHash} params
* @returns ResultOfHash
*/
sha512(params) {
return this.client.request('crypto.sha512', params);
}
/**
* Perform `scrypt` encryption
*
* @remarks
* Derives key from `password` and `key` using `scrypt` algorithm.
* See [https://en.wikipedia.org/wiki/Scrypt].
*
* # Arguments
* - `log_n` - The log2 of the Scrypt parameter `N`
* - `r` - The Scrypt parameter `r`
* - `p` - The Scrypt parameter `p`
* # Conditions
* - `log_n` must be less than `64`
* - `r` must be greater than `0` and less than or equal to `4294967295`
* - `p` must be greater than `0` and less than `4294967295`
* # Recommended values sufficient for most use-cases
* - `log_n = 15` (`n = 32768`)
* - `r = 8`
* - `p = 1`
*
* @param {ParamsOfScrypt} params
* @returns ResultOfScrypt
*/
scrypt(params) {
return this.client.request('crypto.scrypt', params);
}
/**
* Generates a key pair for signing from the secret key
*
* @remarks
* **NOTE:** In the result the secret key is actually the concatenation
* of secret and public keys (128 symbols hex string) by design of [NaCL](http://nacl.cr.yp.to/sign.html).
* See also [the stackexchange question](https://crypto.stackexchange.com/questions/54353/).
*
* @param {ParamsOfNaclSignKeyPairFromSecret} params
* @returns KeyPair
*/
nacl_sign_keypair_from_secret_key(params) {
return this.client.request('crypto.nacl_sign_keypair_from_secret_key', params);
}
/**
* Signs data using the signer's secret key.
*
* @param {ParamsOfNaclSign} params
* @returns ResultOfNaclSign
*/
nacl_sign(params) {
return this.client.request('crypto.nacl_sign', params);
}
/**
* Verifies the signature and returns the unsigned message
*
* @remarks
* Verifies the signature in `signed` using the signer's public key `public`
* and returns the message `unsigned`.
*
* If the signature fails verification, crypto_sign_open raises an exception.
*
* @param {ParamsOfNaclSignOpen} params
* @returns ResultOfNaclSignOpen
*/
nacl_sign_open(params) {
return this.client.request('crypto.nacl_sign_open', params);
}
/**
* Signs the message using the secret key and returns a signature.
*
* @remarks
* Signs the message `unsigned` using the secret key `secret`
* and returns a signature `signature`.
*
* @param {ParamsOfNaclSign} params
* @returns ResultOfNaclSignDetached
*/
nacl_sign_detached(params) {
return this.client.request('crypto.nacl_sign_detached', params);
}
/**
* Verifies the signature with public key and `unsigned` data.
*
* @param {ParamsOfNaclSignDetachedVerify} params
* @returns ResultOfNaclSignDetachedVerify
*/
nacl_sign_detached_verify(params) {
return this.client.request('crypto.nacl_sign_detached_verify', params);
}
/**
* Generates a random NaCl key pair
* @returns KeyPair
*/
nacl_box_keypair() {
return this.client.request('crypto.nacl_box_keypair');
}
/**
* Generates key pair from a secret key
*
* @param {ParamsOfNaclBoxKeyPairFromSecret} params
* @returns KeyPair
*/
nacl_box_keypair_from_secret_key(params) {
return this.client.request('crypto.nacl_box_keypair_from_secret_key', params);
}
/**
* Public key authenticated encryption
*
* @remarks
* Encrypt and authenticate a message using the senders secret key, the receivers public
* key, and a nonce.
*
* @param {ParamsOfNaclBox} params
* @returns ResultOfNaclBox
*/
nacl_box(params) {
return this.client.request('crypto.nacl_box', params);
}
/**
* Decrypt and verify the cipher text using the receivers secret key, the senders public key, and the nonce.
*
* @param {ParamsOfNaclBoxOpen} params
* @returns ResultOfNaclBoxOpen
*/
nacl_box_open(params) {
return this.client.request('crypto.nacl_box_open', params);
}
/**
* Encrypt and authenticate message using nonce and secret key.
*
* @param {ParamsOfNaclSecretBox} params
* @returns ResultOfNaclBox
*/
nacl_secret_box(params) {
return this.client.request('crypto.nacl_secret_box', params);
}
/**
* Decrypts and verifies cipher text using `nonce` and secret `key`.
*
* @param {ParamsOfNaclSecretBoxOpen} params
* @returns ResultOfNaclBoxOpen
*/
nacl_secret_box_open(params) {
return this.client.request('crypto.nacl_secret_box_open', params);
}
/**
* Prints the list of words from the specified dictionary
*
* @param {ParamsOfMnemonicWords} params
* @returns ResultOfMnemonicWords
*/
mnemonic_words(params) {
return this.client.request('crypto.mnemonic_words', params);
}
/**
* Generates a random mnemonic
*
* @remarks
* Generates a random mnemonic from the specified dictionary and word count
*
* @param {ParamsOfMnemonicFromRandom} params
* @returns ResultOfMnemonicFromRandom
*/
mnemonic_from_random(params) {
return this.client.request('crypto.mnemonic_from_random', params);
}
/**
* Generates mnemonic from pre-generated entropy
*
* @param {ParamsOfMnemonicFromEntropy} params
* @returns ResultOfMnemonicFromEntropy
*/
mnemonic_from_entropy(params) {
return this.client.request('crypto.mnemonic_from_entropy', params);
}
/**
* Validates a mnemonic phrase
*
* @remarks
* The phrase supplied will be checked for word length and validated according to the checksum
* specified in BIP0039.
*
* @param {ParamsOfMnemonicVerify} params
* @returns ResultOfMnemonicVerify
*/
mnemonic_verify(params) {
return this.client.request('crypto.mnemonic_verify', params);
}
/**
* Derives a key pair for signing from the seed phrase
*
* @remarks
* Validates the seed phrase, generates master key and then derives
* the key pair from the master key and the specified path
*
* @param {ParamsOfMnemonicDeriveSignKeys} params
* @returns KeyPair
*/
mnemonic_derive_sign_keys(params) {
return this.client.request('crypto.mnemonic_derive_sign_keys', params);
}
/**
* Generates an extended master private key that will be the root for all the derived keys
*
* @param {ParamsOfHDKeyXPrvFromMnemonic} params
* @returns ResultOfHDKeyXPrvFromMnemonic
*/
hdkey_xprv_from_mnemonic(params) {
return this.client.request('crypto.hdkey_xprv_from_mnemonic', params);
}
/**
* Returns extended private key derived from the specified extended private key and child index
*
* @param {ParamsOfHDKeyDeriveFromXPrv} params
* @returns ResultOfHDKeyDeriveFromXPrv
*/
hdkey_derive_from_xprv(params) {
return this.client.request('crypto.hdkey_derive_from_xprv', params);
}
/**
* Derives the extended private key from the specified key and path
*
* @param {ParamsOfHDKeyDeriveFromXPrvPath} params
* @returns ResultOfHDKeyDeriveFromXPrvPath
*/
hdkey_derive_from_xprv_path(params) {
return this.client.request('crypto.hdkey_derive_from_xprv_path', params);
}
/**
* Extracts the private key from the serialized extended private key
*
* @param {ParamsOfHDKeySecretFromXPrv} params
* @returns ResultOfHDKeySecretFromXPrv
*/
hdkey_secret_from_xprv(params) {
return this.client.request('crypto.hdkey_secret_from_xprv', params);
}
/**
* Extracts the public key from the serialized extended private key
*
* @param {ParamsOfHDKeyPublicFromXPrv} params
* @returns ResultOfHDKeyPublicFromXPrv
*/
hdkey_public_from_xprv(params) {
return this.client.request('crypto.hdkey_public_from_xprv', params);
}
/**
* Performs symmetric `chacha20` encryption.
*
* @param {ParamsOfChaCha20} params
* @returns ResultOfChaCha20
*/
chacha20(params) {
return this.client.request('crypto.chacha20', params);
}
/**
* Register an application implemented signing box.
* @returns RegisteredSigningBox
*/
register_signing_box(obj) {
return this.client.request('crypto.register_signing_box', undefined, (params, responseType) => {
if (responseType === 3) {
dispatchAppSigningBox(obj, params.request_data, params.app_request_id, this.client);
}
else if (responseType === 4) {
dispatchAppSigningBox(obj, params, null, this.client);
}
});
}
/**
* Creates a default signing box implementation.
*
* @param {KeyPair} params
* @returns RegisteredSigningBox
*/
get_signing_box(params) {
return this.client.request('crypto.get_signing_box', params);
}
/**
* Returns public key of signing key pair.
*
* @param {RegisteredSigningBox} params
* @returns ResultOfSigningBoxGetPublicKey
*/
signing_box_get_public_key(params) {
return this.client.request('crypto.signing_box_get_public_key', params);
}
/**
* Returns signed user data.
*
* @param {ParamsOfSigningBoxSign} params
* @returns ResultOfSigningBoxSign
*/
signing_box_sign(params) {
return this.client.request('crypto.signing_box_sign', params);
}
/**
* Removes signing box from SDK.
*
* @param {RegisteredSigningBox} params
* @returns
*/
remove_signing_box(params) {
return this.client.request('crypto.remove_signing_box', params);
}
/**
* Register an application implemented encryption box.
* @returns RegisteredEncryptionBox
*/
register_encryption_box(obj) {
return this.client.request('crypto.register_encryption_box', undefined, (params, responseType) => {
if (responseType === 3) {
dispatchAppEncryptionBox(obj, params.request_data, params.app_request_id, this.client);
}
else if (responseType === 4) {
dispatchAppEncryptionBox(obj, params, null, this.client);
}
});
}
/**
* Removes encryption box from SDK
*
* @param {RegisteredEncryptionBox} params
* @returns
*/
remove_encryption_box(params) {
return this.client.request('crypto.remove_encryption_box', params);
}
/**
* Queries info from the given encryption box
*
* @param {ParamsOfEncryptionBoxGetInfo} params
* @returns ResultOfEncryptionBoxGetInfo
*/
encryption_box_get_info(params) {
return this.client.request('crypto.encryption_box_get_info', params);
}
/**
* Encrypts data using given encryption box Note.
*
* @remarks
* Block cipher algorithms pad data to cipher block size so encrypted data can be longer then original data. Client should store the original data size after encryption and use it after
* decryption to retrieve the original data from decrypted data.
*
* @param {ParamsOfEncryptionBoxEncrypt} params
* @returns ResultOfEncryptionBoxEncrypt
*/
encryption_box_encrypt(params) {
return this.client.request('crypto.encryption_box_encrypt', params);
}
/**
* Decrypts data using given encryption box Note.
*
* @remarks
* Block cipher algorithms pad data to cipher block size so encrypted data can be longer then original data. Client should store the original data size after encryption and use it after
* decryption to retrieve the original data from decrypted data.
*
* @param {ParamsOfEncryptionBoxDecrypt} params
* @returns ResultOfEncryptionBoxDecrypt
*/
encryption_box_decrypt(params) {
return this.client.request('crypto.encryption_box_decrypt', params);
}
/**
* Creates encryption box with specified algorithm
*
* @param {ParamsOfCreateEncryptionBox} params
* @returns RegisteredEncryptionBox
*/
create_encryption_box(params) {
return this.client.request('crypto.create_encryption_box', params);
}
}
exports.CryptoModule = CryptoModule;
// abi module
var AbiErrorCode;
(function (AbiErrorCode) {
AbiErrorCode[AbiErrorCode["RequiredAddressMissingForEncodeMessage"] = 301] = "RequiredAddressMissingForEncodeMessage";
AbiErrorCode[AbiErrorCode["RequiredCallSetMissingForEncodeMessage"] = 302] = "RequiredCallSetMissingForEncodeMessage";
AbiErrorCode[AbiErrorCode["InvalidJson"] = 303] = "InvalidJson";
AbiErrorCode[AbiErrorCode["InvalidMessage"] = 304] = "InvalidMessage";
AbiErrorCode[AbiErrorCode["EncodeDeployMessageFailed"] = 305] = "EncodeDeployMessageFailed";
AbiErrorCode[AbiErrorCode["EncodeRunMessageFailed"] = 306] = "EncodeRunMessageFailed";
AbiErrorCode[AbiErrorCode["AttachSignatureFailed"] = 307] = "AttachSignatureFailed";
AbiErrorCode[AbiErrorCode["InvalidTvcImage"] = 308] = "InvalidTvcImage";
AbiErrorCode[AbiErrorCode["RequiredPublicKeyMissingForFunctionHeader"] = 309] = "RequiredPublicKeyMissingForFunctionHeader";
AbiErrorCode[AbiErrorCode["InvalidSigner"] = 310] = "InvalidSigner";
AbiErrorCode[AbiErrorCode["InvalidAbi"] = 311] = "InvalidAbi";
AbiErrorCode[AbiErrorCode["InvalidFunctionId"] = 312] = "InvalidFunctionId";
AbiErrorCode[AbiErrorCode["InvalidData"] = 313] = "InvalidData";
AbiErrorCode[AbiErrorCode["EncodeInitialDataFailed"] = 314] = "EncodeInitialDataFailed";
})(AbiErrorCode = exports.AbiErrorCode || (exports.AbiErrorCode = {}));
function abiContract(value) {
return {
type: 'Contract',
value,
};
}
exports.abiContract = abiContract;
function abiJson(value) {
return {
type: 'Json',
value,
};
}
exports.abiJson = abiJson;
function abiHandle(value) {
return {
type: 'Handle',
value,
};
}
exports.abiHandle = abiHandle;
function abiSerialized(value) {
return {
type: 'Serialized',
value,
};
}
exports.abiSerialized = abiSerialized;
function signerNone() {
return {
type: 'None',
};
}
exports.signerNone = signerNone;
function signerExternal(public_key) {
return {
type: 'External',
public_key,
};
}
exports.signerExternal = signerExternal;
function signerKeys(keys) {
return {
type: 'Keys',
keys,
};
}
exports.signerKeys = signerKeys;
function signerSigningBox(handle) {
return {
type: 'SigningBox',
handle,
};
}
exports.signerSigningBox = signerSigningBox;
var MessageBodyType;
(function (MessageBodyType) {
MessageBodyType["Input"] = "Input";
MessageBodyType["Output"] = "Output";
MessageBodyType["InternalOutput"] = "InternalOutput";
MessageBodyType["Event"] = "Event";
})(MessageBodyType = exports.MessageBodyType || (exports.MessageBodyType = {}));
function stateInitSourceMessage(source) {
return {
type: 'Message',
source,
};
}
exports.stateInitSourceMessage = stateInitSourceMessage;
function stateInitSourceStateInit(code, data, library) {
return {
type: 'StateInit',
code,
data,
library,
};
}
exports.stateInitSourceStateInit = stateInitSourceStateInit;
function stateInitSourceTvc(tvc, public_key, init_params) {
return {
type: 'Tvc',
tvc,
public_key,
init_params,
};
}
exports.stateInitSourceTvc = stateInitSourceTvc;
function messageSourceEncoded(message, abi) {
return {
type: 'Encoded',
message,
abi,
};
}
exports.messageSourceEncoded = messageSourceEncoded;
function messageSourceEncodingParams(params) {
return Object.assign({ type: 'EncodingParams' }, params);
}
exports.messageSourceEncodingParams = messageSourceEncodingParams;
/**
* Provides message encoding and decoding according to the ABI specification.
*/
class AbiModule {
constructor(client) {
this.client = client;
}
/**
* Encodes message body according to ABI function call.
*
* @param {ParamsOfEncodeMessageBody} params
* @returns ResultOfEncodeMessageBody
*/
encode_message_body(params) {
return this.client.request('abi.encode_message_body', params);
}
/**
*
* @param {ParamsOfAttachSignatureToMessageBody} params
* @returns ResultOfAttachSignatureToMessageBody
*/
attach_signature_to_message_body(params) {
return this.client.request('abi.attach_signature_to_message_body', params);
}
/**
* Encodes an ABI-compatible message
*
* @remarks
* Allows to encode deploy and function call messages,
* both signed and unsigned.
*
* Use cases include messages of any possible type:
* - deploy with initial function call (i.e. `constructor` or any other function that is used for some kind
* of initialization);
* - deploy without initial function call;
* - signed/unsigned + data for signing.
*
* `Signer` defines how the message should or shouldn't be signed:
*
* `Signer::None` creates an unsigned message. This may be needed in case of some public methods,
* that do not require authorization by pubkey.
*
* `Signer::External` takes public key and returns `data_to_sign` for later signing.
* Use `attach_signature` method with the result signature to get the signed message.
*
* `Signer::Keys` creates a signed message with provided key pair.
*
* [SOON] `Signer::SigningBox` Allows using a special interface to implement signing
* without private key disclosure to SDK. For instance, in case of using a cold wallet or HSM,
* when application calls some API to sign data.
*
* There is an optional public key can be provided in deploy set in order to substitute one
* in TVM file.
*
* Public key resolving priority:
* 1. Public key from deploy set.
* 2. Public key, specified in TVM file.
* 3. Public key, provided by signer.
*
* @param {ParamsOfEncodeMessage} params
* @returns ResultOfEncodeMessage
*/
encode_message(params) {
return this.client.request('abi.encode_message', params);
}
/**
* Encodes an internal ABI-compatible message
*
* @remarks
* Allows to encode deploy and function call messages.
*
* Use cases include messages of any possible type:
* - deploy with initial function call (i.e. `constructor` or any other function that is used for some kind
* of initialization);
* - deploy without initial function call;
* - simple function call
*
* There is an optional public key can be provided in deploy set in order to substitute one
* in TVM file.
*
* Public key resolving priority:
* 1. Public key from deploy set.
* 2. Public key, specified in TVM file.
*
* @param {ParamsOfEncodeInternalMessage} params
* @returns ResultOfEncodeInternalMessage
*/
encode_internal_message(params) {
return this.client.request('abi.encode_internal_message', params);
}
/**
* Combines `hex`-encoded `signature` with `base64`-encoded `unsigned_message`. Returns signed message encoded in `base64`.
*
* @param {ParamsOfAttachSignature} params
* @returns ResultOfAttachSignature
*/
attach_signature(params) {
return this.client.request('abi.attach_signature', params);
}
/**
* Decodes message body using provided message BOC and ABI.
*
* @param {ParamsOfDecodeMessage} params
* @returns DecodedMessageBody
*/
decode_message(params) {
return this.client.request('abi.decode_message', params);
}
/**
* Decodes message body using provided body BOC and ABI.
*
* @param {ParamsOfDecodeMessageBody} params
* @returns DecodedMessageBody
*/
decode_message_body(params) {
return this.client.request('abi.decode_message_body', params);
}
/**
* Creates account state BOC
*
* @remarks
* Creates account state provided with one of these sets of data :
* 1. BOC of code, BOC of data, BOC of library
* 2. TVC (string in `base64`), keys, init params
*
* @param {ParamsOfEncodeAccount} params
* @returns ResultOfEncodeAccount
*/
encode_account(params) {
return this.client.request('abi.encode_account', params);
}
/**
* Decodes account data using provided data BOC and ABI.
*
* @remarks
* Note: this feature requires ABI 2.1 or higher.
*
* @param {ParamsOfDecodeAccountData} params
* @returns ResultOfDecodeAccountData
*/
decode_account_data(params) {
return this.client.request('abi.decode_account_data', params);
}
/**
* Updates initial account data with initial values for the contract's static variables and owner's public key. This operation is applicable only for initial account data (before deploy). If the contract is already deployed, its data doesn't contain this data section any more.
*
* @param {ParamsOfUpdateInitialData} params
* @returns ResultOfUpdateInitialData
*/
update_initial_data(params) {
return this.client.request('abi.update_initial_data', params);
}
/**
* Encodes initial account data with initial values for the contract's static variables and owner's public key into a data BOC that can be passed to `encode_tvc` function afterwards.
*
* @remarks
* This function is analogue of `tvm.buildDataInit` function in Solidity.
*
* @param {ParamsOfEncodeInitialData} params
* @returns ResultOfEncodeInitialData
*/
encode_initial_data(params) {
return this.client.request('abi.encode_initial_data', params);
}
/**
* Decodes initial values of a contract's static variables and owner's public key from account initial data This operation is applicable only for initial account data (before deploy). If the contract is already deployed, its data doesn't contain this data section any more.
*
* @param {ParamsOfDecodeInitialData} params
* @returns ResultOfDecodeInitialData
*/
decode_initial_data(params) {
return this.client.request('abi.decode_initial_data', params);
}
/**
* Decodes BOC into JSON as a set of provided parameters.
*
* @remarks
* Solidity functions use ABI types for [builder encoding](https://github.com/tonlabs/TON-Solidity-Compiler/blob/master/API.md#tvmbuilderstore).
* The simplest way to decode such a BOC is to use ABI decoding.
* ABI has it own rules for fields layout in cells so manually encoded
* BOC can not be described in terms of ABI rules.
*
* To solve this problem we introduce a new ABI type `Ref(<ParamType>)`
* which allows to store `ParamType` ABI parameter in cell reference and, thus,
* decode manually encoded BOCs. This type is available only in `decode_boc` function
* and will not be available in ABI messages encoding until it is included into some ABI revision.
*
* Such BOC descriptions covers most users needs. If someone wants to decode some BOC which
* can not be described by these rules (i.e. BOC with TLB containing constructors of flags
* defining some parsing conditions) then they can decode the fields up to fork condition,
* check the parsed data manually, expand the parsing schema and then decode the whole BOC
* with the full schema.
*
* @param {ParamsOfDecodeBoc} params
* @returns ResultOfDecodeBoc
*/
decode_boc(params) {
return this.client.request('abi.decode_boc', params);
}
/**
* Encodes given parameters in JSON into a BOC using param types from ABI.
*
* @param {ParamsOfAbiEncodeBoc} params
* @returns ResultOfAbiEncodeBoc
*/
encode_boc(params) {
return this.client.request('abi.encode_boc', params);
}
}
exports.AbiModule = AbiModule;
function bocCacheTypePinned(pin) {
return {
type: 'Pinned',
pin,
};
}
exports.bocCacheTypePinned = bocCacheTypePinned;
function bocCacheTypeUnpinned() {
return {
type: 'Unpinned',
};
}
exports.bocCacheTypeUnpinned = bocCacheTypeUnpinned;
var BocErrorCode;
(function (BocErrorCode) {
BocErrorCode[BocErrorCode["InvalidBoc"] = 201] = "InvalidBoc";
BocErrorCode[BocErrorCode["SerializationError"] = 202] = "SerializationError";
BocErrorCode[BocErrorCode["InappropriateBlock"] = 203] = "InappropriateBlock";
BocErrorCode[BocErrorCode["MissingSourceBoc"] = 204] = "MissingSourceBoc";
BocErrorCode[BocErrorCode["InsufficientCacheSize"] = 205] = "InsufficientCacheSize";
BocErrorCode[BocErrorCode["BocRefNotFound"] = 206] = "BocRefNotFound";
BocErrorCode[BocErrorCode["InvalidBocRef"] = 207] = "InvalidBocRef";
})(BocErrorCode = exports.BocErrorCode || (exports.BocErrorCode = {}));
function builderOpInteger(size, value) {
return {
type: 'Integer',
size,
value,
};
}
exports.builderOpInteger = builderOpInteger;
function builderOpBitString(value) {
return {
type: 'BitString',
value,
};
}
exports.builderOpBitString = builderOpBitString;
function builderOpCell(builder) {
return {
type: 'Cell',
builder,
};
}
exports.builderOpCell = builderOpCell;
function builderOpCellBoc(boc) {
return {
type: 'CellBoc',
boc,
};
}
exports.builderOpCellBoc = builderOpCellBoc;
function builderOpAddress(address) {
return {
type: 'Address',
address,
};
}
exports.builderOpAddress = builderOpAddress;
/**
* BOC manipulation module.
*/
class BocModule {
constructor(client) {
this.client = client;
}
/**
* Parses message boc into a JSON
*
* @remarks
* JSON structure is compatible with GraphQL API message object
*
* @param {ParamsOfParse} params
* @returns ResultOfParse
*/
parse_message(params) {
return this.client.request('boc.parse_message', params);
}
/**
* Parses transaction boc into a JSON
*
* @remarks
* JSON structure is compatible with GraphQL API transaction object
*
* @param {ParamsOfParse} params
* @returns ResultOfParse
*/
parse_transaction(params) {
return this.client.request('boc.parse_transaction', params);
}
/**
* Parses account boc into a JSON
*
* @remarks
* JSON structure is compatible with GraphQL API account object
*
* @param {ParamsOfParse} params
* @returns ResultOfParse
*/
parse_account(params) {
return this.client.request('boc.parse_account', params);
}
/**
* Parses block boc into a JSON
*
* @remarks
* JSON structure is compatible with GraphQL API block object
*
* @param {ParamsOfParse} params
* @returns ResultOfParse
*/
parse_block(params) {
return this.client.request('boc.parse_block', params);
}
/**
* Parses shardstate boc into a JSON
*
* @remarks
* JSON structure is compatible with GraphQL API shardstate object
*
* @param {ParamsOfParseShardstate} params
* @returns ResultOfParse
*/
parse_shardstate(params) {
return this.client.request('boc.parse_shardstate', params);
}
/**
* Extract blockchain configuration from key block and also from zerostate.
*
* @param {ParamsOfGetBlockchainConfig} params
* @returns ResultOfGetBlockchainConfig
*/
get_blockchain_config(params) {
return this.client.request('boc.get_blockchain_config', params);
}
/**
* Calculates BOC root hash
*
* @param {ParamsOfGetBocHash} params
* @returns ResultOfGetBocHash
*/
get_boc_hash(params) {
return this.client.request('boc.get_boc_hash', params);
}
/**
* Calculates BOC depth
*
* @param {ParamsOfGetBocDepth} params
* @returns ResultOfGetBocDepth
*/
get_boc_depth(params) {
return this.client.request('boc.get_boc_depth', params);
}
/**
* Extracts code from TVC contract image
*
* @param {ParamsOfGetCodeFromTvc} params
* @returns ResultOfGetCodeFromTvc
*/
get_code_from_tvc(params) {
return this.client.request('boc.get_code_from_tvc', params);
}
/**
* Get BOC from cache
*
* @param {ParamsOfBocCacheGet} params
* @returns ResultOfBocCacheGet
*/
cache_get(params) {
return this.client.request('boc.cache_get', params);
}
/**
* Save BOC into cache
*
* @param {ParamsOfBocCacheSet} params
* @returns ResultOfBocCacheSet
*/
cache_set(params) {
return this.client.request('boc.cache_set', params);
}
/**
* Unpin BOCs with specified pin.
*
* @remarks
* BOCs which don't have another pins will be removed from cache
*
* @param {ParamsOfBocCacheUnpin} params
* @returns
*/
cache_unpin(params) {
return this.client.request('boc.cache_unpin', params);
}
/**
* Encodes bag of cells (BOC) with builder operations. This method provides the same functionality as Solidity TvmBuilder. Resulting BOC of this method can be passed into Solidity and C++ contracts as TvmCell type.
*
* @param {ParamsOfEncodeBoc} params
* @returns ResultOfEncodeBoc
*/
encode_boc(params) {
return this.client.request('boc.encode_boc', params);
}
/**
* Returns the contract code's salt if it is present.
*
* @param {ParamsOfGetCodeSalt} params
* @returns ResultOfGetCodeSalt
*/
get_code_salt(params) {
return this.client.request('boc.get_code_salt', params);
}
/**
* Sets new salt to contract code.
*
* @remarks
* Returns the new contract code with salt.
*
* @param {ParamsOfSetCodeSalt} params
* @returns ResultOfSetCodeSalt
*/
set_code_salt(params) {
return this.client.request('boc.set_code_salt', params);
}
/**
* Decodes tvc into code, data, libraries and special options.
*
* @param {ParamsOfDecodeTvc} params
* @returns ResultOfDecodeTvc
*/
decode_tvc(params) {
return this.client.request('boc.decode_tvc', params);
}
/**
* Encodes tvc from code, data, libraries ans special options (see input params)
*
* @param {ParamsOfEncodeTvc} params
* @returns ResultOfEncodeTvc
*/
encode_tvc(params) {
return this.client.request('boc.encode_tvc', params);
}
/**
* Encodes a message
*
* @remarks
* Allows to encode any external inbound message.
*
* @param {ParamsOfEncodeExternalInMessage} params
* @returns ResultOfEncodeExternalInMessage
*/
encode_external_in_message(params) {
return this.client.request('boc.encode_external_in_message', params);
}
/**
* Returns the compiler version used to compile the code.
*
* @param {ParamsOfGetCompilerVersion} params
* @returns ResultOfGetCompilerVersion
*/
get_compiler_version(params) {
return this.client.request('boc.get_compiler_version', params);
}
}
exports.BocModule = BocModule;
// processing module
var ProcessingErrorCode;
(function (ProcessingErrorCode) {
ProcessingErrorCode[ProcessingErrorCode["MessageAlreadyExpired"] = 501] = "MessageAlreadyExpired";
ProcessingErrorCode[ProcessingErrorCode["MessageHasNotDestinationAddress"] = 502] = "MessageHasNotDestinationAddress";
ProcessingErrorCode[ProcessingErrorCode["CanNotBuildMessageCell"] = 503] = "CanNotBuildMessageCell";
ProcessingErrorCode[ProcessingErrorCode["FetchBlockFailed"] = 504] = "FetchBlockFailed";
ProcessingErrorCode[ProcessingErrorCode["SendMessageFailed"] = 505] = "SendMessageFailed";
ProcessingErrorCode[ProcessingErrorCode["InvalidMessageBoc"] = 506] = "InvalidMessageBoc";
ProcessingErrorCode