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

chore: wip

This commit is contained in:
AdriGeorge 2024-10-24 14:24:57 +03:00
parent 2c25699b25
commit 2a3b8c4bd3
5 changed files with 35 additions and 72 deletions

View File

@ -1,33 +0,0 @@
import { Asset, Metadata, Service } from '../../@types'
import { BaseDDOType } from '../../@types/DDO/versions/BaseDDO'
export class DDO_V4 implements BaseDDOType {
'@context': string[]
id: string
version: string
nftAddress: string
chainId: number
metadata: Metadata
services: Service[]
constructor(data: any) {
this['@context'] = data['@context']
this.id = data.id
this.version = data.version
this.nftAddress = data.nftAddress
this.chainId = data.chainId
this.metadata = data.metadata
this.services = data.services
}
/**
* Get param to order an asset based on the specified pricing schema and configuration.
* @param {Asset} asset - The asset to be ordered.
* @param {number} [serviceIndex=0] - Index of the service within the asset.
*/
getOrderAssetParams(asset: Asset, serviceIndex: number = 0) {
const did = asset.id
const serviceId = asset.services[serviceIndex].id
return { did, serviceId }
}
}

View File

@ -1,5 +1,31 @@
import { DDO_V4 } from './DDO_V4'
import { VerifiableCredential } from './VerifiableCredential'
import { Asset } from '../../@types'
import { VerifiableCredentialType } from '../../@types/DDO/versions/VerifiableCredential'
export class DDO_V4 {
/**
* Get param to order an asset based on the specified pricing schema and configuration.
* @param {Asset} asset - The asset to be ordered.
* @param {number} [serviceIndex=0] - Index of the service within the asset.
*/
getOrderAssetParams(asset: Asset, serviceIndex: number = 0) {
const did = asset.id
const serviceId = asset.services[serviceIndex].id
return { did, serviceId }
}
}
export class VerifiableCredential {
/**
* Get param to order an asset based on the specified pricing schema and configuration.
* @param {Asset} asset - The asset to be ordered.
* @param {number} [serviceIndex=0] - Index of the service within the asset.
*/
getOrderAssetParams(asset: VerifiableCredentialType, serviceIndex: number = 0) {
const did = asset.credentialSubject.id
const serviceId = asset.credentialSubject.services[serviceIndex].id
return { did, serviceId }
}
}
type AssetType = DDO_V4 | VerifiableCredential
@ -11,10 +37,10 @@ export class DDOFactory {
case '4.3.0':
case '4.5.0':
case '4.7.0':
return new DDO_V4(data)
return new DDO_V4()
case '5.0.0':
return new VerifiableCredential(data)
return new VerifiableCredential()
default:
throw new Error(`Unsupported DDO version: ${version}`)

View File

@ -1,30 +0,0 @@
import { CredentialSubject } from '../../@types/DDO/CredentialSubject'
import { BaseDDOType } from '../../@types/DDO/versions/BaseDDO'
import { VerifiableCredentialType } from '../../@types/DDO/versions/VerifiableCredential'
export class VerifiableCredential implements BaseDDOType {
'@context': string[]
id?: string
version: string
credentialSubject: CredentialSubject
issuer: string
constructor(data: any) {
this['@context'] = data['@context']
this.id = data.id
this.version = data.version
this.credentialSubject = data.credentialSubject
this.issuer = data.issuer
}
/**
* Get param to order an asset based on the specified pricing schema and configuration.
* @param {Asset} asset - The asset to be ordered.
* @param {number} [serviceIndex=0] - Index of the service within the asset.
*/
getOrderAssetParams(asset: VerifiableCredentialType, serviceIndex: number = 0) {
const did = asset.credentialSubject.id
const serviceId = asset.credentialSubject.services[serviceIndex].id
return { did, serviceId }
}
}

View File

@ -1,5 +0,0 @@
import { DDOFactory } from './DDO/DdoFactory'
export async function getDDOType(assetData: any) {
return DDOFactory.createDDO(assetData)
}

View File

@ -1,5 +1,6 @@
import sha256 from 'crypto-js/sha256'
import { ethers } from 'ethers'
import { DDOFactory } from './DDO/DdoFactory'
/**
* Generates a valid DID
@ -21,3 +22,7 @@ export function generateDid(nftAddress: string, chainId: number): string {
export function getHash(data: any): string {
return sha256(data).toString()
}
export async function getDDOType(assetData: any) {
return DDOFactory.createDDO(assetData)
}