@tonclient/core
Version:
TON Client for Java Script
1,878 lines • 158 kB
TypeScript
import { ResponseHandler } from "./bin";
interface IClient {
request(functionName: string, functionParams?: any, responseHandler?: ResponseHandler): Promise<any>;
resolve_app_request(app_request_id: number | null, result: any): Promise<void>;
reject_app_request(app_request_id: number | null, error: any): Promise<void>;
}
export declare enum ClientErrorCode {
NotImplemented = 1,
InvalidHex = 2,
InvalidBase64 = 3,
InvalidAddress = 4,
CallbackParamsCantBeConvertedToJson = 5,
WebsocketConnectError = 6,
WebsocketReceiveError = 7,
WebsocketSendError = 8,
HttpClientCreateError = 9,
HttpRequestCreateError = 10,
HttpRequestSendError = 11,
HttpRequestParseError = 12,
CallbackNotRegistered = 13,
NetModuleNotInit = 14,
InvalidConfig = 15,
CannotCreateRuntime = 16,
InvalidContextHandle = 17,
CannotSerializeResult = 18,
CannotSerializeError = 19,
CannotConvertJsValueToJson = 20,
CannotReceiveSpawnedResult = 21,
SetTimerError = 22,
InvalidParams = 23,
ContractsAddressConversionFailed = 24,
UnknownFunction = 25,
AppRequestError = 26,
NoSuchRequest = 27,
CanNotSendRequestResult = 28,
CanNotReceiveRequestResult = 29,
CanNotParseRequestResult = 30,
UnexpectedCallbackResponse = 31,
CanNotParseNumber = 32,
InternalError = 33,
InvalidHandle = 34,
LocalStorageError = 35
}
export declare type ClientError = {
/**
*/
code: number;
/**
*/
message: string;
/**
*/
data: any;
};
export declare type ClientConfig = {
/**
*/
network?: NetworkConfig;
/**
*/
crypto?: CryptoConfig;
/**
*/
abi?: AbiConfig;
/**
*/
boc?: BocConfig;
/**
*/
proofs?: ProofsConfig;
/**
* For file based storage is a folder name where SDK will store its data. For browser based is a browser async storage key prefix. Default (recommended) value is "~/.tonclient" for native environments and ".tonclient" for web-browser.
*/
local_storage_path?: string;
};
export declare type NetworkConfig = {
/**
* DApp Server public address. For instance, for `net.ton.dev/graphql` GraphQL endpoint the server address will be net.ton.dev
*/
server_address?: string;
/**
* List of DApp Server addresses.
*
* @remarks
* Any correct URL format can be specified, including IP addresses This parameter is prevailing over `server_address`.
*/
endpoints?: string[];
/**
* Deprecated.
*
* @remarks
* You must use `network.max_reconnect_timeout` that allows to specify maximum network resolving timeout.
*/
network_retries_count?: number;
/**
* Maximum time for sequential reconnections.
*
* @remarks
* Must be specified in milliseconds. Default is 120000 (2 min).
*/
max_reconnect_timeout?: number;
/**
* Deprecated
*/
reconnect_timeout?: number;
/**
* The number of automatic message processing retries that SDK performs in case of `Message Expired (507)` error - but only for those messages which local emulation was successful or failed with replay protection error.
*
* @remarks
* Default is 5.
*/
message_retries_count?: number;
/**
* Timeout that is used to process message delivery for the contracts which ABI does not include "expire" header. If the message is not delivered within the specified timeout the appropriate error occurs.
*
* @remarks
* Must be specified in milliseconds. Default is 40000 (40 sec).
*/
message_processing_timeout?: number;
/**
* Maximum timeout that is used for query response.
*
* @remarks
* Must be specified in milliseconds. Default is 40000 (40 sec).
*/
wait_for_timeout?: number;
/**
* Maximum time difference between server and client.
*
* @remarks
* If client's device time is out of sync and difference is more than the threshold then error will occur. Also an error will occur if the specified threshold is more than
* `message_processing_timeout/2`.
*
* Must be specified in milliseconds. Default is 15000 (15 sec).
*/
out_of_sync_threshold?: number;
/**
* Maximum number of randomly chosen endpoints the library uses to broadcast a message.
*
* @remarks
* Default is 2.
*/
sending_endpoint_count?: number;
/**
* Frequency of sync latency detection.
*
* @remarks
* Library periodically checks the current endpoint for blockchain data syncronization latency.
* If the latency (time-lag) is less then `NetworkConfig.max_latency`
* then library selects another endpoint.
*
* Must be specified in milliseconds. Default is 60000 (1 min).
*/
latency_detection_interval?: number;
/**
* Maximum value for the endpoint's blockchain data syncronization latency (time-lag). Library periodically checks the current endpoint for blockchain data synchronization latency. If the latency (time-lag) is less then `NetworkConfig.max_latency` then library selects another endpoint.
*
* @remarks
* Must be specified in milliseconds. Default is 60000 (1 min).
*/
max_latency?: number;
/**
* Default timeout for http requests.
*
* @remarks
* Is is used when no timeout specified for the request to limit the answer waiting time. If no answer received during the timeout requests ends with
* error.
*
* Must be specified in milliseconds. Default is 60000 (1 min).
*/
query_timeout?: number;
/**
* Access key to GraphQL API.
*
* @remarks
* At the moment is not used in production.
*/
access_key?: string;
};
export declare type CryptoConfig = {
/**
* Mnemonic dictionary that will be used by default in crypto functions. If not specified, 1 dictionary will be used.
*/
mnemonic_dictionary?: number;
/**
* Mnemonic word count that will be used by default in crypto functions. If not specified the default value will be 12.
*/
mnemonic_word_count?: number;
/**
* Derivation path that will be used by default in crypto functions. If not specified `m/44'/396'/0'/0/0` will be used.
*/
hdkey_derivation_path?: string;
};
export declare type AbiConfig = {
/**
* Workchain id that is used by default in DeploySet
*/
workchain?: number;
/**
* Message lifetime for contracts which ABI includes "expire" header. The default value is 40 sec.
*/
message_expiration_timeout?: number;
/**
* Factor that increases the expiration timeout for each retry The default value is 1.5
*/
message_expiration_timeout_grow_factor?: number;
};
export declare type BocConfig = {
/**
* Maximum BOC cache size in kilobytes.
*
* @remarks
* Default is 10 MB
*/
cache_max_size?: number;
};
export declare type ProofsConfig = {
/**
* Cache proofs in the local storage.
*
* @remarks
* Default is `true`. If this value is set to `true`, downloaded proofs and master-chain BOCs are saved into the
* persistent local storage (e.g. file system for native environments or browser's IndexedDB
* for the web); otherwise all the data is cached only in memory in current client's context
* and will be lost after destruction of the client.
*/
cache_in_local_storage?: boolean;
};
export declare type BuildInfoDependency = {
/**
* Dependency name.
*
* @remarks
* Usually it is a crate name.
*/
name: string;
/**
* Git commit hash of the related repository.
*/
git_commit: string;
};
export declare type ParamsOfAppRequest = {
/**
* Request ID.
*
* @remarks
* Should be used in `resolve_app_request` call
*/
app_request_id: number;
/**
* Request describing data
*/
request_data: any;
};
export declare type AppRequestResult = {
type: 'Error';
/**
* Error description
*/
text: string;
} | {
type: 'Ok';
/**
* Request processing result
*/
result: any;
};
export declare function appRequestResultError(text: string): AppRequestResult;
export declare function appRequestResultOk(result: any): AppRequestResult;
export declare type ResultOfGetApiReference = {
/**
*/
api: any;
};
export declare type ResultOfVersion = {
/**
* Core Library version
*/
version: string;
};
export declare type ResultOfBuildInfo = {
/**
* Build number assigned to this build by the CI.
*/
build_number: number;
/**
* Fingerprint of the most important dependencies.
*/
dependencies: BuildInfoDependency[];
};
export declare type ParamsOfResolveAppRequest = {
/**
* Request ID received from SDK
*/
app_request_id: number;
/**
* Result of request processing
*/
result: AppRequestResult;
};
/**
* Provides information about library.
*/
export declare class ClientModule {
client: IClient;
constructor(client: IClient);
/**
* Returns Core Library API reference
* @returns ResultOfGetApiReference
*/
get_api_reference(): Promise<ResultOfGetApiReference>;
/**
* Returns Core Library version
* @returns ResultOfVersion
*/
version(): Promise<ResultOfVersion>;
/**
* Returns detailed information about this build.
* @returns ResultOfBuildInfo
*/
build_info(): Promise<ResultOfBuildInfo>;
/**
* Resolves application request processing result
*
* @param {ParamsOfResolveAppRequest} params
* @returns
*/
resolve_app_request(params: ParamsOfResolveAppRequest): Promise<void>;
}
export declare enum CryptoErrorCode {
InvalidPublicKey = 100,
InvalidSecretKey = 101,
InvalidKey = 102,
InvalidFactorizeChallenge = 106,
InvalidBigInt = 107,
ScryptFailed = 108,
InvalidKeySize = 109,
NaclSecretBoxFailed = 110,
NaclBoxFailed = 111,
NaclSignFailed = 112,
Bip39InvalidEntropy = 113,
Bip39InvalidPhrase = 114,
Bip32InvalidKey = 115,
Bip32InvalidDerivePath = 116,
Bip39InvalidDictionary = 117,
Bip39InvalidWordCount = 118,
MnemonicGenerationFailed = 119,
MnemonicFromEntropyFailed = 120,
SigningBoxNotRegistered = 121,
InvalidSignature = 122,
EncryptionBoxNotRegistered = 123,
InvalidIvSize = 124,
UnsupportedCipherMode = 125,
CannotCreateCipher = 126,
EncryptDataError = 127,
DecryptDataError = 128,
IvRequired = 129
}
export declare type SigningBoxHandle = number;
export declare type EncryptionBoxHandle = number;
export declare type EncryptionBoxInfo = {
/**
* Derivation path, for instance "m/44'/396'/0'/0/0"
*/
hdpath?: string;
/**
* Cryptographic algorithm, used by this encryption box
*/
algorithm?: string;
/**
* Options, depends on algorithm and specific encryption box implementation
*/
options?: any;
/**
* Public information, depends on algorithm
*/
public?: any;
};
export declare type EncryptionAlgorithm = ({
type: 'AES';
} & AesParams);
export declare function encryptionAlgorithmAES(params: AesParams): EncryptionAlgorithm;
export declare enum CipherMode {
CBC = "CBC",
CFB = "CFB",
CTR = "CTR",
ECB = "ECB",
OFB = "OFB"
}
export declare type AesParams = {
/**
*/
mode: CipherMode;
/**
*/
key: string;
/**
*/
iv?: string;
};
export declare type AesInfo = {
/**
*/
mode: CipherMode;
/**
*/
iv?: string;
};
export declare type ParamsOfFactorize = {
/**
* Hexadecimal representation of u64 composite number.
*/
composite: string;
};
export declare type ResultOfFactorize = {
/**
* Two factors of composite or empty if composite can't be factorized.
*/
factors: string[];
};
export declare type ParamsOfModularPower = {
/**
* `base` argument of calculation.
*/
base: string;
/**
* `exponent` argument of calculation.
*/
exponent: string;
/**
* `modulus` argument of calculation.
*/
modulus: string;
};
export declare type ResultOfModularPower = {
/**
* Result of modular exponentiation
*/
modular_power: string;
};
export declare type ParamsOfTonCrc16 = {
/**
* Input data for CRC calculation.
*
* @remarks
* Encoded with `base64`.
*/
data: string;
};
export declare type ResultOfTonCrc16 = {
/**
* Calculated CRC for input data.
*/
crc: number;
};
export declare type ParamsOfGenerateRandomBytes = {
/**
* Size of random byte array.
*/
length: number;
};
export declare type ResultOfGenerateRandomBytes = {
/**
* Generated bytes encoded in `base64`.
*/
bytes: string;
};
export declare type ParamsOfConvertPublicKeyToTonSafeFormat = {
/**
* Public key - 64 symbols hex string
*/
public_key: string;
};
export declare type ResultOfConvertPublicKeyToTonSafeFormat = {
/**
* Public key represented in TON safe format.
*/
ton_public_key: string;
};
export declare type KeyPair = {
/**
* Public key - 64 symbols hex string
*/
public: string;
/**
* Private key - u64 symbols hex string
*/
secret: string;
};
export declare type ParamsOfSign = {
/**
* Data that must be signed encoded in `base64`.
*/
unsigned: string;
/**
* Sign keys.
*/
keys: KeyPair;
};
export declare type ResultOfSign = {
/**
* Signed data combined with signature encoded in `base64`.
*/
signed: string;
/**
* Signature encoded in `hex`.
*/
signature: string;
};
export declare type ParamsOfVerifySignature = {
/**
* Signed data that must be verified encoded in `base64`.
*/
signed: string;
/**
* Signer's public key - 64 symbols hex string
*/
public: string;
};
export declare type ResultOfVerifySignature = {
/**
* Unsigned data encoded in `base64`.
*/
unsigned: string;
};
export declare type ParamsOfHash = {
/**
* Input data for hash calculation.
*
* @remarks
* Encoded with `base64`.
*/
data: string;
};
export declare type ResultOfHash = {
/**
* Hash of input `data`.
*
* @remarks
* Encoded with 'hex'.
*/
hash: string;
};
export declare type ParamsOfScrypt = {
/**
* The password bytes to be hashed. Must be encoded with `base64`.
*/
password: string;
/**
* Salt bytes that modify the hash to protect against Rainbow table attacks. Must be encoded with `base64`.
*/
salt: string;
/**
* CPU/memory cost parameter
*/
log_n: number;
/**
* The block size parameter, which fine-tunes sequential memory read size and performance.
*/
r: number;
/**
* Parallelization parameter.
*/
p: number;
/**
* Intended output length in octets of the derived key.
*/
dk_len: number;
};
export declare type ResultOfScrypt = {
/**
* Derived key.
*
* @remarks
* Encoded with `hex`.
*/
key: string;
};
export declare type ParamsOfNaclSignKeyPairFromSecret = {
/**
* Secret key - unprefixed 0-padded to 64 symbols hex string
*/
secret: string;
};
export declare type ParamsOfNaclSign = {
/**
* Data that must be signed encoded in `base64`.
*/
unsigned: string;
/**
* Signer's secret key - unprefixed 0-padded to 128 symbols hex string (concatenation of 64 symbols secret and 64 symbols public keys). See `nacl_sign_keypair_from_secret_key`.
*/
secret: string;
};
export declare type ResultOfNaclSign = {
/**
* Signed data, encoded in `base64`.
*/
signed: string;
};
export declare type ParamsOfNaclSignOpen = {
/**
* Signed data that must be unsigned.
*
* @remarks
* Encoded with `base64`.
*/
signed: string;
/**
* Signer's public key - unprefixed 0-padded to 64 symbols hex string
*/
public: string;
};
export declare type ResultOfNaclSignOpen = {
/**
* Unsigned data, encoded in `base64`.
*/
unsigned: string;
};
export declare type ResultOfNaclSignDetached = {
/**
* Signature encoded in `hex`.
*/
signature: string;
};
export declare type ParamsOfNaclSignDetachedVerify = {
/**
* Unsigned data that must be verified.
*
* @remarks
* Encoded with `base64`.
*/
unsigned: string;
/**
* Signature that must be verified.
*
* @remarks
* Encoded with `hex`.
*/
signature: string;
/**
* Signer's public key - unprefixed 0-padded to 64 symbols hex string.
*/
public: string;
};
export declare type ResultOfNaclSignDetachedVerify = {
/**
* `true` if verification succeeded or `false` if it failed
*/
succeeded: boolean;
};
export declare type ParamsOfNaclBoxKeyPairFromSecret = {
/**
* Secret key - unprefixed 0-padded to 64 symbols hex string
*/
secret: string;
};
export declare type ParamsOfNaclBox = {
/**
* Data that must be encrypted encoded in `base64`.
*/
decrypted: string;
/**
* Nonce, encoded in `hex`
*/
nonce: string;
/**
* Receiver's public key - unprefixed 0-padded to 64 symbols hex string
*/
their_public: string;
/**
* Sender's private key - unprefixed 0-padded to 64 symbols hex string
*/
secret: string;
};
export declare type ResultOfNaclBox = {
/**
* Encrypted data encoded in `base64`.
*/
encrypted: string;
};
export declare type ParamsOfNaclBoxOpen = {
/**
* Data that must be decrypted.
*
* @remarks
* Encoded with `base64`.
*/
encrypted: string;
/**
*/
nonce: string;
/**
* Sender's public key - unprefixed 0-padded to 64 symbols hex string
*/
their_public: string;
/**
* Receiver's private key - unprefixed 0-padded to 64 symbols hex string
*/
secret: string;
};
export declare type ResultOfNaclBoxOpen = {
/**
* Decrypted data encoded in `base64`.
*/
decrypted: string;
};
export declare type ParamsOfNaclSecretBox = {
/**
* Data that must be encrypted.
*
* @remarks
* Encoded with `base64`.
*/
decrypted: string;
/**
* Nonce in `hex`
*/
nonce: string;
/**
* Secret key - unprefixed 0-padded to 64 symbols hex string
*/
key: string;
};
export declare type ParamsOfNaclSecretBoxOpen = {
/**
* Data that must be decrypted.
*
* @remarks
* Encoded with `base64`.
*/
encrypted: string;
/**
* Nonce in `hex`
*/
nonce: string;
/**
* Public key - unprefixed 0-padded to 64 symbols hex string
*/
key: string;
};
export declare type ParamsOfMnemonicWords = {
/**
* Dictionary identifier
*/
dictionary?: number;
};
export declare type ResultOfMnemonicWords = {
/**
* The list of mnemonic words
*/
words: string;
};
export declare type ParamsOfMnemonicFromRandom = {
/**
* Dictionary identifier
*/
dictionary?: number;
/**
* Mnemonic word count
*/
word_count?: number;
};
export declare type ResultOfMnemonicFromRandom = {
/**
* String of mnemonic words
*/
phrase: string;
};
export declare type ParamsOfMnemonicFromEntropy = {
/**
* Entropy bytes.
*
* @remarks
* Hex encoded.
*/
entropy: string;
/**
* Dictionary identifier
*/
dictionary?: number;
/**
* Mnemonic word count
*/
word_count?: number;
};
export declare type ResultOfMnemonicFromEntropy = {
/**
* Phrase
*/
phrase: string;
};
export declare type ParamsOfMnemonicVerify = {
/**
* Phrase
*/
phrase: string;
/**
* Dictionary identifier
*/
dictionary?: number;
/**
* Word count
*/
word_count?: number;
};
export declare type ResultOfMnemonicVerify = {
/**
* Flag indicating if the mnemonic is valid or not
*/
valid: boolean;
};
export declare type ParamsOfMnemonicDeriveSignKeys = {
/**
* Phrase
*/
phrase: string;
/**
* Derivation path, for instance "m/44'/396'/0'/0/0"
*/
path?: string;
/**
* Dictionary identifier
*/
dictionary?: number;
/**
* Word count
*/
word_count?: number;
};
export declare type ParamsOfHDKeyXPrvFromMnemonic = {
/**
* String with seed phrase
*/
phrase: string;
/**
* Dictionary identifier
*/
dictionary?: number;
/**
* Mnemonic word count
*/
word_count?: number;
};
export declare type ResultOfHDKeyXPrvFromMnemonic = {
/**
* Serialized extended master private key
*/
xprv: string;
};
export declare type ParamsOfHDKeyDeriveFromXPrv = {
/**
* Serialized extended private key
*/
xprv: string;
/**
* Child index (see BIP-0032)
*/
child_index: number;
/**
* Indicates the derivation of hardened/not-hardened key (see BIP-0032)
*/
hardened: boolean;
};
export declare type ResultOfHDKeyDeriveFromXPrv = {
/**
* Serialized extended private key
*/
xprv: string;
};
export declare type ParamsOfHDKeyDeriveFromXPrvPath = {
/**
* Serialized extended private key
*/
xprv: string;
/**
* Derivation path, for instance "m/44'/396'/0'/0/0"
*/
path: string;
};
export declare type ResultOfHDKeyDeriveFromXPrvPath = {
/**
* Derived serialized extended private key
*/
xprv: string;
};
export declare type ParamsOfHDKeySecretFromXPrv = {
/**
* Serialized extended private key
*/
xprv: string;
};
export declare type ResultOfHDKeySecretFromXPrv = {
/**
* Private key - 64 symbols hex string
*/
secret: string;
};
export declare type ParamsOfHDKeyPublicFromXPrv = {
/**
* Serialized extended private key
*/
xprv: string;
};
export declare type ResultOfHDKeyPublicFromXPrv = {
/**
* Public key - 64 symbols hex string
*/
public: string;
};
export declare type ParamsOfChaCha20 = {
/**
* Source data to be encrypted or decrypted.
*
* @remarks
* Must be encoded with `base64`.
*/
data: string;
/**
* 256-bit key.
*
* @remarks
* Must be encoded with `hex`.
*/
key: string;
/**
* 96-bit nonce.
*
* @remarks
* Must be encoded with `hex`.
*/
nonce: string;
};
export declare type ResultOfChaCha20 = {
/**
* Encrypted/decrypted data.
*
* @remarks
* Encoded with `base64`.
*/
data: string;
};
export declare type RegisteredSigningBox = {
/**
* Handle of the signing box.
*/
handle: SigningBoxHandle;
};
export declare type ParamsOfAppSigningBox = {
type: 'GetPublicKey';
} | {
type: 'Sign';
/**
* Data to sign encoded as base64
*/
unsigned: string;
};
export declare function paramsOfAppSigningBoxGetPublicKey(): ParamsOfAppSigningBox;
export declare function paramsOfAppSigningBoxSign(unsigned: string): ParamsOfAppSigningBox;
export declare type ResultOfAppSigningBox = {
type: 'GetPublicKey';
/**
* Signing box public key
*/
public_key: string;
} | {
type: 'Sign';
/**
* Data signature encoded as hex
*/
signature: string;
};
export declare function resultOfAppSigningBoxGetPublicKey(public_key: string): ResultOfAppSigningBox;
export declare function resultOfAppSigningBoxSign(signature: string): ResultOfAppSigningBox;
export declare type ResultOfSigningBoxGetPublicKey = {
/**
* Public key of signing box.
*
* @remarks
* Encoded with hex
*/
pubkey: string;
};
export declare type ParamsOfSigningBoxSign = {
/**
* Signing Box handle.
*/
signing_box: SigningBoxHandle;
/**
* Unsigned user data.
*
* @remarks
* Must be encoded with `base64`.
*/
unsigned: string;
};
export declare type ResultOfSigningBoxSign = {
/**
* Data signature.
*
* @remarks
* Encoded with `hex`.
*/
signature: string;
};
export declare type RegisteredEncryptionBox = {
/**
* Handle of the encryption box
*/
handle: EncryptionBoxHandle;
};
export declare type ParamsOfAppEncryptionBox = {
type: 'GetInfo';
} | {
type: 'Encrypt';
/**
* Data, encoded in Base64
*/
data: string;
} | {
type: 'Decrypt';
/**
* Data, encoded in Base64
*/
data: string;
};
export declare function paramsOfAppEncryptionBoxGetInfo(): ParamsOfAppEncryptionBox;
export declare function paramsOfAppEncryptionBoxEncrypt(data: string): ParamsOfAppEncryptionBox;
export declare function paramsOfAppEncryptionBoxDecrypt(data: string): ParamsOfAppEncryptionBox;
export declare type ResultOfAppEncryptionBox = {
type: 'GetInfo';
/**
*/
info: EncryptionBoxInfo;
} | {
type: 'Encrypt';
/**
* Encrypted data, encoded in Base64
*/
data: string;
} | {
type: 'Decrypt';
/**
* Decrypted data, encoded in Base64
*/
data: string;
};
export declare function resultOfAppEncryptionBoxGetInfo(info: EncryptionBoxInfo): ResultOfAppEncryptionBox;
export declare function resultOfAppEncryptionBoxEncrypt(data: string): ResultOfAppEncryptionBox;
export declare function resultOfAppEncryptionBoxDecrypt(data: string): ResultOfAppEncryptionBox;
export declare type ParamsOfEncryptionBoxGetInfo = {
/**
* Encryption box handle
*/
encryption_box: EncryptionBoxHandle;
};
export declare type ResultOfEncryptionBoxGetInfo = {
/**
* Encryption box information
*/
info: EncryptionBoxInfo;
};
export declare type ParamsOfEncryptionBoxEncrypt = {
/**
* Encryption box handle
*/
encryption_box: EncryptionBoxHandle;
/**
* Data to be encrypted, encoded in Base64
*/
data: string;
};
export declare type ResultOfEncryptionBoxEncrypt = {
/**
* Encrypted data, encoded in Base64.
*
* @remarks
* Padded to cipher block size
*/
data: string;
};
export declare type ParamsOfEncryptionBoxDecrypt = {
/**
* Encryption box handle
*/
encryption_box: EncryptionBoxHandle;
/**
* Data to be decrypted, encoded in Base64
*/
data: string;
};
export declare type ResultOfEncryptionBoxDecrypt = {
/**
* Decrypted data, encoded in Base64.
*/
data: string;
};
export declare type ParamsOfCreateEncryptionBox = {
/**
* Encryption algorithm specifier including cipher parameters (key, IV, etc)
*/
algorithm: EncryptionAlgorithm;
};
declare type ResultOfAppSigningBoxGetPublicKey = {
public_key: string;
};
declare type ParamsOfAppSigningBoxSign = {
unsigned: string;
};
declare type ResultOfAppSigningBoxSign = {
signature: string;
};
export interface AppSigningBox {
get_public_key(): Promise<ResultOfAppSigningBoxGetPublicKey>;
sign(params: ParamsOfAppSigningBoxSign): Promise<ResultOfAppSigningBoxSign>;
}
declare type ResultOfAppEncryptionBoxGetInfo = {
info: EncryptionBoxInfo;
};
declare type ParamsOfAppEncryptionBoxEncrypt = {
data: string;
};
declare type ResultOfAppEncryptionBoxEncrypt = {
data: string;
};
declare type ParamsOfAppEncryptionBoxDecrypt = {
data: string;
};
declare type ResultOfAppEncryptionBoxDecrypt = {
data: string;
};
export interface AppEncryptionBox {
get_info(): Promise<ResultOfAppEncryptionBoxGetInfo>;
encrypt(params: ParamsOfAppEncryptionBoxEncrypt): Promise<ResultOfAppEncryptionBoxEncrypt>;
decrypt(params: ParamsOfAppEncryptionBoxDecrypt): Promise<ResultOfAppEncryptionBoxDecrypt>;
}
/**
* Crypto functions.
*/
export declare class CryptoModule {
client: IClient;
constructor(client: IClient);
/**
* 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: ParamsOfFactorize): Promise<ResultOfFactorize>;
/**
* 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: ParamsOfModularPower): Promise<ResultOfModularPower>;
/**
* Calculates CRC16 using TON algorithm.
*
* @param {ParamsOfTonCrc16} params
* @returns ResultOfTonCrc16
*/
ton_crc16(params: ParamsOfTonCrc16): Promise<ResultOfTonCrc16>;
/**
* Generates random byte array of the specified length and returns it in `base64` format
*
* @param {ParamsOfGenerateRandomBytes} params
* @returns ResultOfGenerateRandomBytes
*/
generate_random_bytes(params: ParamsOfGenerateRandomBytes): Promise<ResultOfGenerateRandomBytes>;
/**
* Converts public key to ton safe_format
*
* @param {ParamsOfConvertPublicKeyToTonSafeFormat} params
* @returns ResultOfConvertPublicKeyToTonSafeFormat
*/
convert_public_key_to_ton_safe_format(params: ParamsOfConvertPublicKeyToTonSafeFormat): Promise<ResultOfConvertPublicKeyToTonSafeFormat>;
/**
* Generates random ed25519 key pair.
* @returns KeyPair
*/
generate_random_sign_keys(): Promise<KeyPair>;
/**
* Signs a data using the provided keys.
*
* @param {ParamsOfSign} params
* @returns ResultOfSign
*/
sign(params: ParamsOfSign): Promise<ResultOfSign>;
/**
* Verifies signed data using the provided public key. Raises error if verification is failed.
*
* @param {ParamsOfVerifySignature} params
* @returns ResultOfVerifySignature
*/
verify_signature(params: ParamsOfVerifySignature): Promise<ResultOfVerifySignature>;
/**
* Calculates SHA256 hash of the specified data.
*
* @param {ParamsOfHash} params
* @returns ResultOfHash
*/
sha256(params: ParamsOfHash): Promise<ResultOfHash>;
/**
* Calculates SHA512 hash of the specified data.
*
* @param {ParamsOfHash} params
* @returns ResultOfHash
*/
sha512(params: ParamsOfHash): Promise<ResultOfHash>;
/**
* 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: ParamsOfScrypt): Promise<ResultOfScrypt>;
/**
* 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: ParamsOfNaclSignKeyPairFromSecret): Promise<KeyPair>;
/**
* Signs data using the signer's secret key.
*
* @param {ParamsOfNaclSign} params
* @returns ResultOfNaclSign
*/
nacl_sign(params: ParamsOfNaclSign): Promise<ResultOfNaclSign>;
/**
* 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: ParamsOfNaclSignOpen): Promise<ResultOfNaclSignOpen>;
/**
* 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: ParamsOfNaclSign): Promise<ResultOfNaclSignDetached>;
/**
* Verifies the signature with public key and `unsigned` data.
*
* @param {ParamsOfNaclSignDetachedVerify} params
* @returns ResultOfNaclSignDetachedVerify
*/
nacl_sign_detached_verify(params: ParamsOfNaclSignDetachedVerify): Promise<ResultOfNaclSignDetachedVerify>;
/**
* Generates a random NaCl key pair
* @returns KeyPair
*/
nacl_box_keypair(): Promise<KeyPair>;
/**
* Generates key pair from a secret key
*
* @param {ParamsOfNaclBoxKeyPairFromSecret} params
* @returns KeyPair
*/
nacl_box_keypair_from_secret_key(params: ParamsOfNaclBoxKeyPairFromSecret): Promise<KeyPair>;
/**
* 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: ParamsOfNaclBox): Promise<ResultOfNaclBox>;
/**
* 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: ParamsOfNaclBoxOpen): Promise<ResultOfNaclBoxOpen>;
/**
* Encrypt and authenticate message using nonce and secret key.
*
* @param {ParamsOfNaclSecretBox} params
* @returns ResultOfNaclBox
*/
nacl_secret_box(params: ParamsOfNaclSecretBox): Promise<ResultOfNaclBox>;
/**
* Decrypts and verifies cipher text using `nonce` and secret `key`.
*
* @param {ParamsOfNaclSecretBoxOpen} params
* @returns ResultOfNaclBoxOpen
*/
nacl_secret_box_open(params: ParamsOfNaclSecretBoxOpen): Promise<ResultOfNaclBoxOpen>;
/**
* Prints the list of words from the specified dictionary
*
* @param {ParamsOfMnemonicWords} params
* @returns ResultOfMnemonicWords
*/
mnemonic_words(params: ParamsOfMnemonicWords): Promise<ResultOfMnemonicWords>;
/**
* 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: ParamsOfMnemonicFromRandom): Promise<ResultOfMnemonicFromRandom>;
/**
* Generates mnemonic from pre-generated entropy
*
* @param {ParamsOfMnemonicFromEntropy} params
* @returns ResultOfMnemonicFromEntropy
*/
mnemonic_from_entropy(params: ParamsOfMnemonicFromEntropy): Promise<ResultOfMnemonicFromEntropy>;
/**
* 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: ParamsOfMnemonicVerify): Promise<ResultOfMnemonicVerify>;
/**
* 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: ParamsOfMnemonicDeriveSignKeys): Promise<KeyPair>;
/**
* 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: ParamsOfHDKeyXPrvFromMnemonic): Promise<ResultOfHDKeyXPrvFromMnemonic>;
/**
* Returns extended private key derived from the specified extended private key and child index
*
* @param {ParamsOfHDKeyDeriveFromXPrv} params
* @returns ResultOfHDKeyDeriveFromXPrv
*/
hdkey_derive_from_xprv(params: ParamsOfHDKeyDeriveFromXPrv): Promise<ResultOfHDKeyDeriveFromXPrv>;
/**
* Derives the extended private key from the specified key and path
*
* @param {ParamsOfHDKeyDeriveFromXPrvPath} params
* @returns ResultOfHDKeyDeriveFromXPrvPath
*/
hdkey_derive_from_xprv_path(params: ParamsOfHDKeyDeriveFromXPrvPath): Promise<ResultOfHDKeyDeriveFromXPrvPath>;
/**
* Extracts the private key from the serialized extended private key
*
* @param {ParamsOfHDKeySecretFromXPrv} params
* @returns ResultOfHDKeySecretFromXPrv
*/
hdkey_secret_from_xprv(params: ParamsOfHDKeySecretFromXPrv): Promise<ResultOfHDKeySecretFromXPrv>;
/**
* Extracts the public key from the serialized extended private key
*
* @param {ParamsOfHDKeyPublicFromXPrv} params
* @returns ResultOfHDKeyPublicFromXPrv
*/
hdkey_public_from_xprv(params: ParamsOfHDKeyPublicFromXPrv): Promise<ResultOfHDKeyPublicFromXPrv>;
/**
* Performs symmetric `chacha20` encryption.
*
* @param {ParamsOfChaCha20} params
* @returns ResultOfChaCha20
*/
chacha20(params: ParamsOfChaCha20): Promise<ResultOfChaCha20>;
/**
* Register an application implemented signing box.
* @returns RegisteredSigningBox
*/
register_signing_box(obj: AppSigningBox): Promise<RegisteredSigningBox>;
/**
* Creates a default signing box implementation.
*
* @param {KeyPair} params
* @returns RegisteredSigningBox
*/
get_signing_box(params: KeyPair): Promise<RegisteredSigningBox>;
/**
* Returns public key of signing key pair.
*
* @param {RegisteredSigningBox} params
* @returns ResultOfSigningBoxGetPublicKey
*/
signing_box_get_public_key(params: RegisteredSigningBox): Promise<ResultOfSigningBoxGetPublicKey>;
/**
* Returns signed user data.
*
* @param {ParamsOfSigningBoxSign} params
* @returns ResultOfSigningBoxSign
*/
signing_box_sign(params: ParamsOfSigningBoxSign): Promise<ResultOfSigningBoxSign>;
/**
* Removes signing box from SDK.
*
* @param {RegisteredSigningBox} params
* @returns
*/
remove_signing_box(params: RegisteredSigningBox): Promise<void>;
/**
* Register an application implemented encryption box.
* @returns RegisteredEncryptionBox
*/
register_encryption_box(obj: AppEncryptionBox): Promise<RegisteredEncryptionBox>;
/**
* Removes encryption box from SDK
*
* @param {RegisteredEncryptionBox} params
* @returns
*/
remove_encryption_box(params: RegisteredEncryptionBox): Promise<void>;
/**
* Queries info from the given encryption box
*
* @param {ParamsOfEncryptionBoxGetInfo} params
* @returns ResultOfEncryptionBoxGetInfo
*/
encryption_box_get_info(params: ParamsOfEncryptionBoxGetInfo): Promise<ResultOfEncryptionBoxGetInfo>;
/**
* 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: ParamsOfEncryptionBoxEncrypt): Promise<ResultOfEncryptionBoxEncrypt>;
/**
* 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: ParamsOfEncryptionBoxDecrypt): Promise<ResultOfEncryptionBoxDecrypt>;
/**
* Creates encryption box with specified algorithm
*
* @param {ParamsOfCreateEncryptionBox} params
* @returns RegisteredEncryptionBox
*/
create_encryption_box(params: ParamsOfCreateEncryptionBox): Promise<RegisteredEncryptionBox>;
}
export declare enum AbiErrorCode {
RequiredAddressMissingForEncodeMessage = 301,
RequiredCallSetMissingForEncodeMessage = 302,
InvalidJson = 303,
InvalidMessage = 304,
EncodeDeployMessageFailed = 305,
EncodeRunMessageFailed = 306,
AttachSignatureFailed = 307,
InvalidTvcImage = 308,
RequiredPublicKeyMissingForFunctionHeader = 309,
InvalidSigner = 310,
InvalidAbi = 311,
InvalidFunctionId = 312,
InvalidData = 313,
EncodeInitialDataFailed = 314
}
export declare type Abi = {
type: 'Contract';
/**
*/
value: AbiContract;
} | {
type: 'Json';
/**
*/
value: string;
} | {
type: 'Handle';
/**
*/
value: AbiHandle;
} | {
type: 'Serialized';
/**
*/
value: AbiContract;
};
export declare function abiContract(value: AbiContract): Abi;
export declare function abiJson(value: string): Abi;
export declare function abiHandle(value: AbiHandle): Abi;
export declare function abiSerialized(value: AbiContract): Abi;
export declare type AbiHandle = number;
export declare type FunctionHeader = {
/**
* Message expiration time in seconds. If not specified - calculated automatically from message_expiration_timeout(), try_index and message_expiration_timeout_grow_factor() (if ABI includes `expire` header).
*/
expire?: number;
/**
* Message creation time in milliseconds.
*
* @remarks
* If not specified, `now` is used (if ABI includes `time` header).
*/
time?: bigint;
/**
* Public key is used by the contract to check the signature.
*
* @remarks
* Encoded in `hex`. If not specified, method fails with exception (if ABI includes `pubkey` header)..
*/
pubkey?: string;
};
export declare type CallSet = {
/**
* Function name that is being called. Or function id encoded as string in hex (starting with 0x).
*/
function_name: string;
/**
* Function header.
*
* @remarks
* If an application omits some header parameters required by the
* contract's ABI, the library will set the default values for
* them.
*/
header?: FunctionHeader;
/**
* Function input parameters according to ABI.
*/
input?: any;
};
export declare type DeploySet = {
/**
* Content of TVC file encoded in `base64`.
*/
tvc: string;
/**
* Target workchain for destination address.
*
* @remarks
* Default is `0`.
*/
workchain_id?: number;
/**
* List of initial values for contract's public variables.
*/
initial_data?: any;
/**
* Optional public key that can be provided in deploy set in order to substitute one in TVM file or provided by Signer.
*
* @remarks
* Public key resolving priority:
* 1. Public key from deploy set.
* 2. Public key, specified in TVM file.
* 3. Public key, provided by Signer.
*/
initial_pubkey?: string;
};
export declare type Signer = {
type: 'None';
} | {
type: 'External';
/**
*/
public_key: string;
} | {
type: 'Keys';
/**
*/
keys: KeyPair;
} | {
type: 'SigningBox';
/**
*/
handle: SigningBoxHandle;
};
export declare function signerNone(): Signer;
export declare function signerExternal(public_key: string): Signer;
export declare function signerKeys(keys: KeyPair): Signer;
export declare function signerSigningBox(handle: SigningBoxHandle): Signer;
export declare enum MessageBodyType {
Input = "Input",
Output = "Output",
InternalOutput = "InternalOutput",
Event = "Event"
}
export declare type StateInitSource = {
type: 'Message';
/**
*/
source: MessageSource;
} | {
type: 'StateInit';
/**
* Code BOC.
*
* @remarks
* Encoded in `base64`.
*/
code: string;
/**
* Data BOC.
*
* @remarks
* Encoded in `base64`.
*/
data: string;
/**
* Library BOC.
*
* @remarks
* Encoded in `base64`.
*/
library?: string;
} | {
type: 'Tvc';
/**
*/
tvc: string;
/**
*/
public_key?: string;
/**
*/
init_params?: StateInitParams;
};
export declare function stateInitSourceMessage(source: MessageSource): StateInitSource;
export declare function stateInitSourceStateInit(code: string, data: string, library?: string): StateInitSource;
export declare function stateInitSourceTvc(tvc: string, public_key?: string, init_params?: StateInitParams): StateInitSource;
export declare type StateInitParams = {
/**
*/
abi: Abi;
/**
*/
value: any;
};
export declare type MessageSource = {
type: 'Encoded';
/**
*/
message: string;
/**
*/
abi?: Abi;
} | ({
type: 'EncodingParams';
} & ParamsOfEncodeMessage);
export declare function messageSourceEncoded(message: string, abi?: Abi): MessageSource;
export declare function messageSourceEncodingParams(params: ParamsOfEncodeMessage): MessageSource;
export declare type AbiParam = {
/**
*/
name: string;
/**
*/
type: string;
/**
*/
components?: AbiParam[];
};
export declare type AbiEvent = {
/**
*/
name: string;
/**
*/
inputs: AbiParam[];
/**
*/
id?: string | null;
};
export declare type AbiData = {
/**
*/
key: number;
/**
*/
name: string;
/**
*/
type: string;
/**
*/
components?: AbiParam[];
};
export declare type AbiFunction = {
/**
*/
name: string;
/**
*/
inputs: AbiParam[];
/**
*/
outputs: AbiParam[];
/**
*/
id?: string | null;
};
export declare type AbiContract = {
/**
*/
'ABI version'?: number;
/**
*/
abi_version?: number;
/**
*/
version?: string | null;
/**
*/
header?: string[];
/**
*/
functions?: AbiFunction[];
/**
*/
events?: AbiEvent[];
/**
*/
data?: AbiData[];
/**
*/
fields?: AbiParam[];
};
export declare type ParamsOfEncodeMessageBody = {
/**
* Contract ABI.
*/
abi: Abi;
/**
* Function call parameters.
*
* @remarks
* Must be specified in non deploy message.
*
* In case of deploy message contains parameters of constructor.
*/
call_set: CallSet;
/**
* True if internal message body must be encoded.
*/
is_internal: boolean;
/**
* Signing parameters.
*/
signer: Signer;
/**
* Processing try index.
*
* @remarks
* Used in message processing with retries.
*
* Encoder uses the provided try index to calculate message
* expiration time.
*
* Expiration timeouts will grow with every retry.
*
* Default value is 0.
*/
processing_try_index?: number;
};
export declare type ResultOfEncodeMessageBody = {
/**
* Message body BOC encoded with `base64`.
*/
body: string;
/**
* Optional data to sign.
*
* @remarks
* Encoded with `base64`.
* Presents when `message` is unsigned. Can be used for external
* message signing. Is this case you need to sing this data and
* produce signed message using `abi.attach_signature`.
*/
data_to_sign?: string;
};
export declare type ParamsOfAttachSignatureToMessageBody = {
/**
* Contract ABI
*/
abi: Abi;
/**
* Public key.
*
* @remarks
* Must be encoded with `hex`.
*/
public_key: string;
/**
* Unsigned message body BOC.
*
* @remarks
* Must be encoded with `base64`.
*/
message: string;
/**
* Signature.
*
* @remarks
* Must be encoded with `hex`.
*/
signature: string;
};
export declare type ResultOfAttachSignatureToMessageBody = {
/**
*/
body: string;
};
export declare type ParamsOfEncodeMessage = {
/**
* Contract ABI.
*/
abi: Abi;
/**
* Target address the message will be sent to.
*
* @remarks
* M