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
Optional
compressed?: booleanOptional
provider?: ProviderInterfaceOptional
sendAccount address
Boolean determining if the public/private key is using the compressed format
Private
privateOptional
providerProvider to connect with the blockchain
Optional
sendOptions to apply when sending a transaction. By default broadcast is true and the other fields are undefined
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 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
recoverFunction 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: RecoverPublicKeyOptionsStatic
recoverStatic
recoverFunction 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: RecoverPublicKeyOptionsGenerated 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