mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
Update provider nonce handling (#1747)
* Updates the usage of nonce * nonce method updates * fix lint * remove double resolve for the response * use provider invalid-signature image and comm update docs * print errro * set a default value if nonce received is null * fix issue with consumer address on download * remove parse int * skip compute tests * Updating CodeExamples.md * put back compute tests * prepare for release * use older contracts --------- Co-authored-by: GitHub Actions Bot <>
This commit is contained in:
parent
ff5fcd7f22
commit
808178291d
4
.github/workflows/ci.yml
vendored
4
.github/workflows/ci.yml
vendored
@ -61,7 +61,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --no-aquarius --no-elasticsearch --no-provider --no-dashboard 2>&1 > start_ocean.log &
|
||||||
env:
|
env:
|
||||||
CONTRACTS_VERSION: v1.1.4
|
CONTRACTS_VERSION: v1.1.8
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- name: Wait for contracts deployment
|
- name: Wait for contracts deployment
|
||||||
working-directory: ${{ github.workspace }}/barge
|
working-directory: ${{ github.workspace }}/barge
|
||||||
@ -119,7 +119,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
bash -x start_ocean.sh --with-provider2 --no-dashboard --with-c2d 2>&1 > start_ocean.log &
|
||||||
env:
|
env:
|
||||||
CONTRACTS_VERSION: v1.1.3
|
CONTRACTS_VERSION: v1.1.8
|
||||||
|
|
||||||
- run: npm ci
|
- run: npm ci
|
||||||
- run: npm run build:metadata
|
- run: npm run build:metadata
|
||||||
|
@ -108,7 +108,8 @@ import {
|
|||||||
amountToUnits,
|
amountToUnits,
|
||||||
ValidateMetadata,
|
ValidateMetadata,
|
||||||
getEventFromTx,
|
getEventFromTx,
|
||||||
DDO
|
DDO,
|
||||||
|
LoggerInstance
|
||||||
} from '@oceanprotocol/lib'
|
} from '@oceanprotocol/lib'
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -564,6 +565,7 @@ Lets check that the download URL was successfully received
|
|||||||
const fileData = await downloadFile(downloadURL)
|
const fileData = await downloadFile(downloadURL)
|
||||||
console.log(fileData)
|
console.log(fileData)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
LoggerInstance.error('Download failed', e)
|
||||||
assert.fail('Download failed')
|
assert.fail('Download failed')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,10 +100,13 @@ export class Provider {
|
|||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
signal
|
signal
|
||||||
})
|
})
|
||||||
return (await response.json()).nonce.toString()
|
const { nonce } = await response.json()
|
||||||
|
console.log(`[getNonce] Consumer: ${consumerAddress} nonce: ${nonce}`)
|
||||||
|
const sanitizedNonce = !nonce || nonce === null ? '0' : nonce
|
||||||
|
return sanitizedNonce
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
LoggerInstance.error(e)
|
LoggerInstance.error(e)
|
||||||
throw new Error('HTTP request failed calling Provider')
|
throw new Error(e.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,14 +490,24 @@ export class Provider {
|
|||||||
? this.getEndpointURL(serviceEndpoints, 'download').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'download').urlPath
|
||||||
: null
|
: null
|
||||||
if (!downloadUrl) return null
|
if (!downloadUrl) return null
|
||||||
const nonce = Date.now()
|
const consumerAddress = await signer.getAddress()
|
||||||
|
const nonce = (
|
||||||
|
(await this.getNonce(
|
||||||
|
providerUri,
|
||||||
|
consumerAddress,
|
||||||
|
null,
|
||||||
|
providerEndpoints,
|
||||||
|
serviceEndpoints
|
||||||
|
)) + 1
|
||||||
|
).toString()
|
||||||
|
|
||||||
const signature = await this.signProviderRequest(signer, did + nonce)
|
const signature = await this.signProviderRequest(signer, did + nonce)
|
||||||
let consumeUrl = downloadUrl
|
let consumeUrl = downloadUrl
|
||||||
consumeUrl += `?fileIndex=${fileIndex}`
|
consumeUrl += `?fileIndex=${fileIndex}`
|
||||||
consumeUrl += `&documentId=${did}`
|
consumeUrl += `&documentId=${did}`
|
||||||
consumeUrl += `&transferTxId=${transferTxId}`
|
consumeUrl += `&transferTxId=${transferTxId}`
|
||||||
consumeUrl += `&serviceId=${serviceId}`
|
consumeUrl += `&serviceId=${serviceId}`
|
||||||
consumeUrl += `&consumerAddress=${await signer.getAddress()}`
|
consumeUrl += `&consumerAddress=${consumerAddress}`
|
||||||
consumeUrl += `&nonce=${nonce}`
|
consumeUrl += `&nonce=${nonce}`
|
||||||
consumeUrl += `&signature=${signature}`
|
consumeUrl += `&signature=${signature}`
|
||||||
if (userCustomParameters)
|
if (userCustomParameters)
|
||||||
@ -532,13 +545,23 @@ export class Provider {
|
|||||||
? this.getEndpointURL(serviceEndpoints, 'computeStart').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'computeStart').urlPath
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const nonce = Date.now()
|
const consumerAddress = await consumer.getAddress()
|
||||||
let signatureMessage = await consumer.getAddress()
|
const nonce = (
|
||||||
|
(await this.getNonce(
|
||||||
|
providerUri,
|
||||||
|
consumerAddress,
|
||||||
|
signal,
|
||||||
|
providerEndpoints,
|
||||||
|
serviceEndpoints
|
||||||
|
)) + 1
|
||||||
|
).toString()
|
||||||
|
|
||||||
|
let signatureMessage = consumerAddress
|
||||||
signatureMessage += dataset.documentId
|
signatureMessage += dataset.documentId
|
||||||
signatureMessage += nonce
|
signatureMessage += nonce
|
||||||
const signature = await this.signProviderRequest(consumer, signatureMessage)
|
const signature = await this.signProviderRequest(consumer, signatureMessage)
|
||||||
const payload = Object()
|
const payload = Object()
|
||||||
payload.consumerAddress = await consumer.getAddress()
|
payload.consumerAddress = consumerAddress
|
||||||
payload.signature = signature
|
payload.signature = signature
|
||||||
payload.nonce = nonce
|
payload.nonce = nonce
|
||||||
payload.environment = computeEnv
|
payload.environment = computeEnv
|
||||||
@ -601,13 +624,15 @@ export class Provider {
|
|||||||
? this.getEndpointURL(serviceEndpoints, 'computeStop').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'computeStop').urlPath
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const nonce = await this.getNonce(
|
const nonce = (
|
||||||
providerUri,
|
(await this.getNonce(
|
||||||
consumerAddress,
|
providerUri,
|
||||||
signal,
|
consumerAddress,
|
||||||
providerEndpoints,
|
signal,
|
||||||
serviceEndpoints
|
providerEndpoints,
|
||||||
)
|
serviceEndpoints
|
||||||
|
)) + 1
|
||||||
|
).toString()
|
||||||
|
|
||||||
let signatureMessage = consumerAddress
|
let signatureMessage = consumerAddress
|
||||||
signatureMessage += jobId || ''
|
signatureMessage += jobId || ''
|
||||||
@ -737,7 +762,15 @@ export class Provider {
|
|||||||
? this.getEndpointURL(serviceEndpoints, 'computeResult').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'computeResult').urlPath
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const nonce = Date.now()
|
const nonce = (
|
||||||
|
(await this.getNonce(
|
||||||
|
providerUri,
|
||||||
|
await consumer.getAddress(),
|
||||||
|
null,
|
||||||
|
providerEndpoints,
|
||||||
|
serviceEndpoints
|
||||||
|
)) + 1
|
||||||
|
).toString()
|
||||||
let signatureMessage = await consumer.getAddress()
|
let signatureMessage = await consumer.getAddress()
|
||||||
signatureMessage += jobId
|
signatureMessage += jobId
|
||||||
signatureMessage += index.toString()
|
signatureMessage += index.toString()
|
||||||
@ -777,13 +810,15 @@ export class Provider {
|
|||||||
? this.getEndpointURL(serviceEndpoints, 'computeDelete').urlPath
|
? this.getEndpointURL(serviceEndpoints, 'computeDelete').urlPath
|
||||||
: null
|
: null
|
||||||
|
|
||||||
const nonce = await this.getNonce(
|
const nonce = (
|
||||||
providerUri,
|
(await this.getNonce(
|
||||||
await consumer.getAddress(),
|
providerUri,
|
||||||
signal,
|
await consumer.getAddress(),
|
||||||
providerEndpoints,
|
signal,
|
||||||
serviceEndpoints
|
providerEndpoints,
|
||||||
)
|
serviceEndpoints
|
||||||
|
)) + 1
|
||||||
|
).toString()
|
||||||
|
|
||||||
let signatureMessage = await consumer.getAddress()
|
let signatureMessage = await consumer.getAddress()
|
||||||
signatureMessage += jobId || ''
|
signatureMessage += jobId || ''
|
||||||
|
@ -108,7 +108,8 @@ import {
|
|||||||
amountToUnits,
|
amountToUnits,
|
||||||
ValidateMetadata,
|
ValidateMetadata,
|
||||||
getEventFromTx,
|
getEventFromTx,
|
||||||
DDO
|
DDO,
|
||||||
|
LoggerInstance
|
||||||
} from '../../src'
|
} from '../../src'
|
||||||
/// ```
|
/// ```
|
||||||
|
|
||||||
@ -564,6 +565,7 @@ describe('Marketplace flow tests', async () => {
|
|||||||
const fileData = await downloadFile(downloadURL)
|
const fileData = await downloadFile(downloadURL)
|
||||||
console.log(fileData)
|
console.log(fileData)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
LoggerInstance.error('Download failed', e)
|
||||||
assert.fail('Download failed')
|
assert.fail('Download failed')
|
||||||
}
|
}
|
||||||
}) ///
|
}) ///
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { assert } from 'chai'
|
import { assert } from 'chai'
|
||||||
import { getTestConfig, provider } from '../config'
|
import { getTestConfig, provider } from '../config'
|
||||||
import { Config, Provider } from '../../src'
|
import { Config, Provider } from '../../src'
|
||||||
import { ethers, Signer } from 'ethers'
|
import { Signer } from 'ethers'
|
||||||
import { FileInfo } from '../../src/@types'
|
import { FileInfo } from '../../src/@types'
|
||||||
|
|
||||||
describe('Provider tests', async () => {
|
describe('Provider tests', async () => {
|
||||||
@ -55,4 +55,12 @@ describe('Provider tests', async () => {
|
|||||||
const computeEnvs = await providerInstance.getComputeEnvironments(config.providerUri)
|
const computeEnvs = await providerInstance.getComputeEnvironments(config.providerUri)
|
||||||
assert(computeEnvs, 'No Compute environments found')
|
assert(computeEnvs, 'No Compute environments found')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Alice tests getNonce', async () => {
|
||||||
|
const nonce = await providerInstance.getNonce(
|
||||||
|
config.providerUri,
|
||||||
|
'0xe2DD09d719Da89e5a3D0F2549c7E24566e947260'
|
||||||
|
)
|
||||||
|
assert(nonce, 'could not get nonce for the sent address')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user