@nevermined-io/core-kit 0.0.2-rc19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/Instantiable.abstract.d.ts +35 -0
- package/dist/Instantiable.abstract.d.ts.map +1 -0
- package/dist/Instantiable.abstract.js +102 -0
- package/dist/artifacts/generated.d.ts +29912 -0
- package/dist/artifacts/generated.d.ts.map +1 -0
- package/dist/artifacts/generated.js +16797 -0
- package/dist/contracts/AccessManager.d.ts +17 -0
- package/dist/contracts/AccessManager.d.ts.map +1 -0
- package/dist/contracts/AccessManager.js +15 -0
- package/dist/contracts/AssetRegistry.d.ts +65 -0
- package/dist/contracts/AssetRegistry.d.ts.map +1 -0
- package/dist/contracts/AssetRegistry.js +103 -0
- package/dist/contracts/ContractBase.d.ts +21 -0
- package/dist/contracts/ContractBase.d.ts.map +1 -0
- package/dist/contracts/ContractBase.js +270 -0
- package/dist/contracts/ContractsApi.d.ts +62 -0
- package/dist/contracts/ContractsApi.d.ts.map +1 -0
- package/dist/contracts/ContractsApi.js +66 -0
- package/dist/contracts/FiatPaymentTemplate.d.ts +10 -0
- package/dist/contracts/FiatPaymentTemplate.d.ts.map +1 -0
- package/dist/contracts/FiatPaymentTemplate.js +14 -0
- package/dist/contracts/FiatSettlementCondition.d.ts +11 -0
- package/dist/contracts/FiatSettlementCondition.d.ts.map +1 -0
- package/dist/contracts/FiatSettlementCondition.js +18 -0
- package/dist/contracts/FixedPaymentTemplate.d.ts +10 -0
- package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -0
- package/dist/contracts/FixedPaymentTemplate.js +14 -0
- package/dist/contracts/NFT1155Base.d.ts +41 -0
- package/dist/contracts/NFT1155Base.d.ts.map +1 -0
- package/dist/contracts/NFT1155Base.js +21 -0
- package/dist/contracts/NFT1155Credits.d.ts +6 -0
- package/dist/contracts/NFT1155Credits.d.ts.map +1 -0
- package/dist/contracts/NFT1155Credits.js +9 -0
- package/dist/contracts/NFT1155ExpirableCredits.d.ts +34 -0
- package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +1 -0
- package/dist/contracts/NFT1155ExpirableCredits.js +18 -0
- package/dist/contracts/NVMConfig.d.ts +10 -0
- package/dist/contracts/NVMConfig.d.ts.map +1 -0
- package/dist/contracts/NVMConfig.js +18 -0
- package/dist/contracts/ProtocolStandardFees.d.ts +9 -0
- package/dist/contracts/ProtocolStandardFees.d.ts.map +1 -0
- package/dist/contracts/ProtocolStandardFees.js +15 -0
- package/dist/contracts/Roles.d.ts +13 -0
- package/dist/contracts/Roles.d.ts.map +1 -0
- package/dist/contracts/Roles.js +12 -0
- package/dist/contracts/index.d.ts +3 -0
- package/dist/contracts/index.d.ts.map +1 -0
- package/dist/contracts/index.js +2 -0
- package/dist/errors/NeverminedErrors.d.ts +71 -0
- package/dist/errors/NeverminedErrors.d.ts.map +1 -0
- package/dist/errors/NeverminedErrors.js +123 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/models/Logger.d.ts +9 -0
- package/dist/models/Logger.d.ts.map +1 -0
- package/dist/models/Logger.js +27 -0
- package/dist/models/NeverminedOptions.d.ts +55 -0
- package/dist/models/NeverminedOptions.d.ts.map +1 -0
- package/dist/models/NeverminedOptions.js +58 -0
- package/dist/models/NvmApiKey.d.ts +137 -0
- package/dist/models/NvmApiKey.d.ts.map +1 -0
- package/dist/models/NvmApiKey.js +234 -0
- package/dist/models/Transactions.d.ts +11 -0
- package/dist/models/Transactions.d.ts.map +1 -0
- package/dist/models/Transactions.js +1 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.d.ts.map +1 -0
- package/dist/models/index.js +4 -0
- package/dist/nevermined/DID.d.ts +45 -0
- package/dist/nevermined/DID.d.ts.map +1 -0
- package/dist/nevermined/DID.js +90 -0
- package/dist/nevermined/Nevermined.d.ts +48 -0
- package/dist/nevermined/Nevermined.d.ts.map +1 -0
- package/dist/nevermined/Nevermined.js +72 -0
- package/dist/nevermined/api/PaymentsApi.d.ts +17 -0
- package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -0
- package/dist/nevermined/api/PaymentsApi.js +125 -0
- package/dist/nevermined/api/ServicesApi.d.ts +28 -0
- package/dist/nevermined/api/ServicesApi.d.ts.map +1 -0
- package/dist/nevermined/api/ServicesApi.js +33 -0
- package/dist/nevermined/api/UtilsApi.d.ts +28 -0
- package/dist/nevermined/api/UtilsApi.d.ts.map +1 -0
- package/dist/nevermined/api/UtilsApi.js +33 -0
- package/dist/nevermined/index.d.ts +4 -0
- package/dist/nevermined/index.d.ts.map +1 -0
- package/dist/nevermined/index.js +3 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +276 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/BlockchainViemUtils.js +376 -0
- package/dist/nevermined/utils/JwtUtils.d.ts +27 -0
- package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/JwtUtils.js +154 -0
- package/dist/nevermined/utils/SignatureUtils.d.ts +14 -0
- package/dist/nevermined/utils/SignatureUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/SignatureUtils.js +99 -0
- package/dist/nevermined/utils/WebServiceConnector.d.ts +32 -0
- package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -0
- package/dist/nevermined/utils/WebServiceConnector.js +191 -0
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +19 -0
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -0
- package/dist/nevermined/utils/ZeroDevPolicies.js +78 -0
- package/dist/nevermined/utils/index.d.ts +6 -0
- package/dist/nevermined/utils/index.d.ts.map +1 -0
- package/dist/nevermined/utils/index.js +5 -0
- package/dist/services/Api.d.ts +7 -0
- package/dist/services/Api.d.ts.map +1 -0
- package/dist/services/Api.js +25 -0
- package/dist/services/MarketplaceAPI.d.ts +7 -0
- package/dist/services/MarketplaceAPI.d.ts.map +1 -0
- package/dist/services/MarketplaceAPI.js +25 -0
- package/dist/services/MetadataService.d.ts +90 -0
- package/dist/services/MetadataService.d.ts.map +1 -0
- package/dist/services/MetadataService.js +277 -0
- package/dist/services/Profiles.d.ts +16 -0
- package/dist/services/Profiles.d.ts.map +1 -0
- package/dist/services/Profiles.js +84 -0
- package/dist/services/index.d.ts +4 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/index.js +3 -0
- package/dist/utils/ConversionTypeHelpers.d.ts +8 -0
- package/dist/utils/ConversionTypeHelpers.d.ts.map +1 -0
- package/dist/utils/ConversionTypeHelpers.js +31 -0
- package/dist/utils/Network.d.ts +5 -0
- package/dist/utils/Network.d.ts.map +1 -0
- package/dist/utils/Network.js +224 -0
- package/dist/utils/helpers.d.ts +21 -0
- package/dist/utils/helpers.d.ts.map +1 -0
- package/dist/utils/helpers.js +109 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +3 -0
- package/package.json +27 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Instantiable } from '../Instantiable.abstract.js';
|
|
2
|
+
import { NeverminedOptions } from '../models/NeverminedOptions.js';
|
|
3
|
+
import { UtilsApi } from '../nevermined/api/UtilsApi.js';
|
|
4
|
+
import { ServicesApi } from './api/ServicesApi.js';
|
|
5
|
+
import { ContractsApi } from '../contracts/ContractsApi.js';
|
|
6
|
+
import { PaymentsApi } from './api/PaymentsApi.js';
|
|
7
|
+
/**
|
|
8
|
+
* Main interface for Nevermined Protocol.
|
|
9
|
+
*/
|
|
10
|
+
export declare class Nevermined extends Instantiable {
|
|
11
|
+
/**
|
|
12
|
+
* Returns the instance of Nevermined.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { Nevermined, Config } from '@nevermined-io/sdk'
|
|
17
|
+
*
|
|
18
|
+
* const config: Config = {...}
|
|
19
|
+
* const nevermined = await Nevermined.getInstance(config)
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param config - Nevermined instance configuration.
|
|
23
|
+
* @returns A {@link Nevermined} instance
|
|
24
|
+
*/
|
|
25
|
+
static getInstance(config: NeverminedOptions): Promise<Nevermined>;
|
|
26
|
+
/**
|
|
27
|
+
* ContractsApi instance.
|
|
28
|
+
*/
|
|
29
|
+
contracts: ContractsApi;
|
|
30
|
+
/**
|
|
31
|
+
* SearchApi API
|
|
32
|
+
*/
|
|
33
|
+
services: ServicesApi;
|
|
34
|
+
/**
|
|
35
|
+
* Utils submodule
|
|
36
|
+
*/
|
|
37
|
+
utils: UtilsApi;
|
|
38
|
+
payments: PaymentsApi;
|
|
39
|
+
/**
|
|
40
|
+
* Web3 Clients
|
|
41
|
+
*/
|
|
42
|
+
/**
|
|
43
|
+
* If contracts are initialized
|
|
44
|
+
*/
|
|
45
|
+
contractsInitialized: boolean | undefined;
|
|
46
|
+
private constructor();
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=Nevermined.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Nevermined.d.ts","sourceRoot":"","sources":["../../src/nevermined/Nevermined.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAwC,MAAM,6BAA6B,CAAA;AAChG,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AAClE,OAAO,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAElD;;GAEG;AACH,qBAAa,UAAW,SAAQ,YAAY;IAC1C;;;;;;;;;;;;;OAaG;WAC0B,WAAW,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,UAAU,CAAC;IAgCxF;;OAEG;IACI,SAAS,EAAG,YAAY,CAAA;IAE/B;;OAEG;IACI,QAAQ,EAAG,WAAW,CAAA;IAE7B;;OAEG;IACI,KAAK,EAAG,QAAQ,CAAA;IAEhB,QAAQ,EAAG,WAAW,CAAA;IAE7B;;OAEG;IAGH;;OAEG;IACI,oBAAoB,EAAE,OAAO,GAAG,SAAS,CAAA;IAEhD,OAAO;CAGR"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { Instantiable, generateInstantiableConfigFromConfig } from '../Instantiable.abstract.js';
|
|
2
|
+
import { UtilsApi } from '../nevermined/api/UtilsApi.js';
|
|
3
|
+
import { ServicesApi } from './api/ServicesApi.js';
|
|
4
|
+
import { ContractsApi } from '../contracts/ContractsApi.js';
|
|
5
|
+
import { PaymentsApi } from './api/PaymentsApi.js';
|
|
6
|
+
/**
|
|
7
|
+
* Main interface for Nevermined Protocol.
|
|
8
|
+
*/
|
|
9
|
+
export class Nevermined extends Instantiable {
|
|
10
|
+
/**
|
|
11
|
+
* Returns the instance of Nevermined.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { Nevermined, Config } from '@nevermined-io/sdk'
|
|
16
|
+
*
|
|
17
|
+
* const config: Config = {...}
|
|
18
|
+
* const nevermined = await Nevermined.getInstance(config)
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* @param config - Nevermined instance configuration.
|
|
22
|
+
* @returns A {@link Nevermined} instance
|
|
23
|
+
*/
|
|
24
|
+
static async getInstance(config) {
|
|
25
|
+
const instance = new Nevermined();
|
|
26
|
+
// Nevermined main API
|
|
27
|
+
try {
|
|
28
|
+
const instanceConfig = {
|
|
29
|
+
...(await generateInstantiableConfigFromConfig(config, true)),
|
|
30
|
+
nevermined: instance,
|
|
31
|
+
};
|
|
32
|
+
instance.setInstanceConfig(instanceConfig);
|
|
33
|
+
// instance.search = new SearchApi(instanceConfig)
|
|
34
|
+
instance.services = new ServicesApi(instanceConfig);
|
|
35
|
+
instance.utils = new UtilsApi(instanceConfig);
|
|
36
|
+
instance.contracts = await ContractsApi.getInstance(instanceConfig);
|
|
37
|
+
await instance.contracts.init();
|
|
38
|
+
instance.payments = new PaymentsApi(instanceConfig);
|
|
39
|
+
instance.contractsInitialized = true;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
instance.contractsInitialized = false;
|
|
43
|
+
instance.logger.error(error);
|
|
44
|
+
instance.logger.error("Contracts didn't initialize because for the above mentioned reason. Loading SDK in offchain mode...");
|
|
45
|
+
}
|
|
46
|
+
return instance;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* ContractsApi instance.
|
|
50
|
+
*/
|
|
51
|
+
contracts;
|
|
52
|
+
/**
|
|
53
|
+
* SearchApi API
|
|
54
|
+
*/
|
|
55
|
+
services;
|
|
56
|
+
/**
|
|
57
|
+
* Utils submodule
|
|
58
|
+
*/
|
|
59
|
+
utils;
|
|
60
|
+
payments;
|
|
61
|
+
/**
|
|
62
|
+
* Web3 Clients
|
|
63
|
+
*/
|
|
64
|
+
// public web3: Web3Clients
|
|
65
|
+
/**
|
|
66
|
+
* If contracts are initialized
|
|
67
|
+
*/
|
|
68
|
+
contractsInitialized;
|
|
69
|
+
constructor() {
|
|
70
|
+
super();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Account, Address } from 'viem';
|
|
2
|
+
import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js';
|
|
3
|
+
import { SmartAccount } from 'viem/account-abstraction';
|
|
4
|
+
import { OrderResult, Plan } from '@nvm-monorepo/commons';
|
|
5
|
+
export declare class PaymentsApi extends Instantiable {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new PaymentsApi
|
|
8
|
+
* @param config - Configuration of the Nevermined instance
|
|
9
|
+
* @returns {@link PaymentsApi}
|
|
10
|
+
*/
|
|
11
|
+
constructor(config: InstantiableConfig);
|
|
12
|
+
private getTokenContract;
|
|
13
|
+
getERC20Balance(userAddress: Address, tokenAddress: Address): Promise<bigint>;
|
|
14
|
+
orderFiatPayment(planId: bigint, planReceiver: Address, from: Account | SmartAccount): Promise<OrderResult>;
|
|
15
|
+
orderCryptoPayment(planId: bigint, plan: Plan, from: Account | SmartAccount): Promise<OrderResult>;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=PaymentsApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PaymentsApi.d.ts","sourceRoot":"","sources":["../../../src/nevermined/api/PaymentsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,OAAO,EAAsC,MAAM,MAAM,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,IAAI,EAA8B,MAAM,uBAAuB,CAAA;AAQrF,qBAAa,WAAY,SAAQ,YAAY;IAC3C;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;YAKxB,gBAAgB;IAsBjB,eAAe,CAAC,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB7E,gBAAgB,CAC3B,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;IAqBV,kBAAkB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;CA8ExB"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { getContract, parseAbi, zeroAddress } from 'viem';
|
|
2
|
+
import { Instantiable } from '../../Instantiable.abstract.js';
|
|
3
|
+
import { lockPaymentConditionAddress } from '../../artifacts/generated.js';
|
|
4
|
+
import { createKernelClient } from '../utils/BlockchainViemUtils.js';
|
|
5
|
+
import { PlanTransactionPaymentType } from '@nvm-monorepo/commons';
|
|
6
|
+
const TOKEN_APPROVE_ABI = parseAbi([
|
|
7
|
+
'function approve(address spender, uint256 amount) external returns (bool)',
|
|
8
|
+
]);
|
|
9
|
+
const TOKEN_BALANCE_ABI = parseAbi(['function balanceOf(address) view returns (uint256)']);
|
|
10
|
+
export class PaymentsApi extends Instantiable {
|
|
11
|
+
/**
|
|
12
|
+
* Creates a new PaymentsApi
|
|
13
|
+
* @param config - Configuration of the Nevermined instance
|
|
14
|
+
* @returns {@link PaymentsApi}
|
|
15
|
+
*/
|
|
16
|
+
constructor(config) {
|
|
17
|
+
super();
|
|
18
|
+
this.setInstanceConfig(config);
|
|
19
|
+
}
|
|
20
|
+
async getTokenContract(token, from) {
|
|
21
|
+
if (from.type === 'smart') {
|
|
22
|
+
const kernelClient = await createKernelClient(from, this.config.chainId, this.config.zeroDevProjectId, this.nevermined.contracts.assetRegistry.publicClient);
|
|
23
|
+
return getContract({
|
|
24
|
+
address: token,
|
|
25
|
+
abi: TOKEN_APPROVE_ABI,
|
|
26
|
+
client: kernelClient,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return getContract({
|
|
31
|
+
address: token,
|
|
32
|
+
abi: TOKEN_APPROVE_ABI,
|
|
33
|
+
client: this.walletClient,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async getERC20Balance(userAddress, tokenAddress) {
|
|
38
|
+
try {
|
|
39
|
+
return this.client.public.readContract({
|
|
40
|
+
address: tokenAddress,
|
|
41
|
+
abi: TOKEN_BALANCE_ABI,
|
|
42
|
+
functionName: 'balanceOf',
|
|
43
|
+
args: [userAddress],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
this.logger.debug(`Error fetching ERC20 balance for ${userAddress} in ${tokenAddress}: ${error}`);
|
|
48
|
+
}
|
|
49
|
+
return 0n;
|
|
50
|
+
}
|
|
51
|
+
async orderFiatPayment(planId, planReceiver, from) {
|
|
52
|
+
const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId);
|
|
53
|
+
const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
|
|
54
|
+
const txHash = await this.nevermined.contracts.fiatPaymentTemplate.createAgreement(planId, planReceiver, from);
|
|
55
|
+
const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
|
|
56
|
+
return {
|
|
57
|
+
txHash: txReceipt.transactionHash,
|
|
58
|
+
planId,
|
|
59
|
+
planReceiver: from.address,
|
|
60
|
+
totalAmount,
|
|
61
|
+
numCredits: plan.credits.amount,
|
|
62
|
+
paymentMethod: PlanTransactionPaymentType.Fiat,
|
|
63
|
+
currency: 'USD',
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
async orderCryptoPayment(planId, plan, from) {
|
|
67
|
+
try {
|
|
68
|
+
// const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId)
|
|
69
|
+
const tokenAddress = plan.price.tokenAddress;
|
|
70
|
+
const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
|
|
71
|
+
this.logger.debug(`Ordering ${tokenAddress} ${totalAmount}`);
|
|
72
|
+
if (tokenAddress && tokenAddress !== zeroAddress) {
|
|
73
|
+
// ERC20 token payment
|
|
74
|
+
if (totalAmount > 0n) {
|
|
75
|
+
const erc20Balance = await this.getERC20Balance(from.address, tokenAddress);
|
|
76
|
+
if (erc20Balance < totalAmount) {
|
|
77
|
+
throw new Error(`Insufficient balance (${erc20Balance} < ${totalAmount}) for ERC20 ${tokenAddress}`);
|
|
78
|
+
}
|
|
79
|
+
const tokenContract = await this.getTokenContract(tokenAddress, from);
|
|
80
|
+
// Approve lockPayment contract
|
|
81
|
+
const hash = await tokenContract.write.approve([lockPaymentConditionAddress, totalAmount]);
|
|
82
|
+
const receipt = await this.nevermined.contracts.fixedPaymentTemplate.publicClient.waitForTransactionReceipt({ hash });
|
|
83
|
+
this.logger.debug('Approving token transfer to lockPayment contract', receipt);
|
|
84
|
+
}
|
|
85
|
+
const txHash = await this.nevermined.contracts.fixedPaymentTemplate.createAgreement(planId, from);
|
|
86
|
+
const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
|
|
87
|
+
return {
|
|
88
|
+
txHash: txReceipt.transactionHash,
|
|
89
|
+
planId,
|
|
90
|
+
planReceiver: from.address,
|
|
91
|
+
totalAmount,
|
|
92
|
+
numCredits: plan.credits.amount,
|
|
93
|
+
paymentMethod: PlanTransactionPaymentType.Crypto,
|
|
94
|
+
currency: 'USDC',
|
|
95
|
+
tokenAddress,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// Native token payment
|
|
100
|
+
const nativeTokenBalance = await this.client.public.getBalance({ address: from.address });
|
|
101
|
+
if (nativeTokenBalance < totalAmount) {
|
|
102
|
+
throw new Error(`Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`);
|
|
103
|
+
}
|
|
104
|
+
const txHash = await this.nevermined.contracts.fixedPaymentTemplate.createAgreement(planId, from, {
|
|
105
|
+
value: totalAmount,
|
|
106
|
+
});
|
|
107
|
+
const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
|
|
108
|
+
return {
|
|
109
|
+
txHash: txReceipt.transactionHash,
|
|
110
|
+
planId,
|
|
111
|
+
planReceiver: from.address,
|
|
112
|
+
totalAmount,
|
|
113
|
+
numCredits: plan.credits.amount,
|
|
114
|
+
paymentMethod: PlanTransactionPaymentType.Crypto,
|
|
115
|
+
currency: 'Native',
|
|
116
|
+
tokenAddress: zeroAddress,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
this.logger.error('Error in PaymentsApi order method:', error);
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js';
|
|
2
|
+
import { Api } from '../../services/Api.js';
|
|
3
|
+
import { MetadataService } from '../../services/MetadataService.js';
|
|
4
|
+
import { Profiles } from '../../services/Profiles.js';
|
|
5
|
+
/**
|
|
6
|
+
* Utils internal submodule of Nevermined.
|
|
7
|
+
*/
|
|
8
|
+
export declare class ServicesApi extends Instantiable {
|
|
9
|
+
/**
|
|
10
|
+
* Nevermined Node Service
|
|
11
|
+
*/
|
|
12
|
+
api: Api;
|
|
13
|
+
/**
|
|
14
|
+
* Marketplace instance.
|
|
15
|
+
*/
|
|
16
|
+
metadata: MetadataService;
|
|
17
|
+
/**
|
|
18
|
+
* Profiles instance
|
|
19
|
+
*/
|
|
20
|
+
profiles: Profiles;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ServicesApi
|
|
23
|
+
* @param config - Configuration of the Nevermined instance
|
|
24
|
+
* @returns {@link ServicesApi}
|
|
25
|
+
*/
|
|
26
|
+
constructor(config: InstantiableConfig);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=ServicesApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ServicesApi.d.ts","sourceRoot":"","sources":["../../../src/nevermined/api/ServicesApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACjF,OAAO,EAAE,GAAG,EAAE,MAAM,uBAAuB,CAAA;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAA;AACnE,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C;;OAEG;IACI,GAAG,EAAE,GAAG,CAAA;IAEf;;OAEG;IACI,QAAQ,EAAE,eAAe,CAAA;IAEhC;;OAEG;IACI,QAAQ,EAAE,QAAQ,CAAA;IAEzB;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;CAQvC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Instantiable } from '../../Instantiable.abstract.js';
|
|
2
|
+
import { Api } from '../../services/Api.js';
|
|
3
|
+
import { MetadataService } from '../../services/MetadataService.js';
|
|
4
|
+
import { Profiles } from '../../services/Profiles.js';
|
|
5
|
+
/**
|
|
6
|
+
* Utils internal submodule of Nevermined.
|
|
7
|
+
*/
|
|
8
|
+
export class ServicesApi extends Instantiable {
|
|
9
|
+
/**
|
|
10
|
+
* Nevermined Node Service
|
|
11
|
+
*/
|
|
12
|
+
api;
|
|
13
|
+
/**
|
|
14
|
+
* Marketplace instance.
|
|
15
|
+
*/
|
|
16
|
+
metadata;
|
|
17
|
+
/**
|
|
18
|
+
* Profiles instance
|
|
19
|
+
*/
|
|
20
|
+
profiles;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new ServicesApi
|
|
23
|
+
* @param config - Configuration of the Nevermined instance
|
|
24
|
+
* @returns {@link ServicesApi}
|
|
25
|
+
*/
|
|
26
|
+
constructor(config) {
|
|
27
|
+
super();
|
|
28
|
+
this.setInstanceConfig(config);
|
|
29
|
+
this.api = new Api(config);
|
|
30
|
+
this.metadata = new MetadataService(config);
|
|
31
|
+
this.profiles = new Profiles(config);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js';
|
|
2
|
+
import { JwtUtils } from '../utils/JwtUtils.js';
|
|
3
|
+
import { SignatureUtils } from '../utils/SignatureUtils.js';
|
|
4
|
+
import { WebServiceConnector } from '../utils/WebServiceConnector.js';
|
|
5
|
+
/**
|
|
6
|
+
* Nevermined Utils API
|
|
7
|
+
*/
|
|
8
|
+
export declare class UtilsApi extends Instantiable {
|
|
9
|
+
/**
|
|
10
|
+
* Fetch utils.
|
|
11
|
+
*/
|
|
12
|
+
fetch: WebServiceConnector;
|
|
13
|
+
/**
|
|
14
|
+
* Jwt utils.
|
|
15
|
+
*/
|
|
16
|
+
jwt: JwtUtils;
|
|
17
|
+
/**
|
|
18
|
+
* Signature utils.
|
|
19
|
+
*/
|
|
20
|
+
signature: SignatureUtils;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new AssetsApi
|
|
23
|
+
* @param config - Configuration of the Nevermined instance
|
|
24
|
+
* @returns {@link UtilsApi}
|
|
25
|
+
*/
|
|
26
|
+
constructor(config: InstantiableConfig);
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=UtilsApi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UtilsApi.d.ts","sourceRoot":"","sources":["../../../src/nevermined/api/UtilsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACjF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAA;AAErE;;GAEG;AACH,qBAAa,QAAS,SAAQ,YAAY;IACxC;;OAEG;IACI,KAAK,EAAE,mBAAmB,CAAA;IAEjC;;OAEG;IACI,GAAG,EAAE,QAAQ,CAAA;IAEpB;;OAEG;IACI,SAAS,EAAE,cAAc,CAAA;IAEhC;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;CAQvC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Instantiable } from '../../Instantiable.abstract.js';
|
|
2
|
+
import { JwtUtils } from '../utils/JwtUtils.js';
|
|
3
|
+
import { SignatureUtils } from '../utils/SignatureUtils.js';
|
|
4
|
+
import { WebServiceConnector } from '../utils/WebServiceConnector.js';
|
|
5
|
+
/**
|
|
6
|
+
* Nevermined Utils API
|
|
7
|
+
*/
|
|
8
|
+
export class UtilsApi extends Instantiable {
|
|
9
|
+
/**
|
|
10
|
+
* Fetch utils.
|
|
11
|
+
*/
|
|
12
|
+
fetch;
|
|
13
|
+
/**
|
|
14
|
+
* Jwt utils.
|
|
15
|
+
*/
|
|
16
|
+
jwt;
|
|
17
|
+
/**
|
|
18
|
+
* Signature utils.
|
|
19
|
+
*/
|
|
20
|
+
signature;
|
|
21
|
+
/**
|
|
22
|
+
* Creates a new AssetsApi
|
|
23
|
+
* @param config - Configuration of the Nevermined instance
|
|
24
|
+
* @returns {@link UtilsApi}
|
|
25
|
+
*/
|
|
26
|
+
constructor(config) {
|
|
27
|
+
super();
|
|
28
|
+
this.setInstanceConfig(config);
|
|
29
|
+
this.fetch = new WebServiceConnector(config);
|
|
30
|
+
this.jwt = new JwtUtils(config);
|
|
31
|
+
this.signature = new SignatureUtils(config);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nevermined/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,cAAc,kBAAkB,CAAA"}
|