@nevermined-io/core-kit 0.1.4 → 0.1.5

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.
Files changed (145) hide show
  1. package/dist/Instantiable.abstract.d.ts +33 -0
  2. package/dist/Instantiable.abstract.d.ts.map +1 -0
  3. package/dist/Instantiable.abstract.js +98 -0
  4. package/dist/artifacts/generated.d.ts +39371 -0
  5. package/dist/artifacts/generated.d.ts.map +1 -0
  6. package/dist/artifacts/generated.js +21448 -0
  7. package/dist/contracts/AccessManager.d.ts +17 -0
  8. package/dist/contracts/AccessManager.d.ts.map +1 -0
  9. package/dist/contracts/AccessManager.js +15 -0
  10. package/dist/contracts/AssetRegistry.d.ts +105 -0
  11. package/dist/contracts/AssetRegistry.d.ts.map +1 -0
  12. package/dist/contracts/AssetRegistry.js +155 -0
  13. package/dist/contracts/ContractBase.d.ts +45 -0
  14. package/dist/contracts/ContractBase.d.ts.map +1 -0
  15. package/dist/contracts/ContractBase.js +519 -0
  16. package/dist/contracts/ContractsApi.d.ts +69 -0
  17. package/dist/contracts/ContractsApi.d.ts.map +1 -0
  18. package/dist/contracts/ContractsApi.js +73 -0
  19. package/dist/contracts/CryptoTemplateBase.d.ts +11 -0
  20. package/dist/contracts/CryptoTemplateBase.d.ts.map +1 -0
  21. package/dist/contracts/CryptoTemplateBase.js +49 -0
  22. package/dist/contracts/FiatPaymentTemplate.d.ts +10 -0
  23. package/dist/contracts/FiatPaymentTemplate.d.ts.map +1 -0
  24. package/dist/contracts/FiatPaymentTemplate.js +14 -0
  25. package/dist/contracts/FiatSettlementCondition.d.ts +11 -0
  26. package/dist/contracts/FiatSettlementCondition.d.ts.map +1 -0
  27. package/dist/contracts/FiatSettlementCondition.js +18 -0
  28. package/dist/contracts/FixedPaymentTemplate.d.ts +12 -0
  29. package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -0
  30. package/dist/contracts/FixedPaymentTemplate.js +62 -0
  31. package/dist/contracts/NFT1155Base.d.ts +50 -0
  32. package/dist/contracts/NFT1155Base.d.ts.map +1 -0
  33. package/dist/contracts/NFT1155Base.js +24 -0
  34. package/dist/contracts/NFT1155Credits.d.ts +6 -0
  35. package/dist/contracts/NFT1155Credits.d.ts.map +1 -0
  36. package/dist/contracts/NFT1155Credits.js +9 -0
  37. package/dist/contracts/NFT1155ExpirableCredits.d.ts +34 -0
  38. package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +1 -0
  39. package/dist/contracts/NFT1155ExpirableCredits.js +18 -0
  40. package/dist/contracts/NVMConfig.d.ts +10 -0
  41. package/dist/contracts/NVMConfig.d.ts.map +1 -0
  42. package/dist/contracts/NVMConfig.js +18 -0
  43. package/dist/contracts/PayAsYouGoTemplate.d.ts +12 -0
  44. package/dist/contracts/PayAsYouGoTemplate.d.ts.map +1 -0
  45. package/dist/contracts/PayAsYouGoTemplate.js +62 -0
  46. package/dist/contracts/ProtocolStandardFees.d.ts +9 -0
  47. package/dist/contracts/ProtocolStandardFees.d.ts.map +1 -0
  48. package/dist/contracts/ProtocolStandardFees.js +15 -0
  49. package/dist/contracts/Roles.d.ts +13 -0
  50. package/dist/contracts/Roles.d.ts.map +1 -0
  51. package/dist/contracts/Roles.js +12 -0
  52. package/dist/contracts/index.d.ts +3 -0
  53. package/dist/contracts/index.d.ts.map +1 -0
  54. package/dist/contracts/index.js +2 -0
  55. package/dist/errors/NeverminedErrors.d.ts +74 -0
  56. package/dist/errors/NeverminedErrors.d.ts.map +1 -0
  57. package/dist/errors/NeverminedErrors.js +128 -0
  58. package/dist/errors/index.d.ts +2 -0
  59. package/dist/errors/index.d.ts.map +1 -0
  60. package/dist/errors/index.js +1 -0
  61. package/dist/index.d.ts +8 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +8 -0
  64. package/dist/models/AgentAccessToken.d.ts +123 -0
  65. package/dist/models/AgentAccessToken.d.ts.map +1 -0
  66. package/dist/models/AgentAccessToken.js +164 -0
  67. package/dist/models/AgentX402AccessToken.d.ts +59 -0
  68. package/dist/models/AgentX402AccessToken.d.ts.map +1 -0
  69. package/dist/models/AgentX402AccessToken.js +78 -0
  70. package/dist/models/Logger.d.ts +9 -0
  71. package/dist/models/Logger.d.ts.map +1 -0
  72. package/dist/models/Logger.js +27 -0
  73. package/dist/models/NeverminedOptions.d.ts +30 -0
  74. package/dist/models/NeverminedOptions.d.ts.map +1 -0
  75. package/dist/models/NeverminedOptions.js +28 -0
  76. package/dist/models/NvmApiKey.d.ts +137 -0
  77. package/dist/models/NvmApiKey.d.ts.map +1 -0
  78. package/dist/models/NvmApiKey.js +235 -0
  79. package/dist/models/Transactions.d.ts +11 -0
  80. package/dist/models/Transactions.d.ts.map +1 -0
  81. package/dist/models/Transactions.js +1 -0
  82. package/dist/models/index.d.ts +7 -0
  83. package/dist/models/index.d.ts.map +1 -0
  84. package/dist/models/index.js +6 -0
  85. package/dist/nevermined/Nevermined.d.ts +48 -0
  86. package/dist/nevermined/Nevermined.d.ts.map +1 -0
  87. package/dist/nevermined/Nevermined.js +72 -0
  88. package/dist/nevermined/api/PaymentsApi.d.ts +24 -0
  89. package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -0
  90. package/dist/nevermined/api/PaymentsApi.js +179 -0
  91. package/dist/nevermined/api/ServicesApi.d.ts +23 -0
  92. package/dist/nevermined/api/ServicesApi.d.ts.map +1 -0
  93. package/dist/nevermined/api/ServicesApi.js +27 -0
  94. package/dist/nevermined/api/UtilsApi.d.ts +28 -0
  95. package/dist/nevermined/api/UtilsApi.d.ts.map +1 -0
  96. package/dist/nevermined/api/UtilsApi.js +33 -0
  97. package/dist/nevermined/index.d.ts +3 -0
  98. package/dist/nevermined/index.d.ts.map +1 -0
  99. package/dist/nevermined/index.js +2 -0
  100. package/dist/nevermined/utils/AgentUtils.d.ts +8 -0
  101. package/dist/nevermined/utils/AgentUtils.d.ts.map +1 -0
  102. package/dist/nevermined/utils/AgentUtils.js +56 -0
  103. package/dist/nevermined/utils/BlockchainViemUtils.d.ts +280 -0
  104. package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -0
  105. package/dist/nevermined/utils/BlockchainViemUtils.js +408 -0
  106. package/dist/nevermined/utils/JwtUtils.d.ts +27 -0
  107. package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -0
  108. package/dist/nevermined/utils/JwtUtils.js +161 -0
  109. package/dist/nevermined/utils/SignatureUtils.d.ts +14 -0
  110. package/dist/nevermined/utils/SignatureUtils.d.ts.map +1 -0
  111. package/dist/nevermined/utils/SignatureUtils.js +99 -0
  112. package/dist/nevermined/utils/WebServiceConnector.d.ts +30 -0
  113. package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -0
  114. package/dist/nevermined/utils/WebServiceConnector.js +170 -0
  115. package/dist/nevermined/utils/ZeroDevPolicies.d.ts +38 -0
  116. package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -0
  117. package/dist/nevermined/utils/ZeroDevPolicies.js +196 -0
  118. package/dist/nevermined/utils/index.d.ts +7 -0
  119. package/dist/nevermined/utils/index.d.ts.map +1 -0
  120. package/dist/nevermined/utils/index.js +6 -0
  121. package/dist/services/Api.d.ts +7 -0
  122. package/dist/services/Api.d.ts.map +1 -0
  123. package/dist/services/Api.js +25 -0
  124. package/dist/services/Profiles.d.ts +16 -0
  125. package/dist/services/Profiles.d.ts.map +1 -0
  126. package/dist/services/Profiles.js +84 -0
  127. package/dist/services/index.d.ts +3 -0
  128. package/dist/services/index.d.ts.map +1 -0
  129. package/dist/services/index.js +2 -0
  130. package/dist/utils/ConversionTypeHelpers.d.ts +5 -0
  131. package/dist/utils/ConversionTypeHelpers.d.ts.map +1 -0
  132. package/dist/utils/ConversionTypeHelpers.js +30 -0
  133. package/dist/utils/DeploymentInfo.d.ts +15 -0
  134. package/dist/utils/DeploymentInfo.d.ts.map +1 -0
  135. package/dist/utils/DeploymentInfo.js +38 -0
  136. package/dist/utils/Network.d.ts +5 -0
  137. package/dist/utils/Network.d.ts.map +1 -0
  138. package/dist/utils/Network.js +224 -0
  139. package/dist/utils/helpers.d.ts +40 -0
  140. package/dist/utils/helpers.d.ts.map +1 -0
  141. package/dist/utils/helpers.js +189 -0
  142. package/dist/utils/index.d.ts +5 -0
  143. package/dist/utils/index.d.ts.map +1 -0
  144. package/dist/utils/index.js +4 -0
  145. package/package.json +1 -1
