A Signer
is an interface that abstracts the interaction with a single Secp256k1 key pair. It exposes methods for
signing data, verifying signatures, and getting metadata associated with the key pair, such as the address.
Currently, the tm2-js-client
package provides support for two Signer
implementations:
- Key: a signer that is based on a raw Secp256k1 key pair.
- Ledger: a signer that is based on a Ledger device, with all interaction flowing through the user's device.
Returns the address associated with the signer's public key
Returns Promise
await signer.getAddress();
// "g1u7y667z64x2h7vc6fmpcprgey4ck233jaww9zq"
Returns the signer's Secp256k1-compressed public key
Returns Promise
await signer.getPublicKey();
// <Uint8Array>
Returns the signer's actual raw private key
Returns Promise
await signer.getPrivateKey();
// <Uint8Array>
Generates a data signature for arbitrary input
data
Uint8Array the data to be signed
Returns Promise
const dataToSign: Uint8Array = // ...
await signer.signData(dataToSign);
// <Uint8Array>
Verifies if the signature matches the provided raw data
data
Uint8Array the raw data (not-hashed)signature
Uint8Array the hashed-data signature
Returns Promise
const signedData: Uint8Array = // ...
const rawData: Uint8Array = // ...
await signer.verifySignature(rawData, signedData);
// <Uint8Array>