본문으로 건너뛰기

Locus Library

서비스에 로커스 체인을 적용할때 필요한 함수가 포함된 라이브러리를 제공합니다 다음과 같은 기능이 포함되어 있습니다.

  • 키를 생성하거나 불러옵니다.
  • 데이터를 형식을 변환합니다.
  • 트랜잭션을 검증합니다.
  • 프라이빗 키로 서명합니다.

설치 방법

npm i @locuschain/lib

사용 방법

LocusLib.function(param1, param2, ... )

  • function: 함수명
  • param: 매개 변수
import { getLibraryVersions } from '@locuschain/lib/utils';
const result = getLibraryVersions()
console.log(result)

Functions


getLibraryVersions

GetLibraryVersion은 이 wasm 라이브러리의 버전을 반환합니다.

Input

getLibraryVersions( )
[None]

Output

KeyTypeDescription
LibraryVersionint라이브러리 버전
KeyStoreVersionint키스토어 버전
KeyStoreVersionMinint호환되는 최소 키스토어 버전
GoBuildVersionstringLibrary를 빌드한 Golang 버전

createAccountAndKeystore

마스터 키와 노멀 키를 위한 두 개의 별도 키스토어 파일을 생성합니다.

Input

createAccountAndKeystore( params )

KeyTypeDescription
params.passwordMasterstring마스터 키 비밀번호
params.passwordNormalstring노멀 키 비밀번호
params.algoMasterstring마스터 키 알고리즘
params.algoNormalstring노멀 키 알고리즘

Output

KeyTypeDescription
-string마스터 및 노멀 키스토어 문자열

createNormalKey

주어진 주소에 대한 새로운 노멀 키를 생성합니다.

Input

createNormalKey( params )

KeyTypeDescription
params.addrStrstring주소
params.keyAlgostring노멀 키 알고리즘

Output

KeyTypeDescription
-string노멀 키 문자열

createMasterKeystore

주어진 주소에 대한 마스터 키스토어를 생성합니다.

Input

createMasterKeystore( params )

KeyTypeDescription
params.addrStrstring주소
params.passwordstring마스터 키 비밀번호
params.mskStrstring마스터 비밀 키
params.mpkStrstring마스터 공개 키

Output

KeyTypeDescription
-string마스터 키스토어 문자열

createNormalKeystore

주어진 주소에 대한 노멀 키스토어를 생성합니다.

Input

createNormalKeystore( params )

KeyTypeDescription
params.addrStrstring주소
params.passwordstring노멀 키 비밀번호
params.nskStrstring노멀 비밀 키
params.npkStrstring노멀 공개 키
params.mpkStrstring마스터 공개 키
params.keySignstring키 서명

Output

KeyTypeDescription
-string노멀 키스토어 문자열

loadMasterKeystore

마스터 키스토어에서 마스터 키를 반환합니다.

Input

loadMasterKeystore( params )

KeyTypeDescription
params.passStrstring마스터 키 비밀번호
params.ksJsonstring마스터 키스토어 문자열

Output

KeyTypeDescription
-string마스터 키 문자열

loadNormalKeystore

노멀 키스토어에서 노멀 키를 반환합니다.

Input

loadNormalKeystore ( params )

KeyTypeDescription
params.passStrstring노멀 키 비밀번호
params.ksJsonstring노멀 키스토어 문자열

Output

KeyTypeDescription
-string노멀 키 문자열

convertToData

다양한 값을 기본 인코딩(base64)으로 디코딩합니다.

Input

convertToData( value, valueType )

KeyTypeDescription
valuestring
valueTypeintvalueType : 0(raw string), 1(hex), 2(crc16-base32), 3(base64)

Output

KeyTypeDescription
-string

convertDataTo

기본 인코딩(base64)된 값을 다양한 타입으로 변환합니다.

Input

convertDataTo( value, retType )

KeyTypeDescription
valuestring
retTypeintvalueType : 0(raw string), 1(hex), 2(crc16-base32), 3(base64)

Output

KeyTypeDescription
-stringResult

convertStringToData

문자열 값을 기본 인코딩(base64)으로 디코딩합니다.

Input

convertStringToData( raw )

KeyTypeDescription
rawstring

Output

KeyTypeDescription
-stringResult

convertDataToString

기본 인코딩(base64)된 값을 문자열 값으로 디코딩합니다.

Input

convertDataToString ( str )

KeyTypeDescription
strstring

Output

KeyTypeDescription
-stringResult

convertAddressToHex

base32 인코딩된 주소를 hex 값으로 디코딩합니다.

Input

convertAddressToHex( addrEncoded )

KeyTypeDescription
addrEncodedstring

Output

KeyTypeDescription
-stringResult

convertHexToAddress

hex 값을 base32 인코딩된 주소로 인코딩합니다.

Input

convertHexToAddress( hexString )

KeyTypeDescription
hexStringstring

Output

KeyTypeDescription
-stringResult

convertAddressToData

base32 인코딩된 주소를 기본 인코딩으로 디코딩합니다.

Input

convertAddressToData( addrEncoded )

KeyTypeDescription
addrEncodedstring

