Skip to content

Commit

Permalink
fix: adapting to sdk v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
aaitor committed Aug 2, 2023
1 parent 8aff78c commit 257e2f9
Show file tree
Hide file tree
Showing 28 changed files with 264 additions and 222 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk-dtp",
"version": "0.6.1",
"version": "0.7.0",
"description": "Javascript SDK for connecting with Nevermined Data Platform (Data Transfer proofs module)",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -38,11 +38,11 @@
"web3-utils": "^1.7.4"
},
"peerDependencies": {
"@nevermined-io/sdk": "^1.6.0"
"@nevermined-io/sdk": "^2.0.0-rc4"
},
"devDependencies": {
"@faker-js/faker": "^6.3.1",
"@nevermined-io/sdk": "^1.6.0",
"@nevermined-io/sdk": "^v2.0.0-rc5",
"@release-it/bumper": "^1.4.1",
"@truffle/hdwallet-provider": "^1.0.42",
"@types/chai": "^4.2.12",
Expand Down
13 changes: 8 additions & 5 deletions src/AccessDLEQCondition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
zeroX,
TxParameters,
InstantiableConfig,
BigNumber,
ConditionInstanceSmall,
} from '@nevermined-io/sdk'
import { makeKeyTransfer } from './KeyTransfer'
Expand Down Expand Up @@ -96,15 +95,18 @@ export class AccessDLEQCondition extends ProviderCondition<
)
}

public setNetworkPublicKey(key: BabyjubPublicKey, from?: Account, txParams?: TxParameters) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async setNetworkPublicKey(key: BabyjubPublicKey, from?: Account, txParams?: TxParameters): Promise<any> {
return super.send("setNetworkPublicKey", from && from.getId(), [[key.x, key.y]], txParams)
}

public addSecret(key: BabyjubPublicKey, from?: Account, txParams?: TxParameters) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async addSecret(key: BabyjubPublicKey, from?: Account, txParams?: TxParameters): Promise<any> {
return super.send("addSecret", from && from.getId(), [[key.x, key.y]], txParams)
}

public addPrice(pid: string, price: BigNumber, token: string, ttype: number, from?: Account, txParams?: TxParameters) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public async addPrice(pid: string, price: bigint, token: string, ttype: number, from?: Account, txParams?: TxParameters): Promise<any> {
return super.send("addPrice", from && from.getId(), [pid, price, token, ttype], txParams)
}

Expand All @@ -118,7 +120,8 @@ export class AccessDLEQCondition extends ProviderCondition<
return new BabyjubPublicKey((res0 as any)._hex, (res1 as any)._hex)
}

public authorize(agreementId: string, instances: ConditionInstanceSmall[], priceIdx: number, from?: Account, txParams?: TxParameters) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public authorize(agreementId: string, instances: ConditionInstanceSmall[], priceIdx: number, from?: Account, txParams?: TxParameters): Promise<any> {
const coder = new ethers.utils.AbiCoder()

const l2 = instances[2].list
Expand Down
19 changes: 11 additions & 8 deletions src/AccessDLEQTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import {
MetaData,
ServiceType,
ValidationParams,
AssetPrice,
LockPaymentCondition,
EscrowPaymentCondition,
AgreementInstance,
InstantiableConfig,
NFTAttributes,
PricedMetadataInformation,
ServiceAttributes,
} from '@nevermined-io/sdk'
import { AccessDLEQCondition } from './AccessDLEQCondition'
import { accessDLEQTemplateServiceAgreementTemplate } from './AccessProofTemplate.serviceAgreementTemplate'
Expand Down Expand Up @@ -39,17 +41,18 @@ export class AccessDLEQTemplate extends DLEQTemplate<AccessDLEQTemplateParams, S
return res
}