@@ -0,0 +1,179 @@
1
+ import { PlanTransactionPaymentType } from '@nvm-monorepo/commons';
2
+ import { isAddress, parseAbi, zeroAddress } from 'viem';
3
+ import { NotEnoughBalance } from '../../errors/NeverminedErrors.js';
4
+ import { Instantiable } from '../../Instantiable.abstract.js';
5
+ const TOKEN_BALANCE_ABI = parseAbi(['function balanceOf(address) view returns (uint256)']);
6
+ const GET_FEE_RATES_ABI = parseAbi([
7
+ 'function getFeeRates() view returns (uint256, uint256, uint256)',
8
+ ]);
9
+ export class PaymentsApi extends Instantiable {
10
+ /**
11
+ * Creates a new PaymentsApi
12
+ * @param config - Configuration of the Nevermined instance
13
+ * @returns {@link PaymentsApi}
14
+ */
15
+ constructor(config) {
16
+ super();
17
+ this.setInstanceConfig(config);
18
+ }
19
+ async getERC20Balance(userAddress, tokenAddress) {
20
+ try {
21
+ return this.client.public.readContract({
22
+ address: tokenAddress,
23
+ abi: TOKEN_BALANCE_ABI,
24
+ functionName: 'balanceOf',
25
+ args: [userAddress],
26
+ });
27
+ }
28
+ catch (error) {
29
+ this.logger.debug(`Error fetching ERC20 balance for ${userAddress} in ${tokenAddress}: ${error}`);
30
+ }
31
+ return 0n;
32
+ }
33
+ async getPlanFees(planId) {
34
+ try {
35
+ const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId);
36
+ let feeControllerAddress;
37
+ if (plan.price.feeController &&
38
+ isAddress(plan.price.feeController) &&
39
+ plan.price.feeController !== zeroAddress) {
40
+ feeControllerAddress = plan.price.feeController;
41
+ }
42
+ else {
43
+ feeControllerAddress = await this.nevermined.contracts.nvmConfig.getDefaultFeeController();
44
+ }
45
+ const result = await this.client.public.readContract({
46
+ address: feeControllerAddress,
47
+ abi: GET_FEE_RATES_ABI,
48
+ functionName: 'getFeeRates',
49
+ args: [],
50
+ });
51
+ const feeReceiver = await this.nevermined.contracts.nvmConfig.getFeeReceiver();
52
+ let amountToReward = 0n;
53
+ plan.price.receivers.map((r, i) => {
54
+ if (r.toLowerCase() !== feeReceiver.toLowerCase()) {
55
+ amountToReward += plan.price.amounts[i];
56
+ }
57
+ });
58
+ const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
59
+ return {
60
+ cryptoFeeRate: result[0],
61
+ fiatFeeRate: result[1],
62
+ feeDenominator: result[2],
63
+ ownerAmount: amountToReward,
64
+ totalAmount,
65
+ };
66
+ }
67
+ catch (error) {
68
+ this.logger.error(`Error fetching plan fee for planId ${planId}: ${String(error)}`);
69
+ throw error;
70
+ }
71
+ }
72
+ async orderFiatPayment(planId, planReceiver, from, numberOfPurchases = 1n) {
73
+ const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId);
74
+ const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
75
+ this.logger.info(`Ordering fiat payment for planId ${planId} to ${planReceiver} from account ${from.address} `);
76
+ const txHash = await this.nevermined.contracts.fiatPaymentTemplate.order(planId, planReceiver, from, numberOfPurchases);
77
+ const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
78
+ return {
79
+ txHash: txReceipt.transactionHash,
80
+ planId,
81
+ planReceiver: from.address,
82
+ totalAmount,
83
+ numCredits: plan.credits.amount,
84
+ paymentMethod: PlanTransactionPaymentType.Fiat,
85
+ currency: 'USD',
86
+ };
87
+ }
88
+ async orderCryptoPlan(planId, plan, from, planReceiver, numberOfPurchases = 1n) {
89
+ if (plan.price.templateAddress === this.nevermined.contracts.payAsYouGoTemplate.address) {
90
+ this.logger.debug(`Setting up Pay-As-You-Go order...`);
91
+ return this._orderCryptoPlan(planId, plan, from, 'payAsYouGo');
92
+ }
93
+ else {
94
+ this.logger.debug(`Setting up Fixed Payment order...`);
95
+ return this._orderCryptoPlan(planId, plan, from, 'fixed', planReceiver, numberOfPurchases);
96
+ }
97
+ }
98
+ async _orderCryptoPlan(planId, plan, from, planType, planReceiver, numberOfPurchases = 1n) {
99
+ try {
100
+ const tokenAddress = plan.price.tokenAddress;
101
+ const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n) * numberOfPurchases;
102
+ this.logger.debug(`Ordering ${tokenAddress} ${totalAmount}`);
103
+ let txHash;
104
+ if (tokenAddress && tokenAddress !== zeroAddress) {
105
+ this.logger.debug(`Processing ERC20 payment...`);
106
+ // ERC20 token payment
107
+ if (totalAmount > 0n) {
108
+ const erc20Balance = await this.getERC20Balance(from.address, tokenAddress);
109
+ this.logger.debug(`ERC20 balance for ${from.address} in ${tokenAddress}: balance = ${erc20Balance} - total amount = ${totalAmount}`);
110
+ if (erc20Balance < totalAmount) {
111
+ throw new NotEnoughBalance(`Insufficient balance (${erc20Balance} < ${totalAmount}) for ERC20 ${tokenAddress}`);
112
+ }
113
+ if (planType === 'payAsYouGo') {
114
+ txHash = await this.nevermined.contracts.payAsYouGoTemplate.orderWithApprovals(planId, totalAmount, tokenAddress, from);
115
+ }
116
+ else {
117
+ txHash = await this.nevermined.contracts.fixedPaymentTemplate.orderWithApprovals(planId, totalAmount, tokenAddress, from, planReceiver || from.address, numberOfPurchases);
118
+ }
119
+ this.logger.debug(`Token approved + Agreement Created: ${txHash}`);
120
+ }
121
+ else {
122
+ if (planType === 'payAsYouGo') {
123
+ txHash = await this.nevermined.contracts.payAsYouGoTemplate.order(planId, from);
124
+ }
125
+ else {
126
+ txHash = await this.nevermined.contracts.fixedPaymentTemplate.order(planId, from, planReceiver || from.address);
127
+ }
128
+ }
129
+ if (!txHash) {
130
+ this.logger.error('Error in PaymentsApi order method: txHash not defined');
131
+ throw new Error('txHash not defined');
132
+ }
133
+ const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
134
+ return {
135
+ txHash: txReceipt.transactionHash,
136
+ planId,
137
+ planReceiver: from.address,
138
+ totalAmount,
139
+ numCredits: plan.credits.amount * numberOfPurchases,
140
+ paymentMethod: PlanTransactionPaymentType.Crypto,
141
+ currency: 'USDC',
142
+ tokenAddress,
143
+ };
144
+ }
145
+ else {
146
+ // Native token payment
147
+ const nativeTokenBalance = await this.client.public.getBalance({ address: from.address });
148
+ if (nativeTokenBalance < totalAmount) {
149
+ throw new NotEnoughBalance(`Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`);
150
+ }
151
+ if (planType === 'payAsYouGo') {
152
+ txHash = await this.nevermined.contracts.payAsYouGoTemplate.order(planId, from, {
153
+ value: totalAmount,
154
+ });
155
+ }
156
+ else {
157
+ txHash = await this.nevermined.contracts.fixedPaymentTemplate.order(planId, from, planReceiver || from.address, numberOfPurchases, {
158
+ value: totalAmount,
159
+ });
160
+ }
161
+ const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
162
+ return {
163
+ txHash: txReceipt.transactionHash,
164
+ planId,
165
+ planReceiver: from.address,
166
+ totalAmount,
167
+ numCredits: plan.credits.amount * numberOfPurchases,
168
+ paymentMethod: PlanTransactionPaymentType.Crypto,
169
+ currency: 'Native',
170
+ tokenAddress: zeroAddress,
171
+ };
172
+ }
173
+ }
174
+ catch (error) {
175
+ this.logger.error(`Error in PaymentsApi order method: ${String(error)}`);
176
+ throw error;
177
+ }
178
+ }
179
+ }
@@ -0,0 +1,23 @@
1
+ import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js';
2
+ import { Api } from '../../services/Api.js';
3
+ import { Profiles } from '../../services/Profiles.js';
4
+ /**
5
+ * Utils internal submodule of Nevermined.
6
+ */
7
+ export declare class ServicesApi extends Instantiable {
8
+ /**
9
+ * Nevermined Node Service
10
+ */
11
+ api: Api;
12
+ /**
13
+ * Profiles instance
14
+ */
15
+ profiles: Profiles;
16
+ /**
17
+ * Creates a new ServicesApi
18
+ * @param config - Configuration of the Nevermined instance
19
+ * @returns {@link ServicesApi}
20
+ */
21
+ constructor(config: InstantiableConfig);
22
+ }
23
+ //# 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,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAErD;;GAEG;AACH,qBAAa,WAAY,SAAQ,YAAY;IAC3C;;OAEG;IACI,GAAG,EAAE,GAAG,CAAA;IAEf;;OAEG;IACI,QAAQ,EAAE,QAAQ,CAAA;IAEzB;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;CAOvC"}
@@ -0,0 +1,27 @@
1
+ import { Instantiable } from '../../Instantiable.abstract.js';
2
+ import { Api } from '../../services/Api.js';
3
+ import { Profiles } from '../../services/Profiles.js';
4
+ /**
5
+ * Utils internal submodule of Nevermined.
6
+ */
7
+ export class ServicesApi extends Instantiable {
8
+ /**
9
+ * Nevermined Node Service
10
+ */
11
+ api;
12
+ /**
13
+ * Profiles instance
14
+ */
15
+ profiles;
16
+ /**
17
+ * Creates a new ServicesApi
18
+ * @param config - Configuration of the Nevermined instance
19
+ * @returns {@link ServicesApi}
20
+ */
21
+ constructor(config) {
22
+ super();
23
+ this.setInstanceConfig(config);
24
+ this.api = new Api(config);
25
+ this.profiles = new Profiles(config);
26
+ }
27
+ }
@@ -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,3 @@
1
+ export { Nevermined } from './Nevermined.js';
2
+ export * from './utils/index.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/nevermined/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,cAAc,kBAAkB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { Nevermined } from './Nevermined.js';
2
+ export * from './utils/index.js';
@@ -0,0 +1,8 @@
1
+ import { ApiEndpoint } from '@nvm-monorepo/commons';
2
+ export declare function isEndpointRequestedIncluded(requestEndpoint: string, requestedHTTPVerb: string, agentEndpoints: ApiEndpoint[], agentOpenEndpoints?: string[]): {
3
+ matches: boolean;
4
+ urlMatching?: URL;
5
+ verbMatching?: string;
6
+ };
7
+ export declare function areUrlsEqualIgnoringQuery(url1: URL, url2: URL): boolean;
8
+ //# sourceMappingURL=AgentUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/AgentUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGnD,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,WAAW,EAAE,EAC7B,kBAAkB,GAAE,MAAM,EAAO,GAChC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,GAAG,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAkDhE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAOvE"}
@@ -0,0 +1,56 @@
1
+ import { match } from 'path-to-regexp';
2
+ export function isEndpointRequestedIncluded(requestEndpoint, requestedHTTPVerb, agentEndpoints, agentOpenEndpoints = []) {
3
+ try {
4
+ let matches = false;
5
+ requestedHTTPVerb = requestedHTTPVerb.toLowerCase();
6
+ let urlMatching, verbMatching;
7
+ const requestedUrl = new URL(requestEndpoint);
8
+ // Is the endpoint an open endpoint?
9
+ for (const openEndpoint of agentOpenEndpoints) {
10
+ try {
11
+ const agentUrl = new URL(openEndpoint);
12
+ if (areUrlsEqualIgnoringQuery(agentUrl, requestedUrl)) {
13
+ urlMatching = new URL(openEndpoint);
14
+ matches = true;
15
+ break;
16
+ }
17
+ }
18
+ catch (error) {
19
+ // Skip invalid URLs and continue with next endpoint
20
+ continue;
21
+ }
22
+ }
23
+ if (matches)
24
+ return { matches: true, urlMatching };
25
+ // check if the endpoint/verb is part of the list
26
+ for (const ep of agentEndpoints) {
27
+ try {
28
+ const [verb, url] = Object.entries(ep)[0];
29
+ const _url = new URL(url);
30
+ const fn = match(_url.pathname, { decode: decodeURIComponent });
31
+ if (fn(requestedUrl.pathname) &&
32
+ (verb.toLowerCase() === requestedHTTPVerb || verb === '*')) {
33
+ matches = true;
34
+ urlMatching = _url;
35
+ verbMatching = verb;
36
+ break;
37
+ }
38
+ }
39
+ catch (error) {
40
+ // Skip invalid patterns and continue with next endpoint
41
+ continue;
42
+ }
43
+ }
44
+ return { matches, urlMatching, verbMatching };
45
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
46
+ }
47
+ catch (error) {
48
+ return { matches: false };
49
+ }
50
+ }
51
+ export function areUrlsEqualIgnoringQuery(url1, url2) {
52
+ return (url1.protocol === url2.protocol &&
53
+ url1.hostname === url2.hostname &&
54
+ url1.port === url2.port &&
55
+ url1.pathname === url2.pathname);
56
+ }
@@ -0,0 +1,280 @@
1
+ import { KernelAccountClient } from '@zerodev/sdk';
2
+ import { Address, type Abi, type AbiEvent, type AbiFunction, type Account, type PublicClient, type TransactionReceipt } from 'viem';
3
+ import { SmartAccount } from 'viem/account-abstraction';
4
+ import { Instantiable, InstantiableConfig, Web3Clients } from '../../Instantiable.abstract.js';
5
+ import { Signer } from '@zerodev/sdk/types';
6
+ /**
7
+ * Utility class with methods that allow the interaction with the blockchain.
8
+ * This class uses Viem library to interact with the blockchain.
9
+ */
10
+ export declare class BlockchainViemUtils extends Instantiable {
11
+ constructor(config: InstantiableConfig);
12
+ }
13
+ /**
14
+ * Given a transaction hash, it returns the transaction receipt.
15
+ * If this function is called before the transaction is mined, it will iterate a few times in order to wait for the transaction to be mined.
16
+ * @param txHash - the transaction hash
17
+ * @param iteration - the iteration number
18
+ * @returns the transaction receipt
19
+ */
20
+ export declare function getTransactionReceipt({ txHash, iteration, publicClient, }: {
21
+ txHash: `0x${string}`;
22
+ iteration?: number;
23
+ publicClient: PublicClient;
24
+ }): Promise<TransactionReceipt>;
25
+ /**
26
+ * Given an already deployed contract address and the ABI, it returns the contract instance.
27
+ *
28
+ * @param contractAddress - the contract address
29
+ * @param abi - the contract artifact
30
+ * @param client - the client to interact with the blockchain
31
+ * @returns a contract instance
32
+ */
33
+ export declare function getContractInstance(contractAddress: string, abi: Abi, client: Web3Clients): Promise<{
34
+ read: {
35
+ [x: string]: (...parameters: [options?: import("viem").Prettify<import("viem").UnionOmit<import("viem").ReadContractParameters<Abi, string, readonly unknown[]>, "address" | "abi" | "args" | "functionName">> | undefined] | [args: readonly unknown[], options?: import("viem").Prettify<import("viem").UnionOmit<import("viem").ReadContractParameters<Abi, string, readonly unknown[]>, "address" | "abi" | "args" | "functionName">> | undefined]) => Promise<import("viem").ReadContractReturnType>;
36
+ };
37
+ estimateGas: {
38
+ [x: string]: (...parameters: [options: import("viem").Prettify<import("viem").UnionOmit<import("viem").EstimateContractGasParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined>, "address" | "abi" | "args" | "functionName">>] | [args: readonly unknown[], options: import("viem").Prettify<import("viem").UnionOmit<import("viem").EstimateContractGasParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined>, "address" | "abi" | "args" | "functionName">>]) => Promise<import("viem").EstimateContractGasReturnType>;
39
+ } & {
40
+ [x: string]: (...parameters: [options: import("viem").Prettify<import("viem").UnionOmit<import("viem").EstimateContractGasParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined>, "address" | "abi" | "args" | "functionName">>] | [args: readonly unknown[], options: import("viem").Prettify<import("viem").UnionOmit<import("viem").EstimateContractGasParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined>, "address" | "abi" | "args" | "functionName">>]) => Promise<import("viem").EstimateContractGasReturnType>;
41
+ };
42
+ simulate: {
43
+ [x: string]: <chainOverride extends import("viem").Chain | undefined = undefined, accountOverride extends Account | Address | undefined = undefined>(...parameters: [options?: Omit<import("viem").SimulateContractParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined, chainOverride, accountOverride>, "address" | "abi" | "args" | "functionName"> | undefined] | [args: readonly unknown[], options?: Omit<import("viem").SimulateContractParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined, chainOverride, accountOverride>, "address" | "abi" | "args" | "functionName"> | undefined]) => Promise<import("viem").SimulateContractReturnType>;
44
+ };
45
+ createEventFilter: {
46
+ [x: string]: <strict extends boolean | undefined = undefined>(...parameters: [options?: ({
47
+ fromBlock?: bigint | import("viem").BlockTag | undefined;
48
+ toBlock?: bigint | import("viem").BlockTag | undefined;
49
+ } & {
50
+ strict?: strict | undefined;
51
+ }) | undefined] | [args: readonly unknown[] | {
52
+ [x: string]: unknown;
53
+ address?: undefined;
54
+ abi?: undefined;
55
+ eventName?: undefined;
56
+ fromBlock?: undefined;
57
+ strict?: undefined;
58
+ toBlock?: undefined;
59
+ args?: undefined;
60
+ }, options?: ({
61
+ fromBlock?: bigint | import("viem").BlockTag | undefined;
62
+ toBlock?: bigint | import("viem").BlockTag | undefined;
63
+ } & {
64
+ strict?: strict | undefined;
65
+ }) | undefined]) => Promise<import("viem").CreateContractEventFilterReturnType>;
66
+ };
67
+ getEvents: {
68
+ [x: string]: (...parameters: [options?: {
69
+ blockHash?: `0x${string}` | undefined;
70
+ strict?: boolean | undefined;
71
+ fromBlock?: bigint | import("viem").BlockTag | undefined;
72
+ toBlock?: bigint | import("viem").BlockTag | undefined;
73
+ } | undefined] | [args?: readonly unknown[] | {
74
+ [x: string]: unknown;
75
+ address?: undefined;
76
+ abi?: undefined;
77
+ args?: undefined;
78
+ eventName?: undefined;
79
+ fromBlock?: undefined;
80
+ onError?: undefined;
81
+ onLogs?: undefined;
82
+ strict?: undefined;
83
+ poll?: undefined;
84
+ batch?: undefined;
85
+ pollingInterval?: undefined;
86
+ } | undefined, options?: {
87
+ blockHash?: `0x${string}` | undefined;
88
+ strict?: boolean | undefined;
89
+ fromBlock?: bigint | import("viem").BlockTag | undefined;
90
+ toBlock?: bigint | import("viem").BlockTag | undefined;
91
+ } | undefined]) => Promise<import("viem").GetContractEventsReturnType<Abi, string>>;
92
+ };
93
+ watchEvent: {
94
+ [x: string]: (...parameters: [options?: {
95
+ batch?: boolean | undefined | undefined;
96
+ pollingInterval?: number | undefined | undefined;
97
+ strict?: boolean | undefined;
98
+ onError?: ((error: Error) => void) | undefined | undefined;
99
+ fromBlock?: bigint | undefined;
100
+ onLogs: import("viem").WatchContractEventOnLogsFn<Abi, string, undefined>;
101
+ poll?: true | undefined | undefined;
102
+ } | undefined] | [args: readonly unknown[] | {
103
+ [x: string]: unknown;
104
+ address?: undefined;
105
+ abi?: undefined;
106
+ args?: undefined;
107
+ eventName?: undefined;
108
+ fromBlock?: undefined;
109
+ onError?: undefined;
110
+ onLogs?: undefined;
111
+ strict?: undefined;
112
+ poll?: undefined;
113
+ batch?: undefined;
114
+ pollingInterval?: undefined;
115
+ }, options?: {
116
+ batch?: boolean | undefined | undefined;
117
+ pollingInterval?: number | undefined | undefined;
118
+ strict?: boolean | undefined;
119
+ onError?: ((error: Error) => void) | undefined | undefined;
120
+ fromBlock?: bigint | undefined;
121
+ onLogs: import("viem").WatchContractEventOnLogsFn<Abi, string, undefined>;
122
+ poll?: true | undefined | undefined;
123
+ } | undefined]) => import("viem").WatchContractEventReturnType;
124
+ };
125
+ write: {
126
+ [x: string]: <chainOverride extends import("viem").Chain | undefined, options extends import("viem").UnionOmit<import("viem").WriteContractParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined, Account | undefined, chainOverride>, "address" | "abi" | "args" | "functionName"> extends infer T ? { [K in keyof T]: T[K]; } : never, Rest extends unknown[] = [options: options]>(...parameters: Rest | [args: readonly unknown[], ...parameters: Rest]) => Promise<import("viem").WriteContractReturnType>;
127
+ };
128
+ address: `0x${string}`;
129
+ abi: Abi;
130
+ }>;
131
+ /**
132
+ * It searchs an ABI function in the ABI.
133
+ * @param abi the ABI of the contract
134
+ * @param funcName the function name
135
+ * @param args the args of the function
136
+ * @returns the function found
137
+ */
138
+ export declare function searchAbiFunction(abi: Abi, funcName: string, args?: any[]): AbiFunction;
139
+ /**
140
+ * It searchs an ABI event in the ABI.
141
+ * @param abi the ABI of the contract
142
+ * @param funcName the event name
143
+ * @returns the event found
144
+ */
145
+ export declare function searchAbiEvent(abi: Abi, eventName: string): AbiEvent;
146
+ /**
147
+ * It searchs an ABI function in the ABI.
148
+ * @param abi the ABI of the contract
149
+ * @param funcName the function name
150
+ * @param args the args of the function
151
+ * @returns the function found
152
+ */
153
+ export declare function getSignatureOfFunction(abi: Abi, funcName: string, args?: any[]): AbiFunction;
154
+ /**
155
+ * It searchs an ABI function in the ABI and return the inputs.
156
+ * @param abi the ABI of the contract
157
+ * @param funcName the function name
158
+ * @param args the args of the function
159
+ * @returns the function found
160
+ */
161
+ export declare function getInputsOfFunction(abi: Abi, funcName: string, args?: any[]): readonly import("viem").AbiParameter[];
162
+ /**
163
+ * It searchs an ABI function in the ABI and return the inputs formatted.
164
+ * @param abi the ABI of the contract
165
+ * @param funcName the function name
166
+ * @param args the args of the function
167
+ * @returns the function found
168
+ */
169
+ export declare function getInputsOfFunctionFormatted(abi: Abi, funcName: string, args?: any[]): {
170
+ name: string | undefined;
171
+ value: any;
172
+ }[];
173
+ /**
174
+ * Given an address it returns that address in checksum format.
175
+ * @param address the address
176
+ * @returns the same address in checksum format
177
+ */
178
+ export declare function getChecksumAddress(address: string): string;
179
+ /**
180
+ * It checks if the address is a valid address.
181
+ * @param address the address to check
182
+ * @returns true of the address is valid
183
+ */
184
+ export declare function isValidAddress(address: string): boolean;
185
+ /**
186
+ * Encodes a UTF-8 string into a byte array.
187
+
188
+ * @param message the string to encode
189
+ * @returns the encoded byte array
190
+ */
191
+ export declare function getBytes(message: string): Uint8Array;
192
+ /**
193
+ * It pads a value with zeros.
194
+ * @param value the value to pad
195
+ * @param length the expected longitutde of the value
196
+ * @returns the padded value
197
+ */
198
+ export declare function zeroPadValue(value: `0x${string}` | Uint8Array, length: number): string;
199
+ /**
200
+ * Encodes a UTF-8 string into a hex string
201
+ * @param message the string to encode
202
+ * @returns the hex string
203
+ */
204
+ export declare function encodeBytes32String(message: string): `0x${string}`;
205
+ /**
206
+ * Given a seedphrase, it returns an account.
207
+ * @param seedphrase - the seedphrase to be used to generate the account
208
+ * @param addressIndex - the address index
209
+ * @returns an account
210
+ */
211
+ export declare function makeWallet(seedphrase: string, addressIndex?: number): Account;
212
+ /**
213
+ * Given a seedphrase generates multiple accounts
214
+ * @param seedphrase - the seedphrase to be used to generate the account
215
+ * @param numAccounts - the number of accounts to create
216
+ * @returns the array of accounts
217
+ */
218
+ export declare function makeWallets(seedphrase: string, numAccounts?: number): Account[];
219
+ /**
220
+ * It generates a random account.
221
+ * @returns a new account
222
+ */
223
+ export declare function makeRandomWallet(): Account;
224
+ /**
225
+ * It generates a list of random accounts
226
+ * @param numAccounts - the number of accounts to create
227
+ * @returns the array of accounts
228
+ */
229
+ export declare function makeRandomWallets(numAccounts?: number): Account[];
230
+ /**
231
+ * It hashes a string using keccak256.
232
+ * @param seed the string to hash
233
+ * @returns the hash
234
+ */
235
+ export declare function keccak256(seed: string): string;
236
+ /**
237
+ * It encodes and hashes a list of primitive values into an ABI-encoded hex value.
238
+ * @param types the types of the values
239
+ * @param values the values to encode
240
+ * @returns the hash
241
+ */
242
+ export declare function keccak256WithEncode(types: any[], values: any[]): string;
243
+ /**
244
+ * It encodes and hashes a list of primitive values into an ABI-encoded hex value.
245
+ * @param types the types of the values
246
+ * @param values the values to encode
247
+ * @returns the hash
248
+ */
249
+ export declare function keccak256Packed(types: any[], values: any[]): string;
250
+ /**
251
+ * It creates a ZeroDev Kernel client.
252
+ * @param signer the signer account
253
+ * @param chainId the chain id
254
+ * @param zeroDevProjectId the zero dev project id, you can get it from the ZeroDev dashboard
255
+ * @returns the kernel client
256
+ */
257
+ export declare function createKernelClient(kernelAccount: SmartAccount, chainId: number, zeroDevProjectId: string, publicClient: any): Promise<KernelAccountClient>;
258
+ export declare function createKernelSmartAccount(signer: Signer, publicClient: PublicClient): Promise<SmartAccount>;
259
+ export declare function getApproval(signer: Signer, publicClient: any, policies: any[]): Promise<string>;
260
+ export declare function useSessionKey(approval: string, signer: Signer, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
261
+ export declare function createSessionKey(signer: Signer, publicClient: any, policies: any[]): Promise<string>;
262
+ export declare function getSessionKey(serializedSessionKey: string, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
263
+ /**
264
+ * Creates a delegated session key for an existing kernel account.
265
+ * The resulting serialized session key can be deserialized into a SmartAccount
266
+ * that shares the same address as the kernel account but enforces the given policies.
267
+ *
268
+ * @param kernelAccount The existing SmartAccount (kernel) to delegate from
269
+ * @param publicClient Viem PublicClient instance
270
+ * @param policies Array of policies to enforce for this session key
271
+ * @returns Serialized session key string
272
+ */
273
+ export declare function createDelegatedSessionKeyFromKernel(kernelAccount: SmartAccount, publicClient: PublicClient, policies: any[]): Promise<string>;
274
+ export declare const WalletUtils: {
275
+ makeWallet: typeof makeWallet;
276
+ makeWallets: typeof makeWallets;
277
+ makeRandomWallet: typeof makeRandomWallet;
278
+ makeRandomWallets: typeof makeRandomWallets;
279
+ };
280
+ //# sourceMappingURL=BlockchainViemUtils.d.ts.map