Output

KeyTypeDescription
-stringResult

convertDataToAddress

기본 인코딩된 값을 base32 인코딩된 주소로 인코딩합니다.

Input

convertDataToAddress( str )

KeyTypeDescription
strstring

Output

KeyTypeDescription
-stringResult

convertBase32ToHex

base32 인코딩된 값을 hex 값으로 디코딩합니다.

Input

convertBase32ToHex( encoded )

KeyTypeDescription
encodedstring

Output

KeyTypeDescription
-stringResult

convertHexToBase32

hex 값을 base32 인코딩된 값으로 인코딩합니다.

Input

convertHexToBase32( hexString )

KeyTypeDescription
hexStringstring

Output

KeyTypeDescription
-stringResult

convertHexToData

hex 인코딩된 값을 기본 인코딩(base64)으로 디코딩합니다.

Input

convertHexToData( encoded )

KeyTypeDescription
encodedstring

Output

KeyTypeDescription
-stringResult

convertDataToHex

기본 인코딩(base64)된 값을 hex 인코딩된 값으로 인코딩합니다.

Input

convertDataToHex( str )

KeyTypeDescription
strstring

Output

KeyTypeDescription
-stringResult

convertBase32ToData

base32 인코딩된 값을 기본 인코딩(base64)으로 디코딩합니다. convertBase32ToData( encoded )

Input

KeyTypeDescription
encodedstring

Output

KeyTypeDescription
-stringResult

convertDataToBase32

기본 인코딩(base64)된 값을 base32 인코딩된 값으로 인코딩합니다.

Input

convertDataToBase32( str )

KeyTypeDescription
strstring

Output

KeyTypeDescription
-stringResult

signByMasterKey

마스터 비밀 키와 메시지로 서명을 생성합니다.

Input

signByMasterKey ( params )

KeyTypeDescription
params.mskstring마스터 비밀 키
params.messagestring사인할 메시지

Output

KeyTypeDescription
-stringResult

sign

노멀 비밀 키와 메시지로 서명을 생성합니다.

Input

sign( params )

KeyTypeDescription
params.skstring노멀 비밀 키
params.messagestring사인할 메시지

Output

KeyTypeDescription
-stringResult

verify

메시지와 노멀 공개 키로 서명을 검증한 결과를 반환합니다.

Input

verify( params )

KeyTypeDescription
params.pkstring노멀 공개 키
params.messagestring검증할 메시지
params.signstring검증할 서명

Output

KeyTypeDescription
-stringResult

verifyTx

RPC로 생성된 모든 유형의 트랜잭션을 검증합니다.

Input

verifyTx( jsonTx )

KeyTypeDescription
jsonTxstring

Output

KeyTypeDescription
-stringResult

compileCoreScript

CompileCoreScript는 코어 스크립트 소스 코드를 바이트 코드로 컴파일합니다.

Input

compileCoreScript( params )

KeyTypeDescription
params.codestring

Output

KeyTypeDescription
-stringResult

disCompileCoreScript

DisCompileCoreScript는 코어 스크립트의 바이트 코드를 디컴파일합니다. DisCompileCoreScript는 구문 오류를 감지하지 않습니다.

Input

disCompileCoreScript( params )

KeyTypeDescription
params.codestring

Output

KeyTypeDescription
-stringResult

testCoreScript

TestCoreScript는 TxDataProvide 및 TxDataAccept와 함께 ScriptProvide 및 ScriptAccept를 테스트합니다.

Input

testCoreScript( params )

KeyTypeDescription
params.scriptProvidestring제공 스크립트 코드
params.scriptAcceptstring수락 스크립트 코드
params.txDataProvidetypes.ParamTxData제공 스크립트의 파라미터
params.txDataAccepttypes.ParamTxData수락 스크립트의 파라미터

types.ParamTxData

KeyTypeDescription
rounduint32
heightint32
args[]string

Output

KeyTypeDescription
-stringResult

getDefFromCoreScript

GetDefFromCoreScript는 바이트 코드에서 정의를 가져옵니다.

Input

getDefFromCoreScript ( params )

KeyTypeDescription
params.codestring

Output

KeyTypeDescription
-stringResult

encodeTxNumber

EncodeTxNumber는 숫자 타입 데이터를 []byte로 인코딩합니다.

Input

encodeTxNumber ( params )

KeyTypeDescription
params.numberstring
params.typeint

Output

KeyTypeDescription
-stringResult

encodeTxCurrency

EncodeTxCurrency는 통화를 []byte로 인코딩합니다.

Input

encodeTxCurrency( params )

KeyTypeDescription
params.currencystring

Output

KeyTypeDescription
-stringResult

hash

Hash는 해시 유형에 따라 데이터를 해싱합니다.

Input

hash ( params )

KeyTypeDescription
params.datastring
params.typeint

Output

KeyTypeDescription
-stringResult

verifyMerkleProof

VerifyMerkleProof는 Hash와 GoalHash로 Proof를 검증합니다.

Input

verifyMerkleProof ( params )

KeyTypeDescription
params.proofstring
params.hashstring
params.goalHashstring

