Locus Library
서비스에 로커스 체인을 적용할때 필요한 함수가 포함된 라이브러리를 제공합니다 다음과 같은 기능이 포함되어 있습니다.
- 키를 생성하거나 불러옵니다.
- 데이터를 형식을 변환합니다.
- 트랜잭션을 검증합니다.
- 프라이빗 키로 서명합니다.
설치 방법
- Javascript
npm i @locuschain/lib
사용 방법
LocusLib.function(param1, param2, ... )
- function: 함수명
- param: 매개 변수
- Javascript
import { getLibraryVersions } from '@locuschain/lib/utils';
const result = getLibraryVersions()
console.log(result)
Functions
getLibraryVersions
GetLibraryVersion은 이 wasm 라이브러리의 버전을 반환합니다.
Input
getLibraryVersions( )
[None]
Output
| Key | Type | Description |
|---|---|---|
| LibraryVersion | int | 라이브러리 버전 |
| KeyStoreVersion | int | 키스토어 버전 |
| KeyStoreVersionMin | int | 호환되는 최소 키스토어 버전 |
| GoBuildVersion | string | Library를 빌드한 Golang 버전 |
createAccountAndKeystore
마스터 키와 노멀 키를 위한 두 개의 별도 키스토어 파일을 생성합니다.
Input
createAccountAndKeystore( params )
| Key | Type | Description |
|---|---|---|
| params.passwordMaster | string | 마스터 키 비밀번호 |
| params.passwordNormal | string | 노멀 키 비밀번호 |
| params.algoMaster | string | 마스터 키 알고리즘 |
| params.algoNormal | string | 노멀 키 알고리즘 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | 마스터 및 노멀 키스토어 문자열 |
createNormalKey
주어진 주소에 대한 새로운 노멀 키를 생성합니다.
Input
createNormalKey( params )
| Key | Type | Description |
|---|---|---|
| params.addrStr | string | 주소 |
| params.keyAlgo | string | 노멀 키 알고리즘 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | 노멀 키 문자열 |
createMasterKeystore
주어진 주소에 대한 마스터 키스토어를 생성합니다.
Input
createMasterKeystore( params )
| Key | Type | Description |
|---|---|---|
| params.addrStr | string | 주소 |
| params.password | string | 마스터 키 비밀번호 |
| params.mskStr | string | 마스터 비밀 키 |
| params.mpkStr | string | 마스터 공개 키 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | 마스터 키스토어 문자열 |
createNormalKeystore
주어진 주소에 대한 노멀 키스토어를 생성합니다.
Input
createNormalKeystore( params )
| Key | Type | Description |
|---|---|---|
| params.addrStr | string | 주소 |
| params.password | string | 노멀 키 비밀번호 |
| params.nskStr | string | 노멀 비밀 키 |
| params.npkStr | string | 노멀 공개 키 |
| params.mpkStr | string | 마스터 공개 키 |
| params.keySign | string | 키 서명 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | 노멀 키스토어 문자열 |
loadMasterKeystore
마스터 키스토어에서 마스터 키를 반환합니다.
Input
loadMasterKeystore( params )
| Key | Type | Description |
|---|---|---|
| params.passStr | string | 마스터 키 비밀번호 |
| params.ksJson | string | 마스터 키스토어 문자열 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | 마스터 키 문자열 |
loadNormalKeystore
노멀 키스토어에서 노멀 키를 반환합니다.
Input
loadNormalKeystore ( params )
| Key | Type | Description |
|---|---|---|
| params.passStr | string | 노멀 키 비밀번호 |
| params.ksJson | string | 노멀 키스토어 문자열 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | 노멀 키 문자열 |
convertToData
다양한 값을 기본 인코딩(base64)으로 디코딩합니다.
Input
convertToData( value, valueType )
| Key | Type | Description |
|---|---|---|
| value | string | |
| valueType | int | valueType : 0(raw string), 1(hex), 2(crc16-base32), 3(base64) |
Output
| Key | Type | Description |
|---|---|---|
| - | string |
convertDataTo
기본 인코딩(base64)된 값을 다양한 타입으로 변환합니다.
Input
convertDataTo( value, retType )
| Key | Type | Description |
|---|---|---|
| value | string | |
| retType | int | valueType : 0(raw string), 1(hex), 2(crc16-base32), 3(base64) |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertStringToData
문자열 값을 기본 인코딩(base64)으로 디코딩합니다.
Input
convertStringToData( raw )
| Key | Type | Description |
|---|---|---|
| raw | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertDataToString
기본 인코딩(base64)된 값을 문자열 값으로 디코딩합니다.
Input
convertDataToString ( str )
| Key | Type | Description |
|---|---|---|
| str | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertAddressToHex
base32 인코딩된 주소를 hex 값으로 디코딩합니다.
Input
convertAddressToHex( addrEncoded )
| Key | Type | Description |
|---|---|---|
| addrEncoded | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertHexToAddress
hex 값을 base32 인코딩된 주소로 인코딩합니다.
Input
convertHexToAddress( hexString )
| Key | Type | Description |
|---|---|---|
| hexString | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertAddressToData
base32 인코딩된 주 소를 기본 인코딩으로 디코딩합니다.
Input
convertAddressToData( addrEncoded )
| Key | Type | Description |
|---|---|---|
| addrEncoded | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertDataToAddress
기본 인코딩된 값을 base32 인코딩된 주소로 인코딩합니다.
Input
convertDataToAddress( str )
| Key | Type | Description |
|---|---|---|
| str | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertBase32ToHex
base32 인코딩된 값을 hex 값으로 디코딩합니다.
Input
convertBase32ToHex( encoded )
| Key | Type | Description |
|---|---|---|
| encoded | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertHexToBase32
hex 값을 base32 인코딩된 값으로 인코딩합니다.
Input
convertHexToBase32( hexString )
| Key | Type | Description |
|---|---|---|
| hexString | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertHexToData
hex 인코딩된 값을 기본 인코딩(base64)으로 디코딩합니다.
Input
convertHexToData( encoded )
| Key | Type | Description |
|---|---|---|
| encoded | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertDataToHex
기본 인코딩(base64)된 값을 hex 인코딩된 값으로 인코딩합니다.
Input
convertDataToHex( str )
| Key | Type | Description |
|---|---|---|
| str | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertBase32ToData
base32 인코딩된 값을 기본 인코딩(base64)으로 디코딩합니다. convertBase32ToData( encoded )
Input
| Key | Type | Description |
|---|---|---|
| encoded | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
convertDataToBase32
기본 인코딩(base64)된 값을 base32 인코딩된 값으로 인코딩합니다.
Input
convertDataToBase32( str )
| Key | Type | Description |
|---|---|---|
| str | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
signByMasterKey
마스터 비밀 키와 메시지로 서명을 생성합니다.
Input
signByMasterKey ( params )
| Key | Type | Description |
|---|---|---|
| params.msk | string | 마스터 비밀 키 |
| params.message | string | 사인할 메시지 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
sign
노멀 비밀 키와 메시지로 서명을 생성합니다.
Input
sign( params )
| Key | Type | Description |
|---|---|---|
| params.sk | string | 노멀 비밀 키 |
| params.message | string | 사인할 메시지 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
verify
메시지와 노멀 공개 키로 서명을 검증한 결과를 반환합니다.
Input
verify( params )
| Key | Type | Description |
|---|---|---|
| params.pk | string | 노멀 공개 키 |
| params.message | string | 검증할 메시지 |
| params.sign | string | 검증할 서명 |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
verifyTx
RPC로 생성된 모든 유형의 트랜잭션을 검증합니다.
Input
verifyTx( jsonTx )
| Key | Type | Description |
|---|---|---|
| jsonTx | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |
compileCoreScript
CompileCoreScript는 코어 스크립트 소스 코드를 바이트 코드로 컴파일합니다.
Input
compileCoreScript( params )
| Key | Type | Description |
|---|---|---|
| params.code | string |
Output
| Key | Type | Description |
|---|---|---|
| - | string | Result |