Crypto

Crypto

new Crypto()

Methods

(static) assert_ripemd160(data, ripe)

to assert if source data is consisted with Ripemd160.

Example
import { assert_ripemd160 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

ripe

encrypte algorithm.

(static) assert_sha1(data, sha1)

to assert if source data is consisted with SHA1.

Example
import { assert_sha1 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

sha1

encrypte algorithm.

(static) assert_sha256(data, sha256)

to assert if source data is consisted with SHA256.

Example
import { assert_sha256 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

sha256

encrypte algorithm.

(static) assert_sha512(data, sha512)

to assert if source data is consisted with SHA512.

Example
import { assert_sha512 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

sha512

encrypte algorithm.

(static) get_random_number(code, table, scope, primary)

Get a random number from system service. This number will be kept the same during a consensus period, so, if you invoke this function multi times in an action, the random number wouldn't change.

Example
import { get_random_number } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
code account_name

system service account.

table u64

table name of the random number.

scope u64

scope of the random number.

primary u64

primary of the random number.

(static) verify_with_pk(pk_str, pk_proof, message)

to verity pk and proof.

Example
import { verify_with_pk } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
pk_str

string of pk

pk_proof

string of proof

message

a message

fromString(hexStr)

hex string to crypto.

Parameters:
Name Type Description
hexStr

a hex string.

toString()

crypto result to hex string.

Crypto

new Crypto()

Class Crypto is applied for hashing a string with desired algorithms. Its derived classes are SHA1, SHA256, SHA512 and Ripemd160.

Methods

(static) assert_ripemd160(data, ripe)

to assert if source data is consisted with Ripemd160.

Example
import { assert_ripemd160 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

ripe

encrypte algorithm.

(static) assert_sha1(data, sha1)

to assert if source data is consisted with SHA1.

Example
import { assert_sha1 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

sha1

encrypte algorithm.

(static) assert_sha256(data, sha256)

to assert if source data is consisted with SHA256.

Example
import { assert_sha256 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

sha256

encrypte algorithm.

(static) assert_sha512(data, sha512)

to assert if source data is consisted with SHA512.

Example
import { assert_sha512 } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
data

source data to assert.

sha512

encrypte algorithm.

(static) get_random_number(code, table, scope, primary)

Get a random number from system service. This number will be kept the same during a consensus period, so, if you invoke this function multi times in an action, the random number wouldn't change.

Example
import { get_random_number } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
code account_name

system service account.

table u64

table name of the random number.

scope u64

scope of the random number.

primary u64

primary of the random number.

(static) verify_with_pk(pk_str, pk_proof, message)

to verity pk and proof.

Example
import { verify_with_pk } from "ultrain-ts-lib/src/crypto";
Parameters:
Name Type Description
pk_str

string of pk

pk_proof

string of proof

message

a message

fromString(hexStr)

hex string to crypto.

Parameters:
Name Type Description
hexStr

a hex string.

toString()

crypto result to hex string.