1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

update provider signature message

This commit is contained in:
Bogdan Fazakas 2023-04-27 13:08:01 +03:00
parent 4f5a8cee3e
commit 05c4030afd
2 changed files with 13 additions and 8 deletions

View File

@ -114,19 +114,22 @@ export class Provider {
* @returns {Promise<string>} A promise that resolves with the signature.
*/
public async signProviderRequest(signer: Signer, message: string): Promise<string> {
// const isMetaMask = web3 && web3.currentProvider && (web3.currentProvider as any).isMetaMask
// if (isMetaMask) return await web3.eth.personal.sign(consumerMessage, accountId, password)
// await web3.eth.sign(consumerMessage, await signer.getAddress())
const consumerMessage = ethers.utils.solidityKeccak256(
['bytes'],
[ethers.utils.hexlify(ethers.utils.toUtf8Bytes(message))]
)
// const isMetaMask = web3 && web3.currentProvider && (web3.currentProvider as any).isMetaMask
// if (isMetaMask) return await web3.eth.personal.sign(consumerMessage, accountId, password)
// await web3.eth.sign(consumerMessage, await signer.getAddress())
const messageHashBytes = ethers.utils.arrayify(consumerMessage)
const newSignature = await (signer as providers.JsonRpcSigner)._legacySignMessage(
messageHashBytes
)
return newSignature
const chainId = await signer.getChainId()
if (chainId == 8996) {
return await (signer as providers.JsonRpcSigner)._legacySignMessage(
messageHashBytes
)
}
return await signer.signMessage(messageHashBytes)
}
/**

View File

@ -50,6 +50,7 @@ export async function getTokenDecimals(signer: Signer, token: string) {
/**
* Converts an amount of units to tokens
* @param {Signer} signer - The signer object to use.
* @param {string} token - The token to convert
* @param {string} amount - The amount of units to convert
* @param {number} [tokenDecimals] - The number of decimals in the token
@ -72,6 +73,7 @@ export async function unitsToAmount(
/**
* Converts an amount of tokens to units
* @param {Signer} signer - The signer object to use.
* @param {string} token - The token to convert
* @param {string} amount - The amount of tokens to convert
* @param {number} [tokenDecimals] - The number of decimals of the token