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

add new signature support

This commit is contained in:
alexcos20 2020-04-08 11:05:32 +03:00
parent 7de1b110b0
commit 0b7eb1c067
2 changed files with 10 additions and 7 deletions

View File

@ -119,8 +119,13 @@ export class Brizo extends Instantiable {
jobId?: string, jobId?: string,
output?: Output output?: Output
): Promise<ComputeJob | ComputeJob[]> { ): Promise<ComputeJob | ComputeJob[]> {
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
const address = consumerAccount.getId() const address = consumerAccount.getId()
let signatureMessage = address
signatureMessage += (jobId && `${jobId}`) || ''
signatureMessage += (serviceAgreementId && `${noZeroX(serviceAgreementId)}`) || ''
const signature = await this.createSignature(consumerAccount, signatureMessage)
let serviceEndpoint let serviceEndpoint
if (serviceAgreementId) if (serviceAgreementId)
serviceEndpoint = await this.getEndpointFromAgreement( serviceEndpoint = await this.getEndpointFromAgreement(
@ -189,13 +194,10 @@ export class Brizo extends Instantiable {
return result return result
} }
public async createSignature(account: Account, agreementId: 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( (await this.ocean.utils.signature.signText(message, account.getId()))
noZeroX(agreementId),
account.getId()
))
return signature return signature
} }

View File

@ -21,7 +21,8 @@ export class SignatureUtils {
this.web3.currentProvider && this.web3.currentProvider &&
(this.web3.currentProvider as any).isMetaMask (this.web3.currentProvider as any).isMetaMask
try { try {
return await this.web3.eth.personal.sign(text, publicKey, password) const hash = await this.getHash(text)
return await this.web3.eth.personal.sign(hash, publicKey, password)
} catch (e) { } catch (e) {
if (isMetaMask) { if (isMetaMask) {
throw e throw e