caver.utils (~v1.4.1)
caver-js utility APIs.
Last updated
caver-js utility APIs.
Last updated
caver.utils
provides utility functions.
The randomHex library to generate cryptographically strong pseudo-random HEX strings from a given byte size.
Parameters
Name | Type | Description |
---|---|---|
Return Value
Type | Description |
---|---|
Example
많은 편리한 자바스크립트 함수를 위한 underscore 라이브러리.
See the underscore API reference for details.
Example
자바스크립트에서 큰 수로 계산하기 위한 BN.js 라이브러리. 자세한 내용은 BN.js documentation을 참조하세요.
Parameters
Return Value
Example
Checks if a given value is a BN.js instance.
Parameters
Return Value
Example
Checks if a given value is a BigNumber.js instance.
Parameters
Return Value
Example
Calculates the sha3 of the input.
참고: 솔리디티의 sha3를 모방하려면 caver.utils.soliditySha3를 사용합니다.
Parameters
Return Value
Example
Calculates the sha3 of given input parameters in the same way solidity would. This means arguments will be ABI converted and tightly packed before being hashed.
Parameters
Return Value
Example
Checks if a given string is a HEX string.
Parameters
Return Value
Example
Checks if a given string is a HEX string. caver.utils.isHex와의 차이점은 HEX 앞에 0x
이 붙는다는 것입니다.
Parameters
Return Value
Example
Checks if a given string is a valid Klaytn address. 주소에 대문자와 소문자가 있으면 체크섬(checksum)도 검사합니다.
Parameters
Return Value
Examples
Converts an upper or lowercase Klaytn address to a checksum address.
Parameters
Return Value
Examples
Checks the checksum of a given address. Will also return false
on non-checksum addresses.
Parameters
Return Value
Examples
Converts any given value to HEX. 숫자 문자열은 숫자로 해석됩니다. Text strings will be interpreted as UTF-8 strings.
Parameters
Return Value
Examples
Safely converts any given value (including BigNumber.js instances) into a BN.js instance, for handling big numbers in JavaScript.
참고: BN.js 클래스의 경우 caver.utils.BN를 사용합니다.
Parameters
Return Value
Examples
Returns the number representation of a given HEX value as a string.
Parameters
Return Value
Examples
Returns the number representation of a given HEX value.
참고: 큰 숫자에는 유용하지 않으며, caver.utils.toBN를 대신 사용합니다.
Parameters
Return Value
Examples
Returns the HEX representation of a given number value.
Parameters
Return Value
Examples
Returns the UTF-8 string representation of a given HEX value.
Parameters
Return Value
Examples
Returns the ASCII string representation of a given HEX value.
Parameters
Return Value
Examples
Returns the HEX representation of a given UTF-8 string.
Parameters
Return Value
Examples
Returns the HEX representation of a given ASCII string.
Parameters
Return Value
Examples
Returns a byte array from the given HEX string.
Parameters
Return Value
Examples
Returns a HEX string from a byte array.
Parameters
Return Value
Examples
Converts any KLAY value into peb.
참고: "peb"는 가장 작은 KLAY 단위이며, 항상 peb로 계산해야 하며 표시할 용도로만 변환해야 합니다.
Parameters
Return Value
Examples
참고: "peb"는 가장 작은 KLAY 단위이며, 항상 peb로 계산해야 하며 표시할 용도로만 변환해야 합니다.
Parameters
Return Value
Examples
Shows all possible KLAY values and their amount in peb.
Return Value
Examples
문자열 왼쪽에 패딩(padding)을 추가합니다. Useful for adding paddings to HEX strings.
Parameters
Return Value
Examples
문자열 오른쪽에 패딩을 추가합니다. HEX 문자열에 패딩을 추가하는 데 유용합니다.
Parameters
Return Value
Examples
Converts a negative number into a two's complement.
Parameters
Return Value
Examples
Returns true
if the given transaction is a smart contract deploy transaction. It returns false
if the transaction is not a smart contract deploy transaction. The result is determined by the values of the parameters in the transactionObject
. Make sure all the mandatory parameters are set correctly.
참고 caver.klay.isContractDeployment는 v1.0.1-rc.8에서 지원됩니다. To use this feature, please install v1.0.1-rc.8 or higher.
Parameters
Return Value
Examples
Returns the x and y coordinates of the given publicKey. 키 암호화에 대한 자세한 내용은 타원 곡선 암호화를 참조하세요.
NOTE This function does not contain any logic to check whether the public key is valid. The function only split the input publicKey into x and y points by length.
Parameters
Return Value
Examples
입력이 0x 접두사가 있는 16진수 문자열이면 true
, 그렇지 않으면 false
를 반환합니다.
참고 caver.klay.isHexPrefixed는 v1.0.1에서 지원됩니다. To use this feature, please install v1.0.1 or higher.
Parameters
Return Value
Examples
Returns a 0x-prefixed hex string. If the input is already 0x-prefixed or a non-hex string, the input value is returned as-is.
참고 caver.klay.addHexPrefix는 v1.0.1에서 지원됩니다. To use this feature, please install v1.0.1 or higher.
Parameters
Return Value
Examples
Returns the result with 0x prefix stripped from input.
NOTE caver.klay.stripHexPrefix is supported from v1.0.1. To use this feature, please install v1.0.1 or higher.
Parameters
Return Value
Examples
This function converts the input to a Buffer. toBuffer
을 사용하여 객체를 버퍼로 변환하려면, 객체는 반드시 toArray 함수를 구현해야 합니다. 문자열 유형 입력의 경우, 이 함수는 0x 접두사가 있는 16진수 문자열에서만 작동합니다.
참고 caver.klay.toBuffer는 v1.1.0에서 지원됩니다. 이 기능을 사용하려면 v1.1.0 또는 그 이상을 설치하세요.
Parameters
Return Value
Examples
This function converts a number to a Buffer. 입력이 숫자인 경우 caver.utils.toBuffer는 이 함수와 동일하게 동작합니다.
참고 caver.klay.numberToBuffer는 v1.1.0에서 지원됩니다. To use this feature, please install v1.1.0 or higher.
Parameters
Return Value
Examples
입력이 트랜잭션 해시 형식이면 true
, 그렇지 않으면 false
를 반환합니다. This function only looks at the input and determines if it is in the format of a transaction hash. 참고 caver.klay.isTxHash는 v1.2.0-rc.1에서 지원됩니다. 이 기능을 사용하려면 v1.2.0-rc.1 또는 그 이상을 설치하세요. 매개변수
Return Value
Examples
Returns true
if input is in transaction hash format, otherwise it returns false
. This function only looks at the input and determines if it is in the format of a transaction hash. caver.utils.isTxHash와의 차이점은 HEX 앞에 0x
이 붙는다는 것입니다. 참고 caver.klay.isTxHashStrict는 v1.2.0-rc.1에서 지원됩니다. To use this feature, please install v1.2.0-rc.1 or higher. Parameters
Return Value
Examples
privateKey가 유효하면 true
, 그렇지 않으면 false
리턴합니다.
Parameters
Return Value
Examples
Returns true
if publicKey is valid, otherwise it returns false
.
참고 caver.utils.isValidPublicKey
는 caver-js v1.2.0부터 지원됩니다.
Parameters
Return Value
Examples
role이 유효하면 true
, 그렇지 않으면 false
를 반환합니다. AccountKeyRoleBased에서 사용되는 현재 정의된 role은 transactionKey
,updateKey
및 feePayerKey
입니다.
참고 caver.utils.isValidRole
는 caver-js v1.2.0부터 지원됩니다.
Parameters
Return Value
Examples
sig가 빈 서명 형식인 경우 ([[ '0x01', '0x', '0x']]
또는 [ '0x01', '0x', '0x']
) true
, 그렇지 않은 경우 false
를 반환합니다.
caver-js에서 트랜잭션을 RLP 인코딩할 때 signatures 또는 feePayerSignatures가 비어있는 경우, 해당 프로퍼티에는 빈 서명을 나타내는 [[ '0x01', '0x', '0x']]
값이 반환됩니다. 이 함수는 주어진 서명이 [[ '0x01', '0x', '0x']]
인지 ('legacy' 트랜잭션인 경우는 [ '0x01', '0x', '0x']
) 확인하고자 할 때 사용합니다.
참고 caver.utils.isEmptySig
는 caver-js v1.2.0부터 지원됩니다.
Parameters
Return Value
Examples
키가 KlaytnWalletKey 포맷이면 true
를 반환하고, 그렇지 않으면 false
를 반환합니다.
참고caver.utils.isKlaytnWalletKey
는 caver-js v1.3.2-rc.3부터 더 정확한 결과를 제공하기 위해 업데이트되었습니다.
Parameters
Return Value
Examples
Converts buffer to 0x-prefixed hex string.
참고 caver.utils.bufferToHex
는 caver-js v1.3.2-rc.1부터 지원됩니다.
Parameters
Return Value
Examples
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
Name | Type | Description |
---|---|---|
Type | Description |
---|---|
size
Number
HEX 문자열의 바이트 크기, 가령, 32
는 접두어 "0x"와 64개의 문자로 구성된 32바이트의 HEX 문자열이 결과가 될 것입니다.
String
The generated random HEX string.
mixed
String | Number
BN 객체로 변환할 숫자, 숫자 문자열 또는 HEX 문자열입니다.
Object
The BN.js instance.
bn
Object
A BN.js instance.
Boolean
true
if a given value is a BN.js instance.
bignumber
Object
A BigNumber.js instance.
Boolean
true
if a given value is a BigNumber.js
instance.
string
String
A string to hash.
String
The result hash.
paramX
Mixed
Any type, or an object with {type: 'uint', value: '123456'}
or {t: 'bytes', v: '0xfff456'}
. Basic types are autodetected as follows:
- String
non numerical UTF-8 string is interpreted as string
.
- `String
String
The result hash.
hex
String | HEX
The given HEX string.
Boolean
true
if a given string is a HEX string.
hex
String | HEX
The given HEX string.
Boolean
true
if a given string is a HEX string.
address
String
An address string.
Boolean
true
if a given string is a valid Klaytn address.
address
String
An address string.
String
The checksum address.
address
String
An address string.
Boolean
true
when the checksum of the address is valid, false
if it is not a checksum address, or the checksum is invalid.
mixed
String | Number | BN | BigNumber
HEX로 변환할 입력값.
String
The resulting HEX string.
number
String | Number | HEX
큰 숫자로 변환할 숫자.
Object
The BN.js instance.
hexString
HEX String
A HEX string to be converted.
String
The number as a string.
hexString
HEX String
A HEX string to be converted.
Number
The number representation of a given HEX value.
number
String | Number | BN | BigNumber
문자열 또는 숫자로 된 숫자.
String
The HEX value of the given number.
hex
String
A HEX string to convert to a UTF-8 string.
String
The UTF-8 string.
hex
String
ASCII 문자열로 변환할 HEX 문자열.
String
The ASCII string.
string
String
A UTF-8 string to convert to a HEX string.
String
The HEX string.
string
String
An ASCII string to convert to a HEX string.
String
The HEX string.
hex
HEX String
A HEX string to be converted.
Array
The byte array.
byteArray
Array
A byte array to convert.
String
The HEX string.
number
String | Number | BN
값.
unit
String
(선택 사항, 기본값은 "KLAY"
) 변환하려고 하는 KLAY. Possible units are:
- peb
: '1'
- kpeb
: '1000'
- Mpeb
: '1000000'
- Gpeb
: '1000000000'
- Ston
: '1000000000'
- uKLAY
: '1000000000000'
- mKLAY
: '1000000000000000'
- KLAY
: '1000000000000000000'
- kKLAY
: '1000000000000000000000'
- MKLAY
: '1000000000000000000000000'
- GKLAY
: '1000000000000000000000000000'
String | BN
숫자 또는 문자열이 주어지면 숫자 문자열을 반환하고, 그렇지 않으면 BN.js 인스턴스를 반환합니다.
number
String | Number | BN
peb 단위의 값.
unit
String
(선택 사항, 기본값은 "KLAY"
) 변환하고자 하는 KLAY. Possible units are:
- peb
: '1'
- kpeb
: '1000'
- Mpeb
: '1000000'
- Gpeb
: '1000000000'
- Ston
: '1000000000'
- uKLAY
: '1000000000000'
- mKLAY
: '1000000000000000'
- KLAY
: '1000000000000000000'
- kKLAY
: '1000000000000000000000'
- MKLAY
: '1000000000000000000000000'
- GKLAY
: '1000000000000000000000000000'
String | BN
If a number or a string is given, it returns a number string, otherwise a BN.js instance.
Object
With the following properties:
- peb
: '1'
- kpeb
: '1000'
- Mpeb
: '1000000'
- Gpeb
: '1000000000'
- Ston
: '1000000000'
- uKLAY
: '1000000000000'
- mKLAY
: '1000000000000000'
- KLAY
: '1000000000000000000'
- kKLAY
: '1000000000000000000000'
- MKLAY
: '1000000000000000000000000'
- GKLAY
: '1000000000000000000000000000'
string
String
The string to add padding on the left.
characterAmount
Number
The number of characters the total string should have.
sign
String
(선택 사항) 사용할 문자 부호, 기본값은 "0"
.
String
The padded string.
string
String
The string to add padding on the right.
characterAmount
Number
The number of characters the total string should have.
sign
String
(optional) The character sign to use, defaults to "0"
.
String
The padded string.
number
Number | String | BigNumber
변환할 숫자.
String
The converted hex string.
transactionObject
Object
트랜잭션이 스마트 컨트랙트 배포용인지 사용자가 확인하고자 하는 트랜잭션 객체.
Boolean
true
means the transaction object is for smart contract deploy.
publicKey
String
The publicKey to get x and y points.
Array
An array storing x and y points. Index 0 has x point, and index 1 has y point.
input
String
The value to be determined if the parameter is 0x-prefixed hex string or not.
Boolean
true
means the input is 0x-prefixed hex string.
input
String
0x 접두사를 더할 문자열 값.
String
0x-prefixed hex string is returned.
input
String
접두사 0x를 제거할 문자열.
String
A string stripped of 0x is returned.
input
Buffer | String | Number | Array | BN | Object
버퍼로 변환할 값.
Buffer
The value converted to Buffer type is returned.
input
String | Number | BN
버퍼로 변환할 숫자.
Buffer
The value converted to Buffer type is returned.
input
String
The value to be determined if the parameter is in the format of transaction hash or not.
Boolean
true
는 입력값이 트랜잭션 해시 형식임을 의미합니다.
input
String
The value to be determined if the parameter is in the format of transaction hash or not.
Boolean
true
means the input is in the format of transaction hash.
privateKey
String
A private key string to validate.
Boolean
true
means the privateKey is valid.
publicKey
String
A public key string to validate.
Boolean
true
means the publicKey is valid.
role
String
A role string to validate.
Boolean
true
means the role is valid.
sig
Array
비어있는지 확인할 서명의 배열.
Boolean
true
는 sig가 [[ '0x01', '0x', '0x']]
또는 [ '0x01', '0x', '0x']
임을 의미합니다.
key
String
A key string to check in the format of KlaytnWalletKey or not.
Boolean
true
means the key is 0x{private key}0x{type}0x{address in hex}
or {private key}0x{type}0x{address in hex}
.
buffer
Buffer
A buffer to convert to hex string.
String
The 0x-prefixed hex string.