Output

KeyTypeDescription
boolResult

calculateTxLinkHash

TxLink 해시를 계산합니다.

Input

calculateTxLinkHash( params )

KeyTypeDescription
params.txstringTx 문자열

Output

KeyTypeDescription
-stringResult

decodeTxs

DecodeTxs는 노드에서 다운로드한 base64 인코딩된 트랜잭션을 디코딩합니다.

Input

decodeTxs ( params )

KeyTypeDescription
params.txs[]stringTx 문자열 배열

Output

KeyTypeDescription
-stringResult

gzipAndEncode

문자열을 압축한 다음 base64로 인코딩합니다.

Input

gzipAndEncode ( str )

KeyTypeDescription
strstring

Output

KeyTypeDescription
-stringResult

convertCurrency

통화 값을 한 단위에서 다른 단위로 변환합니다.

Input

convertCurrency( params )

KeyTypeDescription
params.vstring
params.fromUnitnumber출발 단위
params.toUnitnumber도착 단위

Output

KeyTypeDescription
-stringResult

makeCurrency

x와 단위로부터 통화 값을 생성합니다.

Input

makeCurrency( params )

KeyTypeDescription
params.xstring
params.unitnumber단위

Output

KeyTypeDescription
-stringResult

getHomeShard

주어진 계정에 대한 홈 샤드 ID를 반환합니다.

Input

getHomeShard( params )

KeyTypeDescription
params.accountstring계정
params.totalShardnumber총 샤드 수

Output

KeyTypeDescription
-numberResult

generateMnemonic

지정된 엔트로피 비트 크기로 니모닉 구문을 생성합니다.

Input

generateMnemonic( params )

KeyTypeDescription
params.entropyBitnumber엔트로피 비트

Output

KeyTypeDescription
-stringResult

generateMnemonicBySeed

시드로부터 니모닉 구문을 생성합니다.

Input

generateMnemonicBySeed( params )

KeyTypeDescription
params.seedstring시드

Output

KeyTypeDescription
-stringResult

deriveKeysFromMnemonic

니모닉 구문에서 키를 파생합니다.

Input

deriveKeysFromMnemonic( params )

KeyTypeDescription
params.mnemonicstring니모닉
params.pathstring경로
params.atunumberatu

Output

KeyTypeDescription
-stringResult

isGrantConsumingTx

트랜잭션 타입이 그랜트를 소비하는지 확인합니다.

Input

isGrantConsumingTx( txTypeStr )

KeyTypeDescription
txTypeStrstring트랜잭션 타입 문자열

Output

KeyTypeDescription
-GrantConsumeResultResult

verifyByMasterKey

마스터 공개 키를 사용하여 서명을 검증합니다.

Input

verifyByMasterKey( params )

KeyTypeDescription
params.pkstring공개 키
params.messagestring검증할 메시지
params.signstring서명

Output

KeyTypeDescription
-stringResult

checkAddressType

주소가 어떤 주소 타입인지 확인합니다.

Input

checkAddressType( address )

KeyTypeDescription
addressstring주소

Output

KeyTypeDescription
-numberResult

isAccount

주소 타입이 계정 주소인지 확인합니다.

Input

isAccount( addressType )

KeyTypeDescription
addressTypenumber주소 타입 (AddressClass type 참고)

Output

KeyTypeDescription
-booleanResult

isContract

주소 타입이 컨트랙트 주소인지 확인합니다.

Input

isContract( addressType )

KeyTypeDescription
addressTypenumber주소 타입 (AddressClass type 참고)

Output

KeyTypeDescription
-booleanResult

isToken

주소 타입이 토큰 주소인지 확인합니다.

Input

isToken( addressType )

KeyTypeDescription
addressTypenumber주소 타입 (AddressClass type 참고)

Output

KeyTypeDescription
-booleanResult

isSystemToken

주소 타입이 시스템 토큰 주소인지 확인합니다.

Input

isSystemToken( addressType )

KeyTypeDescription
addressTypenumber주소 타입 (AddressClass type 참고)

Output

KeyTypeDescription
-booleanResult

loadLocusWasm

Locus WASM 모듈을 로드합니다.

Input

loadLocusWasm( ) [None]

Output

KeyTypeDescription
-Promise<void>Result

loadLocusWasmSync

Locus WASM 모듈을 동기로 로드합니다.

Input

loadLocusWasmSync( ) [None]

Output

KeyTypeDescription
-voidResult

verifyTxParams

트랜잭션 파라미터를 검증합니다.

Input

verifyTxParams( rpcResult, params, options )

KeyTypeDescription
rpcResulttypes.generatedTx노드가 생성한 tx
paramsobject검증할 파라미터
optionsOptions옵션

types.generatedTx

KeyTypeDescription
hashstring트랜잭션 해시
txany트랜잭션

types.Options

KeyTypeDescription
targetTxHashstring|false

Output

KeyTypeDescription
resultboolean | string검증 결과 (true/false) 혹은 에러 메시지
reasonstring실패 사유
fieldstring(Option) 실패한 필드명
txHashstring(Option) 트랜잭션 해시