public async createService(
public createService(
publisher: Account,
metadata: MetaData,
assetPrice?: AssetPrice,
erc20TokenAddress?: string,
): Promise<ServiceAccessProof> {
return await super.createService(publisher, metadata, assetPrice, erc20TokenAddress, true)
serviceAttributes: ServiceAttributes,
nftAttributes?: NFTAttributes,
pricedData?: PricedMetadataInformation,
): ServiceAccessProof {
return super.createService(publisher, metadata, serviceAttributes, nftAttributes, pricedData)
}

public async getServiceAgreementTemplate() {
return accessDLEQTemplateServiceAgreementTemplate
public getServiceAgreementTemplate() {
return accessDLEQTemplateServiceAgreementTemplate()
}

public name(): string {
Expand Down
8 changes: 4 additions & 4 deletions src/AccessProofTemplate.serviceAgreementTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ServiceAgreementTemplate } from '@nevermined-io/sdk'
import { access, accessDLEQ, escrowPayment, lockPayment } from './ConditionTemplate'

export const accessTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const accessTemplateServiceAgreementTemplate = (): ServiceAgreementTemplate => ({
contractName: 'AccessProofTemplate',
events: [
{
Expand All @@ -21,9 +21,9 @@ export const accessTemplateServiceAgreementTemplate: ServiceAgreementTemplate =
escrowPayment: ['lockPayment', 'access'],
},
conditions: [lockPayment, access, escrowPayment],
}
})

export const accessDLEQTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const accessDLEQTemplateServiceAgreementTemplate = (): ServiceAgreementTemplate => ({
contractName: 'AccessDLEQTemplate',
events: [
{
Expand All @@ -43,4 +43,4 @@ export const accessDLEQTemplateServiceAgreementTemplate: ServiceAgreementTemplat
escrowPayment: ['lockPayment', 'access'],
},
conditions: [lockPayment, accessDLEQ, escrowPayment],
}
})
19 changes: 11 additions & 8 deletions src/AccessProofTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
MetaData,
ServiceType,
ValidationParams,
AssetPrice,
LockPaymentCondition,
EscrowPaymentCondition,
AgreementInstance,
InstantiableConfig,
AccessProofTemplateParams,
NFTAttributes,
PricedMetadataInformation,
ServiceAttributes,
} from '@nevermined-io/sdk'
import { AccessProofCondition } from './AccessProofCondition'
import { accessTemplateServiceAgreementTemplate } from './AccessProofTemplate.serviceAgreementTemplate'
Expand Down Expand Up @@ -40,17 +42,18 @@ export class AccessProofTemplate extends ProofTemplate<
return res
}

