mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Merge pull request #400 from oceanprotocol/bug/fix_compute_issues
fix Brizo auth for compute
This commit is contained in:
commit
0934c1879b
@ -24,9 +24,9 @@ before_script:
|
||||
- git clone https://github.com/oceanprotocol/barge
|
||||
- cd barge
|
||||
- export AQUARIUS_VERSION=unstable
|
||||
- export BRIZO_VERSION=v0.9.3
|
||||
- export BRIZO_VERSION=v0.9.5
|
||||
- export KEEPER_VERSION=v0.13.2
|
||||
- export EVENTS_HANDLER_VERSION=v0.4.5
|
||||
- export EVENTS_HANDLER_VERSION=v0.4.7
|
||||
- export KEEPER_OWNER_ROLE_ADDRESS="0xe2DD09d719Da89e5a3D0F2549c7E24566e947260"
|
||||
- rm -rf "${HOME}/.ocean/keeper-contracts/artifacts"
|
||||
- bash -x start_ocean.sh --no-commons --no-dashboard 2>&1 > start_ocean.log &
|
||||
|
@ -119,13 +119,20 @@ export class Brizo extends Instantiable {
|
||||
jobId?: string,
|
||||
output?: Output
|
||||
): Promise<ComputeJob | ComputeJob[]> {
|
||||
const signature = await this.createSignature(consumerAccount, serviceAgreementId)
|
||||
const address = consumerAccount.getId()
|
||||
const serviceEndpoint = await this.getEndpointFromAgreement(
|
||||
'compute',
|
||||
serviceAgreementId
|
||||
|
||||
let signatureMessage = address
|
||||
signatureMessage += jobId || ''
|
||||
signatureMessage += (serviceAgreementId && `${noZeroX(serviceAgreementId)}`) || ''
|
||||
const signature = await this.createHashSignature(
|
||||
consumerAccount,
|
||||
signatureMessage
|
||||
)
|
||||
|
||||
const serviceEndpoint = serviceAgreementId
|
||||
? await this.getEndpointFromAgreement('compute', serviceAgreementId)
|
||||
: this.getComputeEndpoint()
|
||||
|
||||
if (!serviceEndpoint) {
|
||||
throw new Error(
|
||||
'Computing on asset failed, service definition is missing the `serviceEndpoint`.'
|
||||
@ -197,6 +204,14 @@ export class Brizo extends Instantiable {
|
||||
return signature
|
||||
}
|
||||
|
||||
public async createHashSignature(account: Account, message: string): Promise<string> {
|
||||
const signature =
|
||||
(await account.getToken()) ||
|
||||
(await this.ocean.utils.signature.signWithHash(message, account.getId()))
|
||||
|
||||
return signature
|
||||
}
|
||||
|
||||
public async encrypt(
|
||||
did: string,
|
||||
signature: string,
|
||||
|
@ -38,6 +38,34 @@ export class SignatureUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public async signWithHash(
|
||||
text: string,
|
||||
publicKey: string,
|
||||
password?: string
|
||||
): Promise<string> {
|
||||
const hash = this.web3.utils.utf8ToHex(text)
|
||||
const isMetaMask =
|
||||
this.web3 &&
|
||||
this.web3.currentProvider &&
|
||||
(this.web3.currentProvider as any).isMetaMask
|
||||
try {
|
||||
return await this.web3.eth.personal.sign(hash, 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(hash, publicKey)
|
||||
} catch (e2) {
|
||||
this.logger.error('Error on sign.')
|
||||
this.logger.error(e2)
|
||||
throw new Error('Error executing personal sign')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async verifyText(text: string, signature: string): Promise<string> {
|
||||
return this.web3.eth.personal.ecRecover(text, signature)
|
||||
}
|
||||
|
@ -33,16 +33,17 @@ describe('Compute', () => {
|
||||
let dataset: DDO
|
||||
let algorithm: DDO
|
||||
let computeService: ServiceCompute
|
||||
let jobId: string
|
||||
|
||||
before(async () => {
|
||||
ocean = await Ocean.getInstance(customConfig)
|
||||
;[account] = await ocean.accounts.list()
|
||||
})
|
||||
|
||||
it('should authenticate the consumer account', async () => {
|
||||
/* it('should authenticate the consumer account', async () => {
|
||||
await account.authenticate()
|
||||
})
|
||||
|
||||
*/
|
||||
it('should publish a dataset with a compute service object', async () => {
|
||||
const stepsAsset = []
|
||||
computeService = await ocean.compute.createComputeServiceAttributes(
|
||||
@ -116,6 +117,19 @@ describe('Compute', () => {
|
||||
algoMeta
|
||||
)
|
||||
|
||||
assert.equal(response.status, ComputeJobStatus.Started)
|
||||
assert.isAtLeast(response.status, ComputeJobStatus.Started)
|
||||
jobId = response.jobId
|
||||
})
|
||||
|
||||
it('should get status of a compute job', async () => {
|
||||
const response = await ocean.compute.status(account, agreementId, jobId)
|
||||
|
||||
assert.equal(response[0].jobId, jobId)
|
||||
})
|
||||
|
||||
it('should get status of all compute jobs for an address', async () => {
|
||||
const response = await ocean.compute.status(account, undefined, undefined)
|
||||
|
||||
assert.isAbove(response.length, 0)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user