KeyringContainer is a class that manages SingleKeyring, MultipleKeyring, and RoleBasedKeyring instances. Caver가 초기화될 때 caver.wallet 안에 KeyringContainer 인스턴스를 생성합니다. caver.wallet를 통해 인메모리 지갑에 키링 인스턴스를 저장하고 관리할 수 있습니다.
// generate without entropy>caver.wallet.generate(3)['0xb4b0c3781082cf818bfaf5adfc73fdf59d92c1cd','0x9957dfd92e4b70f91131c573293343bc5f21f215','0xed2fe179c18fa528da2392532998560bd1008511']// generate with entropy>caver.wallet.generate(3,caver.utils.randomHex(32))['0xb4b0c3781082cf818bfaf5adfc73fdf59d92c1cd','0x9957dfd92e4b70f91131c573293343bc5f21f215','0xed2fe179c18fa528da2392532998560bd1008511']
caver.wallet.newKeyring
caver.wallet.newKeyring(address, key)
주어진 파라미터로 키링 인스턴스를 생성하며 caver.wallet에 추가한다.
If key is a private key string, a SingleKeyring instance that uses a single private key is created. If key is an array containing private key strings, a MultipleKeyring instance that use multiple private keys is created. If key is a 2D array of which each element contains the private key(s) to be used for each role, a RoleBasedKeyring instance is created. 사용할 키링은 caver.wallet에 추가해야 합니다.
// Create a instance of SingleKeyring and add to caver.wallet>caver.wallet.newKeyring('0x{address in hex}','0x{private key}')SingleKeyring { _address:'0x386a4bb40abbfaa59cecdc3ced202475895fd569', _key: PrivateKey { _privateKey:'0x{private key}' }}// Create a instance of MultipleKeyring and add to caver.wallet>caver.wallet.newKeyring('0x{address in hex}', ['0x{private key1}','0x{private key2}'])MultipleKeyring { _address:'0x17e7531b40ad5d7b5fa7b4ec78df64ce1cb36d24', _keys: [ PrivateKey { _privateKey:'0x{private key1}' }, PrivateKey { _privateKey:'0x{private key2}' } ]}// Create a instance of RoleBasedKeyring and add to caver.wallet>constroleBasedKeys= [ ['0x{private key1}','0x{private key2}'], ['0x{private key3}','0x{private key4}'], ['0x{private key5}','0x{private key6}'],]>caver.wallet.newKeyring('0x{address in hex}', roleBasedKeys)RoleBasedKeyring { _address:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _keys: [ [ PrivateKey { _privateKey:'0x{private key1}' }, PrivateKey { _privateKey:'0x{private key2}' } ], [ PrivateKey { _privateKey:'0x{private key3}' }, PrivateKey { _privateKey:'0x{private key4}' } ], [ PrivateKey { _privateKey:'0x{private key5}' }, PrivateKey { _privateKey:'0x{private key6}' } ] ]}
caver.wallet.updateKeyring
caver.wallet.updateKeyring(keyring)
caver.wallet 안에 있는 키링을 업데이트합니다. When a new keyring instance (SingleKeyring, MultipleKeyring or RoleBasedKeyring) is passed as a parameter, the existing keyring stored in the caver.wallet that matches the address property of the given keyring instance is found and replaced with the given one. 일치하는 키링을 찾을 수 없는 경우 에러가 발생합니다.
Adds an instance of keyring to the caver.wallet. If the newly given keyring has the same address with one of the keyrings that already exist in caver.wallet, an error is returned. In this case, use updateKeyring to update the existing keyring in caver.wallet.
caver.wallet.signMessage(address, message, role [, index])
Signs the message with Klaytn-specific prefix using keyring stored in caver.wallet. 다음 메서드는 Klaytn 고유의 서명을 계산합니다.
sign(keccak256("\x19Klaytn Signed Message:\n" + len(message) + message)))
If the user has not provided the index parameter, caver.wallet.signMessage signs message using all the private keys used by the role. If the index parameter is given, caver.wallet.signMessage signs message using only one private key at the given index. The role used in caver-js can be found from caver.wallet.keyring.role.
Parameters
Name
Type
Description
address
string
사용될 키링의 주소입니다.
message
string
서명할 메시지입니다.
role
number
키의 역할을 나타내는 숫자입니다. caver.wallet.keyring.role를 사용할 수 있습니다.
index
number
(optional) The index of the private key you want to use. The index must be less than the length of the array of the private keys defined for each role. If an index is not defined, this method will use all the private keys.
Signs the transaction as a sender of the transaction and appends signatures in the transaction object using the keyring in caver.wallet.
For Account Update transaction, use roleTransactionKey, otherwise, use roleTransactionKey. If the user has not defined an index, caver.wallet.sign signs the transaction using all the private keys used by the role. If index is defined, the caver.wallet.sign signs the transaction using only one private key at the given index.
(optional) The index of the private key you want to use. The index must be less than the length of the array of the private keys defined for each role. If an index is not defined, this method will use all the private keys.
hasher
function
(optional) A hash function to get the transaction hash. If hasher is given as a parameter, it calculates the transaction hash instead of the default method for calculating transaction hash implemented in caver-js. See Basic for details about the default method for transaction hash generation.
Return Value
Promise returning object: The signed transaction.
Type
Description
object
서명된 트랜잭션 데이터입니다. The sign(s) is added to the transaction.signatures.
For more information about fields by transaction type, see caver.transaction.
Example
// This example uses the ValueTransfer transaction.// Please refer to [caver.transaction] for how to use various transaction types.>consttransaction=caver.transaction.valueTransfer.create({ from:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', value:1, gas:30000,})>constcustomHasher= () => { ... }// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleTransactionKey>caver.wallet.sign('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction).then(console.log)ValueTransfer { _type:'TxTypeValueTransfer', _from:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x4e43', _r:'0xd78a2...', _s:'0x379e9...' }, SignatureData { _v:'0x4e43', _r:'0x70a58...', _s:'0x2ab28...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleTransactionKey and index>caver.wallet.sign('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction,1).then(console.log)ValueTransfer { _type:'TxTypeValueTransfer', _from:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x4e43', _r:'0x70a58...', _s:'0x2ab28...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleTransactionKey and hasher>caver.wallet.sign('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction, customHasher).then(console.log)ValueTransfer { _type:'TxTypeValueTransfer', _from:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x4e44', _r:'0x7a8b6...', _s:'0x17139...' }, SignatureData { _v:'0x4e43', _r:'0x7f978...', _s:'0x1a532...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleTransactionKey, index and hasher>caver.wallet.sign('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction,0, customHasher).then(console.log)ValueTransfer { _type:'TxTypeValueTransfer', _from:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x4e44', _r:'0x7a8b6...', _s:'0x17139...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}
Signs the transaction as fee payer of the transaction and appends feePayerSignatures in the transaction object using the keyring in caver.wallet.
For signing a transaction as a fee payer, use roleFeePayerKey. If the user has not defined an index, caver.wallet.signAsFeePayer signs the transaction using all the private keys used by the role. If index is defined, the caver.wallet.signAsFeePayer signs the transaction using only one private key at the given index.
If the transaction.feePayer is not defined, the address of keyring which is founded from caver.wallet is assigned.
(optional) The index of the private key you want to use. The index must be less than the length of the array of the private keys defined for each role. If an index is not defined, this method will use all the private keys.
hasher
function
(optional) A function to get the transaction hash. If hasher is defined as a parameter, this is used to get the transaction hash instead of a default implementation in caver-js.
Return Value
Promise returning object: The signed transaction.
Type
Description
object
A signed transaction instance. The signing result is appended to the transaction.feePayerSignatures.
For more information about fields by transaction type, see caver.transaction.
Example
// This example uses the FeeDelegatedValueTransfer transaction.// Please refer to [caver.transaction] for how to use various transaction types.>consttransaction=caver.transaction.feeDelegatedValueTransfer.create({ from:'0x6fddbcb99d31b8755c2b840a367f53eea4b4f45c', to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', value:1, gas:30000,})>constcustomHasher= () => { ... }// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleFeePayerKey>caver.wallet.signAsFeePayer('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction).then(console.log)FeeDelegatedValueTransfer { _type:'TxTypeFeeDelegatedValueTransfer', _from:'0x6fddbcb99d31b8755c2b840a367f53eea4b4f45c', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x01', _r:'0x', _s:'0x' } ], _feePayer:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _feePayerSignatures: [ SignatureData { _v:'0x4e44', _r:'0x7010e...', _s:'0x65d6b...' }, SignatureData { _v:'0x4e43', _r:'0x96ef2...', _s:'0x77f34...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleFeePayerKey, index>caver.wallet.signAsFeePayer('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction,0).then(console.log)FeeDelegatedValueTransfer { _type:'TxTypeFeeDelegatedValueTransfer', _from:'0x6fddbcb99d31b8755c2b840a367f53eea4b4f45c', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x01', _r:'0x', _s:'0x' } ], _feePayer:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _feePayerSignatures: [ SignatureData { _v:'0x4e44', _r:'0x7010e...', _s:'0x65d6b...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleFeePayerKey and hasher>caver.wallet.signAsFeePayer('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction, customHasher).then(console.log)FeeDelegatedValueTransfer { _type:'TxTypeFeeDelegatedValueTransfer', _from:'0x6fddbcb99d31b8755c2b840a367f53eea4b4f45c', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x01', _r:'0x', _s:'0x' } ], _feePayer:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _feePayerSignatures: [ SignatureData { _v:'0x4e43', _r:'0xe48bf...', _s:'0x1cf36...' }, SignatureData { _v:'0x4e43', _r:'0x82976...', _s:'0x3c5e0...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}// Sign a transaction with the address of RoleBasedKeyring which use two private keys for roleFeePayerKey, index and hasher>caver.wallet.signAsFeePayer('0xe7e9184c125020af5d34eab7848bab799a1dcba9', transaction,0, customHasher).then(console.log)FeeDelegatedValueTransfer { _type:'TxTypeFeeDelegatedValueTransfer', _from:'0x6fddbcb99d31b8755c2b840a367f53eea4b4f45c', _gas:'0x7530', _signatures: [ SignatureData { _v:'0x01', _r:'0x', _s:'0x' } ], _feePayer:'0xe7e9184c125020af5d34eab7848bab799a1dcba9', _feePayerSignatures: [ SignatureData { _v:'0x4e43', _r:'0x82976...', _s:'0x3c5e0...' } ], _to:'0x3424b91026bdc5ec55df4548e6ebf0f28b60abd7', _value:'0x1', _chainId:'0x2710', _gasPrice:'0x5d21dba00', _nonce:'0x0'}