public async createService(
public createService(
publisher: Account,
metadata: MetaData,
assetPrice?: AssetPrice,
erc20TokenAddress?: string,
): Promise<ServiceAccessProof> {
return await super.createService(publisher, metadata, assetPrice, erc20TokenAddress, true)
serviceAttributes: ServiceAttributes,
nftAttributes?: NFTAttributes,
pricedData?: PricedMetadataInformation,
): ServiceAccessProof {
return super.createService(publisher, metadata, serviceAttributes, nftAttributes, pricedData)
}

public async getServiceAgreementTemplate() {
return accessTemplateServiceAgreementTemplate
public getServiceAgreementTemplate() {
return accessTemplateServiceAgreementTemplate()
}

public name(): string {
Expand Down
5 changes: 2 additions & 3 deletions src/Dtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
NeverminedNodeError,
KeeperError,
Babysig,
BigNumber,
didZeroX,
ConditionInstance,
zeroX,
Expand Down Expand Up @@ -194,7 +193,7 @@ export class Dtp extends Instantiable {
did: string,
agreementId: string,
account: Account,
nftAmount: BigNumber,
nftAmount: bigint,
nftHolder: string,
): Promise<boolean> {
const ddo = await this.nevermined.assets.resolve(didZeroX(did))
Expand Down Expand Up @@ -409,7 +408,7 @@ export class Dtp extends Instantiable {

public async order(
did: string,
nftAmount: BigNumber,
nftAmount: bigint,
consumer: Account,
publisher: string,
txParams?: TxParameters,
Expand Down
4 changes: 2 additions & 2 deletions src/NFT721AccessDLEQTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class NFT721AccessDLEQTemplate extends DLEQTemplate<
}
}

public async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate> {
return nft721AccessTemplateServiceAgreementTemplateDLEQ
public getServiceAgreementTemplate(): ServiceAgreementTemplate {
return nft721AccessTemplateServiceAgreementTemplateDLEQ()
}
}
8 changes: 4 additions & 4 deletions src/NFT721AccessProofTemplate.serviceAgreementTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ServiceAgreementTemplate } from '@nevermined-io/sdk'
import { access, accessDLEQ, nftHolder } from './ConditionTemplate'

export const nft721AccessTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const nft721AccessTemplateServiceAgreementTemplate = (): ServiceAgreementTemplate => ({
contractName: 'NFT721AccessTemplate',
events: [
{
Expand All @@ -20,8 +20,8 @@ export const nft721AccessTemplateServiceAgreementTemplate: ServiceAgreementTempl
nftAccess: [],
},
conditions: [nftHolder, access],
}
export const nft721AccessTemplateServiceAgreementTemplateDLEQ: ServiceAgreementTemplate = {
})
export const nft721AccessTemplateServiceAgreementTemplateDLEQ = (): ServiceAgreementTemplate => ({
contractName: 'NFT721AccessTemplate',
events: [
{
Expand All @@ -40,4 +40,4 @@ export const nft721AccessTemplateServiceAgreementTemplateDLEQ: ServiceAgreementT
nftAccess: [],
},
conditions: [nftHolder, accessDLEQ],
}
})
4 changes: 2 additions & 2 deletions src/NFT721AccessProofTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class NFT721AccessProofTemplate extends ProofTemplate<
}
}

public async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate> {
return nft721AccessTemplateServiceAgreementTemplate
public getServiceAgreementTemplate(): ServiceAgreementTemplate {
return nft721AccessTemplateServiceAgreementTemplate()
}
}
8 changes: 4 additions & 4 deletions src/NFT721SalesWithAccessTemplate.serviceAgreementTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ServiceAgreementTemplate } from '@nevermined-io/sdk'
import { access, accessDLEQ, escrowPayment, lockPayment, transferNFT721 } from './ConditionTemplate'

export const nft721SalesTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const nft721SalesTemplateServiceAgreementTemplate = (): ServiceAgreementTemplate => ({
contractName: 'NFT721SalesTemplate',
events: [
{
Expand All @@ -21,9 +21,9 @@ export const nft721SalesTemplateServiceAgreementTemplate: ServiceAgreementTempla
escrowPayment: ['lockPayment', 'transferNFT'],
},
conditions: [lockPayment, transferNFT721, escrowPayment, access],
}
})

export const nft721SalesTemplateServiceAgreementTemplateDLEQ: ServiceAgreementTemplate = {
export const nft721SalesTemplateServiceAgreementTemplateDLEQ = (): ServiceAgreementTemplate => ({
contractName: 'NFT721SalesTemplate',
events: [
{
Expand All @@ -43,4 +43,4 @@ export const nft721SalesTemplateServiceAgreementTemplateDLEQ: ServiceAgreementTe
escrowPayment: ['lockPayment', 'transferNFT'],
},
conditions: [lockPayment, transferNFT721, escrowPayment, accessDLEQ],
}
})
4 changes: 2 additions & 2 deletions src/NFT721SalesWithAccessTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class NFT721SalesWithAccessTemplate extends ProofTemplate<
}
}

public async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate> {
return nft721SalesTemplateServiceAgreementTemplate
public getServiceAgreementTemplate(): ServiceAgreementTemplate {
return nft721SalesTemplateServiceAgreementTemplate()
}
}
4 changes: 2 additions & 2 deletions src/NFT721SalesWithDLEQTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export class NFT721SalesWithDLEQTemplate extends DLEQTemplate<
}
}

