import { JsonTypes } from 'typedjson'; export type EventsMap = { connected: string; disconnected: void; accountChanged: string; locked: void; unlocked: void; }; export default abstract class BaseSigner { protected activeAccount?: string; protected connected: boolean; protected locked: boolean; private readonly events; on(name: K, listener: (ev: EventsMap[K]) => void): void; addEventListener(name: K, listener: (ev: EventsMap[K]) => void): void; off(name: K, listener: (ev: EventsMap[K]) => void): void; removeEventListener(name: K, listenerToRemove: (ev: EventsMap[K]) => void): void; protected emit(name: K, event: EventsMap[K]): void; /** * Returns Signer version */ abstract getVersion(): Promise; /** * Returns connection status from Signer */ abstract isConnected(): Promise; /** * Request connection to the Signer */ abstract connect(): Promise; /** * Disconnect from the Signer */ abstract disconnect(): Promise; /** * Request the signer to change active account * @returns changed active public key in hex format */ abstract changeAccount(): Promise; /** * Sign deploy from `DeployUtil.deployToJson` * * @param deploy - deploy in JSON format * @param signingPublicKey - public key in hex format, the corresponding private key will be used to sign. * * @throws Error if the Signer extension is not connected. * @throws Error if signingPublicKey is not available or does not match the Active Key in the Signer. * * @returns serialized deploy which can be converted into `Deploy` using `DeployUtil.deployFromJson` * * @example * import { DeployUtil } from "casper-js-sdk"; * * try { * const serializedDeploy = DeployUtil.deployToJson(deploy); * const signedSerializedDeploy = await signer.signDeploy(serializedDeploy, pulicKey); * const signedDeploy = DeployUtil.deployFromJson(signedSerializedDeploy).unwrap(); * } catch (error) { * if (isSignerError(error)) { * // handle signer error * } * // handle unknown error * } */ abstract signDeploy(deploy: { deploy: JsonTypes; }, signingPublicKey: string): Promise<{ deploy: JsonTypes; }>; /** * Sign message with given public key's private key * @param message string to be signed. * @param signingPublicKey public key in hex format, the corresponding private key will be used to sign. * @returns string in hex format * * @example * import { decodeBase16, verifyMessageSignature } from "casper-js-sdk"; * * try { * * const message = "Hello Casper"; * const signature = await signer.signMessage(message, publicKey); * const isValidSignature = verifyMessageSignature(CLPublicKey.fromHex(publicKey), message, decodeBase16(signature)); * * } catch(error) { * if (isSignerError(error)) { * // handle signer error * } * // handle unknown error * } */ abstract signMessage(message: string, signingPublicKey: string): Promise; /** * Retrives active public key in hex format * @returns string active public key in hex format */ abstract getActiveAccount(): Promise; }