diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index a3429e1..76f43fd 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -197,7 +197,7 @@ export class Brizo extends Instantiable { public async createSignature(account: Account, message: string): Promise { const signature = (await account.getToken()) || - (await this.ocean.utils.signature.signText(message, account.getId())) + (await this.ocean.utils.signature.signWithHash(message, account.getId())) return signature } diff --git a/src/ocean/utils/SignatureUtils.ts b/src/ocean/utils/SignatureUtils.ts index 81a29d9..cb75f13 100644 --- a/src/ocean/utils/SignatureUtils.ts +++ b/src/ocean/utils/SignatureUtils.ts @@ -15,6 +15,33 @@ export class SignatureUtils { text: string, publicKey: string, password?: string + ): Promise { + const isMetaMask = + this.web3 && + this.web3.currentProvider && + (this.web3.currentProvider as any).isMetaMask + try { + return await this.web3.eth.personal.sign(text, publicKey, password) + } catch (e) { + if (isMetaMask) { + throw e + } + this.logger.warn('Error on personal sign.') + this.logger.warn(e) + try { + return await this.web3.eth.sign(text, publicKey) + } catch (e2) { + this.logger.error('Error on sign.') + this.logger.error(e2) + throw new Error('Error executing personal sign') + } + } + } + + public async signWithHash( + text: string, + publicKey: string, + password?: string ): Promise { const isMetaMask = this.web3 &&