caver.wallet
Last updated
Last updated
caver.wallet
is a package that manages instances in in-memory wallet. caver.wallet
accepts all , , and , and manages them by address.
KeyringContainer
is a class that manages , , and instances. When Caver is instantiated, it creates a KeyringContainer instance in the caver.wallet
. You can store and manage keyring instances in the in-memory wallet through caver.wallet
.
properties
length
number
The number of keyrings in keyringContainer.
Generates instances of in the keyringContainer with randomly generated private keys.
Parameters
numberOfKeyrings
number
entropy
string
(optional) A random string to increase entropy.
Return Value
Array
An array containing the addresses of the generated.
Example
Creates a keyring instance with given parameters and adds it to the caver.wallet
.
Parameters
address
string
The address string.
key
string | Array
Return Value
object
Example
Parameters
keyring
object
Return Value
object
Example
Returns the keyring instance corresponding to the address in caver.wallet
.
Parameters
address
string
The address of keyring to query.
Return Value
object
Example
Returns true
if there is a keyring matching the address.
Parameters
address
string
The address of keyring to check existence.
Return Value
boolean
true
means a keyring matching with the address is existed in the caver.wallet
.
Example
Parameters
keyring
object
Return Value
object
Example
Deletes the keyring from caver.wallet
whose address matches the address of the given keyring.
Parameters
address
string
An address of the keyring to be deleted in caver.wallet
.
Return Value
boolean
true
if keyring is removed from caver.wallet
.
Example
Signs the message with Klaytn-specific prefix using keyring stored in caver.wallet. This calculates a Klaytn-specific signature with:
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
address
string
An address of the keyring to be used.
message
string
The message to sign.
role
number
A number indicating the role of the key. You can use 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.
Return Value
object
An object that includes the result of signing.
The returned object contains the following:
messageHash
string
The hash of message with Klaytn-specific prefix.
signatures
Array
message
string
The message to sign.
Example
Signs the transaction as a sender
of the transaction and appends signatures
in the transaction object using the keyring in caver.wallet
.
Parameters
address
string
An address of the keyring to be used.
transaction
object
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.
hasher
function
Return Value
Promise
returning object
: The signed transaction.
object
A signed transaction instance. The sign(s) is added to the transaction.signatures
.
Example
Signs the transaction as fee payer
of the transaction and appends feePayerSignatures
in the transaction object using the keyring in caver.wallet
.
If the transaction.feePayer
is not defined, the address of keyring which is founded from caver.wallet
is assigned.
Parameters
address
string
An address of the keyring to be used.
transaction
object
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.
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.
object
A signed transaction instance. The signing result is appended to the transaction.feePayerSignatures
.
Example
The number of instances to create.
If key
is a private key string, a instance that uses a single private key is created. If key
is an array containing private key strings, a 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 instance is created. The keyring created is added to caver.wallet
.
The private key string, an array of private keys, or a 2D array of which each array element contains keys defined for each .
The keyring instance (, or ) added to caver.wallet is returned.
Updates the keyring inside the caver.wallet
. When a new keyring
instance (, or ) 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. An error occurs when the matching keyring is not found.
The new keyring (, or ) to be stored in caver.wallet
.
The updated keyring (, or ) stored in caver.wallet
.
The found keyring instance (, or ) stored in caver.wallet
.
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 to update the existing keyring in caver.wallet
.
A keyring instance (, or ) to add to caver.wallet
.
The added keyring (, or ) in caver.wallet
.
An array of .
For transaction, use , otherwise, use . 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.
An instance of .
(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 for details about the default method for transaction hash generation.
For more information about fields by transaction type, see .
For signing a transaction as a fee payer, use . 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.
An instance of .
For more information about fields by transaction type, see .