1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

fix signing

This commit is contained in:
alexcos20 2020-04-08 12:46:28 +03:00
parent c22208a8c1
commit 795f8494f9
2 changed files with 28 additions and 1 deletions

View File

@ -197,7 +197,7 @@ export class Brizo extends Instantiable {
public async createSignature(account: Account, message: string): Promise<string> { public async createSignature(account: Account, message: string): Promise<string> {
const signature = const signature =
(await account.getToken()) || (await account.getToken()) ||
(await this.ocean.utils.signature.signText(message, account.getId())) (await this.ocean.utils.signature.signWithHash(message, account.getId()))
return signature return signature
} }

View File

@ -15,6 +15,33 @@ export class SignatureUtils {
text: string, text: string,
publicKey: string, publicKey: string,
password?: string password?: string
): Promise<string> {
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<string> { ): Promise<string> {
const isMetaMask = const isMetaMask =
this.web3 && this.web3 &&