/****************************************************************************** * * (C) 2022 AhnLab Blockchain Company, Inc. All rights reserved. * Any part of this source code can not be copied with any method without * prior written permission from the author or authorized person. * ******************************************************************************/ /// import EventEmitter from 'events'; import { MpcService } from '../../usecase/mpc'; import { ProviderConnectionManager } from '../../usecase/provider/connectionManager'; import { Account } from '../../schema/model'; import { AppAccount } from '../transactions/interface'; declare class PersonalMessageManager extends EventEmitter { private mpcService; private providerConnectionManager; messages: any; /** * Controller in charge of managing - storing, adding, removing, updating - PersonalMessage. * * @typedef {Object} PersonalMessageManager * @property {Object} memStore The observable store where PersonalMessage are saved. * @property {Object} memStore.unapprovedPersonalMsgs A collection of all PersonalMessages in the 'unapproved' state * @property {number} memStore.unapprovedPersonalMsgCount The count of all PersonalMessages in this.memStore.unapprobedMsgs * @property {Array} messages Holds all messages that have been created by this PersonalMessageManager * */ constructor(mpcService: MpcService, providerConnectionManager: ProviderConnectionManager); /** * A getter for the number of 'unapproved' PersonalMessages in this.messages * * @returns {number} The number of 'unapproved' PersonalMessages in this.messages * */ get unapprovedPersonalMsgCount(): number; /** * A getter for the 'unapproved' PersonalMessages in this.messages * * @returns {Object} An index of PersonalMessage ids to PersonalMessages, for all 'unapproved' PersonalMessages in * this.messages * */ getUnapprovedMsgs(): any; /** * Creates a new PersonalMessage with an 'unapproved' status using the passed msgParams. this.addMsg is called to add * the new PersonalMessage to this.messages, and to save the unapproved PersonalMessages from that list to * this.memStore. * * @param {Object} msgParams - The params for the eth_sign call to be made after the message is approved. * @param {Object} [req] - The original request object possibly containing the origin * @param {Object} abcAccount - ABC App Account * @returns {promise} When the message has been signed or rejected * */ addUnapprovedMessageAsync(req: any, res: any, abcAccount: AppAccount): Promise; /** * Creates a new PersonalMessage with an 'unapproved' status using the passed msgParams. this.addMsg is called to add * the new PersonalMessage to this.messages, and to save the unapproved PersonalMessages from that list to * this.memStore. * * @param {Object} msgParams - The params for the eth_sign call to be made after the message is approved. * @param {Object} [req] - The original request object possibly containing the origin * @returns {number} The id of the newly created PersonalMessage. * */ addUnapprovedMessage(req: any): Promise; getMsgParams(req: any): any; /** * Signifies a user's approval to sign a personal_sign message in queue. * Triggers signing, and the callback function from newUnsignedPersonalMessage. * * @param {Object} msgParams - The params of the message to sign & return to the Dapp. * @returns {Promise} A full state update. */ signPersonalMessage(msgParams: any, abcAccount: Account, accToken: string): Promise; ledgerPrepSignPersonalMessage(msgParams: any, abcAccount: AppAccount): Promise<{ activateDto: { address: string; index: string; hdPath: string; deviceName: string; accountDetail: any; }; message: any; msgId: any; }>; personalRecover(req: any, res: any): Promise; /** * Adds a passed PersonalMessage to this.messages, and calls this._saveMsgList() to save the unapproved PersonalMessages from that * list to this.memStore. * * @param {Message} msg - The PersonalMessage to add to this.messages * */ addMsg(msg: any): Promise; /** * Returns a specified PersonalMessage. * * @param {number} msgId - The id of the PersonalMessage to get * @returns {PersonalMessage|undefined} The PersonalMessage with the id that matches the passed msgId, or undefined * if no PersonalMessage has that id. * */ getMsg(msgId: any): any; /** * Approves a PersonalMessage. Sets the message status via a call to this.setMsgStatusApproved, and returns a promise * with any the message params modified for proper signing. * * @param {Object} msgParams - The msgParams to be used when eth_sign is called, plus data added by MetaMask. * @param {Object} msgParams.metamaskId Added to msgParams for tracking and identification within MetaMask. * @returns {Promise} Promises the msgParams object with metamaskId removed. * */ approveMessage(msgParams: any): Promise; /** * Sets a PersonalMessage status to 'approved' via a call to this._setMsgStatus. * * @param {number} msgId - The id of the PersonalMessage to approve. * */ setMsgStatusApproved(msgId: any): void; /** * Sets a PersonalMessage status to 'signed' via a call to this._setMsgStatus and updates that PersonalMessage in * this.messages by adding the raw signature data of the signature request to the PersonalMessage * * @param {number} msgId - The id of the PersonalMessage to sign. * @param {buffer} rawSig - The raw data of the signature request * */ setMsgStatusSigned(msgId: any, rawSig: any): void; /** * Removes the metamaskId property from passed msgParams and returns a promise which resolves the updated msgParams * * @param {Object} msgParams - The msgParams to modify * @returns {Promise} Promises the msgParams with the metamaskId property removed * */ prepMsgForSigning(msgParams: any): Promise; /** * Sets a PersonalMessage status to 'rejected' via a call to this._setMsgStatus. * * @param {number} msgId - The id of the PersonalMessage to reject. * */ rejectMsg(msgId: any): void; /** * Updates the status of a PersonalMessage in this.messages via a call to this._updateMsg * * @private * @param {number} msgId - The id of the PersonalMessage to update. * @param {string} status - The new status of the PersonalMessage. * @throws A 'PersonalMessageManager - PersonalMessage not found for id: "${msgId}".' if there is no PersonalMessage * in this.messages with an id equal to the passed msgId * @fires An event with a name equal to `${msgId}:${status}`. The PersonalMessage is also fired. * @fires If status is 'rejected' or 'signed', an event with a name equal to `${msgId}:finished` is fired along * with the PersonalMessage * */ _setMsgStatus(msgId: any, status: any): void; /** * Sets a PersonalMessage in this.messages to the passed PersonalMessage if the ids are equal. Then saves the * unapprovedPersonalMsgs index to storage via this._saveMsgList * * @private * @param {msg} PersonalMessage - A PersonalMessage that will replace an existing PersonalMessage (with the same * id) in this.messages * */ _updateMsg(msg: any): Promise; /** * Saves the unapproved PersonalMessages, and their count, to this.memStore * * @private * @fires 'updateBadge' * */ _saveMsgList(): Promise; /** * A helper function that converts raw buffer data to a hex, or just returns the data if it is already formatted as a hex. * * @param {any} data - The buffer data to convert to a hex * @returns {string} A hex string conversion of the buffer data * */ normalizeMsgData(data: any): any; /** * Prefixes a hex string with '0x' or '-0x' and returns it. Idempotent. * * @param {string} str - The string to prefix. * @returns {string} The prefixed string. */ _addHexPrefix: (str: any) => any; } export default PersonalMessageManager;