Skip to content

Commit b9b5d77

Browse files
committed
use latest ddo-js
1 parent aaeb4d4 commit b9b5d77

7 files changed

Lines changed: 49 additions & 65 deletions

File tree

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@
7272
"@libp2p/upnp-nat": "^1.2.1",
7373
"@libp2p/websockets": "^8.1.1",
7474
"@multiformats/multiaddr": "^10.2.0",
75-
"@oceanprotocol/ddo-js": "^0.0.6",
7675
"@oceanprotocol/contracts": "^2.3.0-next.3",
76+
"@oceanprotocol/ddo-js": "^0.0.7",
7777
"@types/lodash.clonedeep": "^4.5.7",
7878
"axios": "^1.8.4",
7979
"base58-js": "^2.0.0",

src/@types/DDO/Credentials.ts

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/test/data/assets.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Credentials } from '@oceanprotocol/ddo-js'
1+
import { Credentials, CREDENTIALS_TYPES } from '@oceanprotocol/ddo-js'
22

33
export const downloadAsset = {
44
'@context': ['https://w3id.org/did/v1'],
@@ -62,11 +62,11 @@ export const downloadAsset = {
6262
const nftLevelCredentials: Credentials = {
6363
allow: [
6464
{
65-
type: 'address',
65+
type: CREDENTIALS_TYPES.ADDRESS,
6666
values: ['0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e']
6767
},
6868
{
69-
type: 'address',
69+
type: CREDENTIALS_TYPES.ADDRESS,
7070
values: [
7171
'0xA78deb2Fa79463945C247991075E2a0e98Ba7A09',
7272
'0xe2DD09d719Da89e5a3D0F2549c7E24566e947260'
@@ -75,7 +75,7 @@ const nftLevelCredentials: Credentials = {
7575
],
7676
deny: [
7777
{
78-
type: 'address',
78+
type: CREDENTIALS_TYPES.ADDRESS,
7979
values: ['0x02354A1F160A3fd7ac8b02ee91F04104440B28E7']
8080
}
8181
]
@@ -84,13 +84,13 @@ const nftLevelCredentials: Credentials = {
8484
const serviceLevelCredentials: Credentials = {
8585
deny: [
8686
{
87-
type: 'address',
87+
type: CREDENTIALS_TYPES.ADDRESS,
8888
values: ['0xA78deb2Fa79463945C247991075E2a0e98Ba7A09']
8989
}
9090
],
9191
allow: [
9292
{
93-
type: 'address',
93+
type: CREDENTIALS_TYPES.ADDRESS,
9494
values: [
9595
'0xe2DD09d719Da89e5a3D0F2549c7E24566e947260',
9696
'0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e'

src/test/data/ddo.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { CREDENTIALS_TYPES } from '@oceanprotocol/ddo-js'
2+
13
export const ddo = {
24
hashType: 'sha256',
35
'@context': ['https://w3id.org/did/v1'],
@@ -71,13 +73,13 @@ export const genericAlgorithm = {
7173
credentials: {
7274
allow: [
7375
{
74-
type: 'address',
76+
type: CREDENTIALS_TYPES.ADDRESS,
7577
values: ['0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e']
7678
}
7779
],
7880
deny: [
7981
{
80-
type: 'address',
82+
type: CREDENTIALS_TYPES.ADDRESS,
8183
values: ['0x123']
8284
}
8385
]
@@ -124,13 +126,13 @@ export const genericDDO = {
124126
credentials: {
125127
allow: [
126128
{
127-
type: 'address',
129+
type: CREDENTIALS_TYPES.ADDRESS,
128130
values: ['0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e']
129131
}
130132
],
131133
deny: [
132134
{
133-
type: 'address',
135+
type: CREDENTIALS_TYPES.ADDRESS,
134136
values: ['0x123']
135137
}
136138
]
@@ -189,13 +191,13 @@ export const genericComputeDDO = {
189191
credentials: {
190192
allow: [
191193
{
192-
type: 'address',
194+
type: CREDENTIALS_TYPES.ADDRESS,
193195
values: ['0xBE5449a6A97aD46c8558A3356267Ee5D2731ab5e']
194196
}
195197
],
196198
deny: [
197199
{
198-
type: 'address',
200+
type: CREDENTIALS_TYPES.ADDRESS,
199201
values: ['0x123']
200202
}
201203
]
@@ -348,13 +350,13 @@ export const ddov7 = {
348350
credentials: {
349351
allow: [
350352
{
351-
type: 'address',
353+
type: CREDENTIALS_TYPES.ADDRESS,
352354
values: ['0x1234']
353355
}
354356
],
355357
deny: [
356358
{
357-
type: 'address',
359+
type: CREDENTIALS_TYPES.ADDRESS,
358360
values: ['0xabcd']
359361
}
360362
]

src/test/unit/credentials.test.ts

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
import { ENVIRONMENT_VARIABLES } from '../../utils/constants.js'
1414
import { homedir } from 'os'
1515
import { DEVELOPMENT_CHAIN_ID } from '../../utils/address.js'
16-
import { Credentials } from '@oceanprotocol/ddo-js'
16+
import { Credentials, CREDENTIALS_TYPES } from '@oceanprotocol/ddo-js'
1717

1818
let envOverrides: OverrideEnvConfig[]
1919

@@ -53,7 +53,7 @@ describe('credentials', () => {
5353
allow: [],
5454
deny: [
5555
{
56-
type: 'address',
56+
type: CREDENTIALS_TYPES.ADDRESS,
5757
values: []
5858
}
5959
]
@@ -69,6 +69,7 @@ describe('credentials', () => {
6969
allow: [],
7070
deny: [
7171
{
72+
// @ts-expect-error
7273
type: 'accessList',
7374
values: [consumerAddress] // not a valid SC address anyway
7475
}
@@ -84,7 +85,7 @@ describe('credentials', () => {
8485
deny: [],
8586
allow: [
8687
{
87-
type: 'address',
88+
type: CREDENTIALS_TYPES.ADDRESS,
8889
values: []
8990
}
9091
]
@@ -98,7 +99,7 @@ describe('credentials', () => {
9899
deny: [],
99100
allow: [
100101
{
101-
type: 'address',
102+
type: CREDENTIALS_TYPES.ADDRESS,
102103
values: ['0x123']
103104
}
104105
]
@@ -112,7 +113,7 @@ describe('credentials', () => {
112113
allow: [],
113114
deny: [
114115
{
115-
type: 'address',
116+
type: CREDENTIALS_TYPES.ADDRESS,
116117
values: ['0x456']
117118
}
118119
]
@@ -125,13 +126,13 @@ describe('credentials', () => {
125126
const credentials: Credentials = {
126127
allow: [
127128
{
128-
type: 'address',
129+
type: CREDENTIALS_TYPES.ADDRESS,
129130
values: []
130131
}
131132
],
132133
deny: [
133134
{
134-
type: 'address',
135+
type: CREDENTIALS_TYPES.ADDRESS,
135136
values: ['0x123']
136137
}
137138
]
@@ -144,13 +145,13 @@ describe('credentials', () => {
144145
const credentials: Credentials = {
145146
allow: [
146147
{
147-
type: 'address',
148+
type: CREDENTIALS_TYPES.ADDRESS,
148149
values: ['0x456']
149150
}
150151
],
151152
deny: [
152153
{
153-
type: 'address',
154+
type: CREDENTIALS_TYPES.ADDRESS,
154155
values: []
155156
}
156157
]
@@ -165,6 +166,7 @@ describe('credentials', () => {
165166
allow: [],
166167
deny: [
167168
{
169+
// @ts-expect-error
168170
type: 'unknow_type',
169171
values: ['0x456']
170172
}
@@ -176,17 +178,17 @@ describe('credentials', () => {
176178
const credentialsOk: Credentials = {
177179
deny: [
178180
{
179-
type: 'address',
181+
type: CREDENTIALS_TYPES.ADDRESS,
180182
values: ['0x456']
181183
}
182184
],
183185
allow: [
184186
{
185-
type: 'accessList',
187+
type: CREDENTIALS_TYPES.ACCESS_LIST,
186188
values: ['0x456']
187189
},
188190
{
189-
type: 'address',
191+
type: CREDENTIALS_TYPES.ADDRESS,
190192
values: ['0x678']
191193
}
192194
]
@@ -197,12 +199,13 @@ describe('credentials', () => {
197199
const credentialsNOk: Credentials = {
198200
deny: [
199201
{
200-
type: 'address',
202+
type: CREDENTIALS_TYPES.ADDRESS,
201203
values: ['0x456']
202204
}
203205
],
204206
allow: [
205207
{
208+
// @ts-expect-error
206209
type: 'not_valid_type',
207210
values: ['0x456']
208211
}
@@ -217,13 +220,13 @@ describe('credentials', () => {
217220
credentials: {
218221
allow: [
219222
{
220-
type: 'address',
223+
type: CREDENTIALS_TYPES.ADDRESS,
221224
values: ['*']
222225
}
223226
],
224227
deny: [
225228
{
226-
type: 'address',
229+
type: CREDENTIALS_TYPES.ADDRESS,
227230
values: ['0x2222', '0x333']
228231
}
229232
]
@@ -239,13 +242,13 @@ describe('credentials', () => {
239242
const credentials: Credentials = {
240243
allow: [
241244
{
242-
type: 'address',
245+
type: CREDENTIALS_TYPES.ADDRESS,
243246
values: []
244247
}
245248
],
246249
deny: [
247250
{
248-
type: 'address',
251+
type: CREDENTIALS_TYPES.ADDRESS,
249252
values: []
250253
}
251254
]

src/utils/credentials.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { AccessListContract } from '../@types/OceanNode.js'
44
import { CORE_LOGGER } from './logging/common.js'
55
import {
66
Credential,
7-
CREDENTIAL_TYPES,
87
Credentials,
8+
CREDENTIALS_TYPES,
99
KNOWN_CREDENTIALS_TYPES
10-
} from '../@types/DDO/Credentials.js'
10+
} from '@oceanprotocol/ddo-js'
1111
import { getNFTContract } from '../components/Indexer/utils.js'
1212
import { isDefined } from './util.js'
1313
import { getConfiguration } from './config.js'
@@ -38,7 +38,7 @@ export function isAddressCredentialMatch(
3838
credential: Credential,
3939
consumerCredentials: Credential
4040
): boolean {
41-
if (credential?.type?.toLowerCase() !== CREDENTIAL_TYPES.ADDRESS) {
41+
if (credential?.type?.toLowerCase() !== CREDENTIALS_TYPES.ADDRESS) {
4242
return false
4343
}
4444
if (credential.values.length > 0) {
@@ -50,7 +50,7 @@ export function isAddressCredentialMatch(
5050
}
5151

5252
function isAddressMatchAll(credential: Credential): boolean {
53-
if (credential?.type?.toLowerCase() !== CREDENTIAL_TYPES.ADDRESS) {
53+
if (credential?.type?.toLowerCase() !== CREDENTIALS_TYPES.ADDRESS) {
5454
return false
5555
}
5656
if (credential.values.length > 0) {
@@ -83,7 +83,7 @@ export async function checkCredentials(
8383
chainId?: number
8484
): Promise<boolean> {
8585
const consumerCredentials: Credential = {
86-
type: CREDENTIAL_TYPES.ADDRESS, // 'address',
86+
type: CREDENTIALS_TYPES.ADDRESS,
8787
values: [String(consumerAddress)?.toLowerCase()]
8888
}
8989

@@ -100,7 +100,7 @@ export async function checkCredentials(
100100
let denyCount = 0
101101
for (const cred of credentials.deny) {
102102
const { type } = cred
103-
if (type === CREDENTIAL_TYPES.ADDRESS) {
103+
if (type === CREDENTIALS_TYPES.ADDRESS) {
104104
const accessDeny = isAddressCredentialMatch(cred, consumerCredentials)
105105
// credential is on deny list, so it should be blocked access
106106
if (accessDeny) {
@@ -122,7 +122,7 @@ export async function checkCredentials(
122122
let matchCount = 0
123123
for (const cred of credentials.allow) {
124124
const { type } = cred
125-
if (type === CREDENTIAL_TYPES.ADDRESS) {
125+
if (type === CREDENTIALS_TYPES.ADDRESS) {
126126
const accessAllow = isAddressCredentialMatch(cred, consumerCredentials)
127127
if (accessAllow || isAddressMatchAll(cred)) {
128128
// if no match_allow or 'any', its fine
@@ -132,7 +132,7 @@ export async function checkCredentials(
132132
// otherwise, match 'all', in this case the amount of matches should be the same of the amount of rules
133133
matchCount++
134134
}
135-
} else if (type === CREDENTIAL_TYPES.ACCESS_LIST && chainId) {
135+
} else if (type === CREDENTIALS_TYPES.ACCESS_LIST && chainId) {
136136
const config = await getConfiguration()
137137
const supportedNetwork = config.supportedNetworks[String(chainId)]
138138
if (supportedNetwork) {

0 commit comments

Comments
 (0)