The constructor receives de private key as hexstring, bigint or Uint8Array. See also the functions Signer.fromWif and Signer.fromSeed to create the signer from the WIF or Seed respectively.
const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
cons signer = new Signer({ privateKey });
console.log(signer.getAddress());
// 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
By default the mana is estimated as 110% the mana used. This estimation is computed using the "broadcast:false" option. For instance, if the transaction consumes 1 mana, the rc_limit will be set to 1.1 mana.
You can also adjust the rc limit.
const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
cons signer = new Signer({
privateKey,
provider,
rcOptions: {
estimateRc: true,
// use 2 times rc_used as rc_limit
adjustRcLimit: (r) => 2 * Number(r.rc_used),
},
});
The rpc node must be highly trusted because the transaction is signed during the estimation of the mana. You can also disable the mana estimation:
const privateKey = "ec8601a24f81decd57f4b611b5ac6eb801cb3780bb02c0f9cdfe9d09daaddf9c";
cons signer = new Signer({
privateKey,
provider,
rcOptions: { estimateRc: false },
});
Optional
compressed?: booleanOptional
provider?: ProviderOptional
rcOptional
sendAccount address
Boolean determining if the public/private key is using the compressed format
Private
privateOptional
providerProvider to connect with the blockchain
Options related to the estimation of the rcLimit. By default the estimation is enabled and increased by 10%.
This code estimates the mana by multiplying the rc_used by 2.
const signer = new Signer({
privateKey,
provider,
rcOptions: {
estimateRc: true,
adjustRcLimit: (receipt) => 2 * Number(receipt.rc_used),
},
});
// you can also update rcOptions
signer.rcOptions = {
estimateRc: true,
adjustRcLimit: (receipt) => 2 * Number(receipt.rc_used),
}
Optional
sendOptions to apply when sending a transaction. By default broadcast is true and the other fields are undefined
Estimate the receipt associated to the transaction if it sent to the blockchain. It is useful to estimate the consumption of mana. The transaction is signed during this process and sent to the rpc node with the "broadcast:false" option to just compute the transaction without broadcasting it to the network. After that, the initial signatures are restored (if any) and the ones used for the estimation will be removed.
Function to get the private key in hex format or wif format
const signer = Signer.fromSeed("one two three four five six");
console.log(signer.getPrivateKey());
// bab7fd6e5bd624f4ea0c33f7e7219262a6fa93a945a8964d9f110148286b7b37
console.log(signer.getPrivateKey("wif"));
// L3UfgFJWmbVziGB1uZBjkG1UjKkF7hhpXWY7mbTUdmycmvXCVtiL
console.log(signer.getPrivateKey("wif", false));
// 5KEX4TMHG66fT7cM9HMZLmdp4hVq4LC4X2Fkg6zeypM5UteWmtd
The format must be "hex" (default) or "wif"
Optional arg when using WIF format. By default it uses the compressed value defined in the signer
Function to recover the signer addresses from a signed transaction or block. The output format can be compressed (default) or uncompressed.
const addresses = await signer.recoverAddress(tx);
If the signature data contains more data, like in the blocks for PoW consensus, use the "transformSignature" function to extract the signature.
const powDescriptorJson = {
nested: {
mypackage: {
nested: {
pow_signature_data: {
fields: {
nonce: {
type: "bytes",
id: 1,
},
recoverable_signature: {
type: "bytes",
id: 2,
},
},
},
},
},
},
};
const serializer = new Serializer(powDescriptorJson, {
defaultTypeName: "pow_signature_data",
});
const addresses = await signer.recoverAddress(block, {
transformSignature: async (signatureData) => {
const powSignatureData = await serializer.deserialize(signatureData);
return powSignatureData.recoverable_signature;
},
});
Optional
opts: RecoverPublicKeyOptionsFunction to recover the publics keys from a signed transaction or block. The output format can be compressed (default) or uncompressed.
const publicKeys = await Signer.recoverPublicKeys(tx);
If the signature data contains more data, like in the blocks for PoW consensus, use the "transformSignature" function to extract the signature.
const powDescriptorJson = {
nested: {
mypackage: {
nested: {
pow_signature_data: {
fields: {
nonce: {
type: "bytes",
id: 1,
},
recoverable_signature: {
type: "bytes",
id: 2,
},
},
},
},
},
},
};
const serializer = new Serializer(powDescriptorJson, {
defaultTypeName: "pow_signature_data",
});
const publicKeys = await signer.recoverPublicKeys(block, {
transformSignature: async (signatureData) => {
const powSignatureData = await serializer.deserialize(signatureData);
return powSignatureData.recoverable_signature;
},
});
Optional
opts: RecoverPublicKeyOptionsFunction to sign and send a transaction. It internally uses Provider.sendTransaction
Transaction to send. It will be signed inside this function if it is not signed yet
Optional
options: SendTransactionOptionsOptions for sending the transaction
Function to sign a block for federated consensus. That is, just the ecdsa signature. For other algorithms, like PoW, you have to sign the block and then process the signature to add the extra data (nonce in the case of PoW).
Unsigned block
Function to sign a transaction. It's important to remark that the transaction parameter is modified inside this function.
Unsigned transaction
Optional
_abis: Record<string, Abi>Static
fromFunction to import a private key from the seed
const signer = Signer.fromSeed("my seed");
console.log(signer.getAddress());
// 1BqtgWBcqm9cSZ97avLGZGJdgso7wx6pCA
Signer object
Seed words
Static
fromFunction to import a private key from the WIF
const signer = Signer.fromWif("L59UtJcTdNBnrH2QSBA5beSUhRufRu3g6tScDTite6Msuj7U93tM")
console.log(signer.getAddress());
// 1MbL6mG8ASAvSYdoMnGUfG3ZXkmQ2dpL5b
Signer object
Private key in WIF format
Static
recoverStatic
recoverGenerated using TypeDoc
The Signer Class contains the private key needed to sign transactions. It can be created using the seed, wif, or private key
Example
using private key as hex string
using private key as Uint8Array
using private key as bigint
using the seed
using private key in WIF format
defining a provider