public async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate> {
return nft721SalesTemplateServiceAgreementTemplateDLEQ
public getServiceAgreementTemplate(): ServiceAgreementTemplate {
return nft721SalesTemplateServiceAgreementTemplateDLEQ()
}
}
9 changes: 4 additions & 5 deletions src/NFTAccessDLEQTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ServiceAgreementTemplate,
NFTHolderCondition,
AgreementInstance,
BigNumber,
InstantiableConfig,
} from '@nevermined-io/sdk'
import { AccessDLEQCondition } from './AccessDLEQCondition'
Expand All @@ -16,7 +15,7 @@ import { ServiceNFTAccessProof } from './Service'

export interface NFTAccessDLEQTemplateParams {
holderAddress: string
amount: BigNumber
amount: bigint
consumer: Account
}

Expand Down Expand Up @@ -65,7 +64,7 @@ export class NFTAccessDLEQTemplate extends DLEQTemplate<
public params(
consumer: Account,
holderAddress: string,
amount: BigNumber,
amount: bigint,
): NFTAccessDLEQTemplateParams {
return { holderAddress, amount, consumer }
}
Expand Down Expand Up @@ -96,7 +95,7 @@ export class NFTAccessDLEQTemplate extends DLEQTemplate<
}
}

public async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate> {
return nftAccessTemplateServiceAgreementTemplateDLEQ
public getServiceAgreementTemplate(): ServiceAgreementTemplate {
return nftAccessTemplateServiceAgreementTemplateDLEQ()
}
}
8 changes: 4 additions & 4 deletions src/NFTAccessProofTemplate.serviceAgreementTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ServiceAgreementTemplate } from '@nevermined-io/sdk'
import { access, accessDLEQ, nftHolder } from './ConditionTemplate'

export const nftAccessTemplateServiceAgreementTemplate: ServiceAgreementTemplate = {
export const nftAccessTemplateServiceAgreementTemplate = (): ServiceAgreementTemplate => ({
contractName: 'NFTAccessTemplate',
events: [
{
Expand All @@ -20,9 +20,9 @@ export const nftAccessTemplateServiceAgreementTemplate: ServiceAgreementTemplate
nftAccess: [],
},
conditions: [nftHolder, access],
}
})

export const nftAccessTemplateServiceAgreementTemplateDLEQ: ServiceAgreementTemplate = {
export const nftAccessTemplateServiceAgreementTemplateDLEQ = (): ServiceAgreementTemplate => ({
contractName: 'NFTAccessTemplate',
events: [
{
Expand All @@ -41,4 +41,4 @@ export const nftAccessTemplateServiceAgreementTemplateDLEQ: ServiceAgreementTemp
nftAccess: [],
},
conditions: [nftHolder, accessDLEQ],
}
})
9 changes: 4 additions & 5 deletions src/NFTAccessProofTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ServiceAgreementTemplate,
NFTHolderCondition,
AgreementInstance,
BigNumber,
InstantiableConfig,
} from '@nevermined-io/sdk'
import { AccessProofCondition } from './AccessProofCondition'
Expand All @@ -16,7 +15,7 @@ import { ServiceNFTAccessProof } from './Service'

export interface NFTAccessProofTemplateParams {
holderAddress: string
amount: BigNumber
amount: bigint
consumer: Account
}

Expand Down Expand Up @@ -69,7 +68,7 @@ export class NFTAccessProofTemplate extends ProofTemplate<
public params(
consumer: Account,
holderAddress: string,
amount: BigNumber,
amount: bigint,
): NFTAccessProofTemplateParams {
return { holderAddress, amount, consumer }
}
Expand Down Expand Up @@ -100,7 +99,7 @@ export class NFTAccessProofTemplate extends ProofTemplate<
}
}

public async getServiceAgreementTemplate(): Promise<ServiceAgreementTemplate> {
return nftAccessTemplateServiceAgreementTemplate
public getServiceAgreementTemplate(): ServiceAgreementTemplate {
return nftAccessTemplateServiceAgreementTemplate()
}
}
Loading

0 comments on commit 257e2f9

Please sign in to comment.