@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,84 @@
1
+ import { ApiError, HttpError } from '../errors/NeverminedErrors.js';
2
+ import { Api } from './Api.js';
3
+ const profilePath = '/api/v1/metadata/profiles';
4
+ export class Profiles extends Api {
5
+ /**
6
+ * Create user profile
7
+ */
8
+ async create(newProfile, backendAuthToken) {
9
+ const fullUrl = `${this.url}${profilePath}`;
10
+ try {
11
+ const response = await this.nevermined.utils.fetch.post(fullUrl, JSON.stringify(newProfile), {
12
+ Authorization: `Bearer ${backendAuthToken}`,
13
+ });
14
+ if (response.ok) {
15
+ return response.json();
16
+ }
17
+ throw new HttpError(`Create profile fail - ${response.statusText} ${response.url}`, response.status);
18
+ }
19
+ catch (error) {
20
+ throw new ApiError(error instanceof Error ? error.message : String(error));
21
+ }
22
+ }
23
+ /**
24
+ * Update user profile
25
+ */
26
+ async update(userId, profile, backendAuthToken) {
27
+ const fullUrl = `${this.url}${profilePath}/${userId}`;
28
+ try {
29
+ const response = await this.nevermined.utils.fetch.put(fullUrl, JSON.stringify(profile), {
30
+ Authorization: `Bearer ${backendAuthToken}`,
31
+ });
32
+ if (response.ok) {
33
+ return response.json();
34
+ }
35
+ throw new HttpError(`Update profile fail - ${response.statusText} ${response.url}`, response.status);
36
+ }
37
+ catch (error) {
38
+ throw new ApiError(error instanceof Error ? error.message : String(error));
39
+ }
40
+ }
41
+ async findOneByUserId(userId, backendAuthToken) {
42
+ const fullUrl = `${this.url}${profilePath}/${userId}`;
43
+ try {
44
+ const response = await this.nevermined.utils.fetch.get(fullUrl, {
45
+ Authorization: `Bearer ${backendAuthToken}`,
46
+ });
47
+ if (response.ok) {
48
+ return response.json();
49
+ }
50
+ throw new HttpError(`Find profile with userId ${userId} fail - ${response.statusText} ${response.url}`, response.status);
51
+ }
52
+ catch (error) {
53
+ throw new ApiError(error instanceof Error ? error.message : String(error));
54
+ }
55
+ }
56
+ async findOneByAddress(address) {
57
+ const fullUrl = `${this.url}${profilePath}/address/${address}`;
58
+ try {
59
+ const response = await this.nevermined.utils.fetch.get(fullUrl);
60
+ if (response.ok) {
61
+ return response.json();
62
+ }
63
+ throw new HttpError(`Find profile with address ${address} fail - ${response.statusText} ${response.url}`, response.status);
64
+ }
65
+ catch (error) {
66
+ throw new ApiError(error instanceof Error ? error.message : String(error));
67
+ }
68
+ }
69
+ async disableOneByUserId(userId, backendAuthToken) {
70
+ const fullUrl = `${this.url}${profilePath}/${userId}`;
71
+ try {
72
+ const response = await this.nevermined.utils.fetch.delete(fullUrl, undefined, {
73
+ Authorization: `Bearer ${backendAuthToken}`,
74
+ });
75
+ if (response.ok) {
76
+ return response.json();
77
+ }
78
+ throw new HttpError(`Disable profile with userId ${userId} fail - ${response.statusText} ${response.url}`, response.status);
79
+ }
80
+ catch (error) {
81
+ throw new ApiError(error instanceof Error ? error.message : String(error));
82
+ }
83
+ }
84
+ }
@@ -0,0 +1,3 @@
1
+ export * from './Api.js';
2
+ export * from './Profiles.js';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './Api.js';
2
+ export * from './Profiles.js';
@@ -0,0 +1,5 @@
1
+ export declare const zeroX: (input: string) => `0x${string}`;
2
+ export declare const noZeroX: (input: string) => string;
3
+ export declare function zeroXTransformer(input: string | undefined, zeroOutput: boolean): string;
4
+ export declare function toAgentId(input: string | bigint): bigint;
5
+ //# sourceMappingURL=ConversionTypeHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConversionTypeHelpers.d.ts","sourceRoot":"","sources":["../../src/utils/ConversionTypeHelpers.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,GAAI,OAAO,MAAM,KAAsC,KAAK,MAAM,EAAE,CAAA;AACtF,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,WAAmC,CAAA;AAExE,wBAAgB,gBAAgB,CAAC,KAAK,oBAAK,EAAE,UAAU,EAAE,OAAO,UAG/D;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAMxD"}
@@ -0,0 +1,30 @@
1
+ import { LoggerInstance } from '../models/Logger.js';
2
+ // Ox transformer
3
+ export const zeroX = (input) => zeroXTransformer(input, true);
4
+ export const noZeroX = (input) => zeroXTransformer(input, false);
5
+ export function zeroXTransformer(input = '', zeroOutput) {
6
+ const { valid, output } = inputMatch(input, /^(?:0x)*([a-f0-9]+)$/i, 'zeroXTransformer');
7
+ return (zeroOutput && valid ? '0x' : '') + output;
8
+ }
9
+ export function toAgentId(input) {
10
+ if (typeof input === 'bigint') {
11
+ return input;
12
+ }
13
+ else {
14
+ return BigInt(input);
15
+ }
16
+ }
17
+ // Shared functions
18
+ function inputMatch(input, regexp, conversorName) {
19
+ if (typeof input !== 'string') {
20
+ LoggerInstance().debug('Not input string:');
21
+ LoggerInstance().debug(input);
22
+ throw new Error(`[${conversorName}] Expected string, input type: ${typeof input}`);
23
+ }
24
+ const match = input.match(regexp);
25
+ if (!match) {
26
+ LoggerInstance().debug(`[${conversorName}] Input transformation failed for input ${input}.`);
27
+ return { valid: false, output: input };
28
+ }
29
+ return { valid: true, output: match[1] };
30
+ }
@@ -0,0 +1,15 @@
1
+ export interface DeploymentInfo {
2
+ version?: string;
3
+ chainId?: number;
4
+ contracts: Record<string, string>;
5
+ }
6
+ /**
7
+ * Get deployment information from generated artifacts.
8
+ * This includes all contract addresses that are available in the generated.ts file.
9
+ *
10
+ * @param chainId - Optional chain ID to include in the response
11
+ * @param version - Optional version to include in the response
12
+ * @returns Deployment information with contract addresses
13
+ */
14
+ export declare function getDeploymentInfo(chainId?: number, version?: string): DeploymentInfo;
15
+ //# sourceMappingURL=DeploymentInfo.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DeploymentInfo.d.ts","sourceRoot":"","sources":["../../src/utils/DeploymentInfo.ts"],"names":[],"mappings":"AAuBA,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAClC;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,cAAc,CA6BpF"}
@@ -0,0 +1,38 @@
1
+ import { accessManagerAddress, agreementsStoreAddress, assetsRegistryAddress, distributePaymentsConditionAddress, erc2771ForwarderAddress, fiatPaymentTemplateAddress, fiatSettlementConditionAddress, fixedPaymentTemplateAddress, linearPricingAddress, lockPaymentConditionAddress, nft1155CreditsAddress, nft1155ExpirableCreditsAddress, nft1155ExpirableCreditsV2Address, nvmConfigAddress, oneTimeCreatorHookAddress, payAsYouGoTemplateAddress, paymentsVaultAddress, protocolStandardFeesAddress, tokenUtilsAddress, transferCreditsConditionAddress, } from '../artifacts/generated.js';
2
+ /**
3
+ * Get deployment information from generated artifacts.
4
+ * This includes all contract addresses that are available in the generated.ts file.
5
+ *
6
+ * @param chainId - Optional chain ID to include in the response
7
+ * @param version - Optional version to include in the response
8
+ * @returns Deployment information with contract addresses
9
+ */
10
+ export function getDeploymentInfo(chainId, version) {
11
+ const contracts = {
12
+ AccessManager: accessManagerAddress,
13
+ AgreementsStore: agreementsStoreAddress,
14
+ AssetsRegistry: assetsRegistryAddress,
15
+ DistributePaymentsCondition: distributePaymentsConditionAddress,
16
+ ERC2771Forwarder: erc2771ForwarderAddress,
17
+ FiatPaymentTemplate: fiatPaymentTemplateAddress,
18
+ FiatSettlementCondition: fiatSettlementConditionAddress,
19
+ FixedPaymentTemplate: fixedPaymentTemplateAddress,
20
+ LinearPricing: linearPricingAddress,
21
+ LockPaymentCondition: lockPaymentConditionAddress,
22
+ NFT1155Credits: nft1155CreditsAddress,
23
+ NFT1155ExpirableCredits: nft1155ExpirableCreditsAddress,
24
+ NFT1155ExpirableCreditsV2: nft1155ExpirableCreditsV2Address,
25
+ NVMConfig: nvmConfigAddress,
26
+ OneTimeCreatorHook: oneTimeCreatorHookAddress,
27
+ PayAsYouGoTemplate: payAsYouGoTemplateAddress,
28
+ PaymentsVault: paymentsVaultAddress,
29
+ ProtocolStandardFees: protocolStandardFeesAddress,
30
+ TokenUtils: tokenUtilsAddress,
31
+ TransferCreditsCondition: transferCreditsConditionAddress,
32
+ };
33
+ return {
34
+ ...(version && { version }),
35
+ ...(chainId && { chainId }),
36
+ contracts,
37
+ };
38
+ }
@@ -0,0 +1,5 @@
1
+ import { type Chain } from 'viem/chains';
2
+ export declare function getNetworkName(networkId: number): Promise<string>;
3
+ export declare function isTestnet(networkId: number): boolean;
4
+ export declare function getChain(networkId: number | undefined): Chain;
5
+ //# sourceMappingURL=Network.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Network.d.ts","sourceRoot":"","sources":["../../src/utils/Network.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,KAAK,EAeX,MAAM,aAAa,CAAA;AAGpB,wBAAsB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAmEvE;AACD,wBAAgB,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAmEpD;AACD,wBAAgB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,CAoF7D"}
@@ -0,0 +1,224 @@
1
+ import { defineChain } from 'viem';
2
+ import { arbitrum, arbitrumSepolia, aurora, auroraTestnet, base, baseSepolia, celo, celoAlfajores, gnosis, hardhat, mainnet, optimism, polygon, polygonMumbai, } from 'viem/chains';
3
+ import { ContractsError } from '../errors/NeverminedErrors.js';
4
+ export async function getNetworkName(networkId) {
5
+ switch (networkId) {
6
+ case 1:
7
+ return 'mainnet';
8
+ case 2:
9
+ return 'morden';
10
+ case 3:
11
+ return 'ropsten';
12
+ case 4:
13
+ return 'rinkeby';
14
+ case 5:
15
+ return 'goerli';
16
+ case 10:
17
+ return 'optimism';
18
+ case 77:
19
+ return 'poa_sokol';
20
+ case 99:
21
+ return 'poa_core';
22
+ case 42:
23
+ return 'kovan';
24
+ case 100:
25
+ return 'gnosis';
26
+ case 137:
27
+ return 'matic';
28
+ case 1337:
29
+ return 'geth-localnet';
30
+ case 3141:
31
+ return 'hyperspace';
32
+ case 3338:
33
+ return 'peaq-mainnet';
34
+ case 8453:
35
+ return 'base';
36
+ case 84532:
37
+ return 'base-sepolia';
38
+ case 10200:
39
+ return 'chiado'; // Gnosis testnet
40
+ case 31337:
41
+ return 'geth-localnet';
42
+ case 8996:
43
+ return 'spree';
44
+ case 8997:
45
+ return 'polygon-localnet';
46
+ case 8998:
47
+ return 'hardhat';
48
+ case 42220:
49
+ return 'celo';
50
+ case 44787:
51
+ return 'celo-alfajores';
52
+ case 62320:
53
+ return 'celo-baklava';
54
+ case 80001:
55
+ return 'mumbai';
56
+ case 42161:
57
+ return 'arbitrum-one';
58
+ case 421613:
59
+ return 'arbitrum-goerli';
60
+ case 421614:
61
+ return 'arbitrum-sepolia';
62
+ case 1313161554:
63
+ return 'aurora';
64
+ case 1313161555:
65
+ return 'aurora-testnet';
66
+ case 1313161556:
67
+ return 'aurora-betanet';
68
+ default:
69
+ throw new ContractsError(`Network with id ${networkId} not supported.`);
70
+ }
71
+ }
72
+ export function isTestnet(networkId) {
73
+ switch (networkId) {
74
+ case 1:
75
+ return false;
76
+ case 2:
77
+ return true;
78
+ case 3:
79
+ return true;
80
+ case 4:
81
+ return true;
82
+ case 5:
83
+ return true;
84
+ case 10:
85
+ return false;
86
+ case 77:
87
+ return false;
88
+ case 99:
89
+ return false;
90
+ case 42:
91
+ return true;
92
+ case 100:
93
+ return false;
94
+ case 137:
95
+ return false;
96
+ case 1337:
97
+ return true;
98
+ case 3141:
99
+ return true;
100
+ case 3338:
101
+ return false;
102
+ case 8453:
103
+ return false;
104
+ case 84532:
105
+ return true;
106
+ case 10200:
107
+ return true;
108
+ case 31337:
109
+ return true;
110
+ case 8996:
111
+ return true;
112
+ case 8997:
113
+ return true;
114
+ case 8998:
115
+ return true;
116
+ case 42220:
117
+ return false;
118
+ case 44787:
119
+ return true;
120
+ case 62320:
121
+ return true;
122
+ case 80001:
123
+ return true;
124
+ case 42161:
125
+ return false;
126
+ case 421613:
127
+ return true;
128
+ case 421614:
129
+ return true;
130
+ case 1313161554:
131
+ return false;
132
+ case 1313161555:
133
+ return true;
134
+ case 1313161556:
135
+ return true;
136
+ default:
137
+ throw new ContractsError(`Network with id ${networkId} not supported.`);
138
+ }
139
+ }
140
+ export function getChain(networkId) {
141
+ switch (networkId) {
142
+ case 1:
143
+ return mainnet;
144
+ case 10:
145
+ return optimism;
146
+ case 100:
147
+ return gnosis;
148
+ case 137:
149
+ return polygon;
150
+ case 3338:
151
+ return defineChain({
152
+ id: networkId,
153
+ name: 'peaq-network',
154
+ nativeCurrency: {
155
+ name: 'Peaq',
156
+ symbol: 'PEAQ',
157
+ decimals: 18,
158
+ },
159
+ rpcUrls: {
160
+ default: {
161
+ http: ['https://evm.peaq.network'],
162
+ },
163
+ },
164
+ });
165
+ case 8453:
166
+ return base;
167
+ case 84532:
168
+ return baseSepolia;
169
+ case 42161:
170
+ return arbitrum;
171
+ case 42220:
172
+ return celo;
173
+ case 44787:
174
+ return celoAlfajores;
175
+ case 80001:
176
+ return polygonMumbai;
177
+ case 421614:
178
+ return arbitrumSepolia;
179
+ case 1313161554:
180
+ return aurora;
181
+ case 1313161555:
182
+ return auroraTestnet;
183
+ case 8996:
184
+ case 8997:
185
+ case 8998:
186
+ return defineChain({
187
+ id: networkId,
188
+ name: 'Localhost',
189
+ fees: {
190
+ baseFeeMultiplier: 1.2,
191
+ //defaultPriorityFee: parseGwei('0.01'),
192
+ },
193
+ nativeCurrency: {
194
+ name: 'Ether',
195
+ symbol: 'ETH',
196
+ decimals: 18,
197
+ },
198
+ rpcUrls: {
199
+ default: {
200
+ http: [`http://127.0.0.1:${process.env.ETH_PORT || 18545}`],
201
+ },
202
+ },
203
+ });
204
+ case 1337:
205
+ return defineChain({
206
+ id: networkId,
207
+ name: 'geth-localnet',
208
+ nativeCurrency: {
209
+ name: 'Ether',
210
+ symbol: 'ETH',
211
+ decimals: 18,
212
+ },
213
+ rpcUrls: {
214
+ default: {
215
+ http: ['http://contracts.nevermined.localnet'],
216
+ },
217
+ },
218
+ });
219
+ case 31337:
220
+ return hardhat;
221
+ default:
222
+ throw new ContractsError(`Network with id ${networkId} not supported.`);
223
+ }
224
+ }
@@ -0,0 +1,40 @@
1
+ import { SearchQuery } from '@nvm-monorepo/commons';
2
+ import { URL } from 'whatwg-url';
3
+ interface ECIES {
4
+ iv: Buffer;
5
+ ephemPublicKey: Buffer;
6
+ ciphertext: Buffer;
7
+ mac: Buffer;
8
+ }
9
+ export declare const buildQuery: (url: string, query?: SearchQuery) => URL;
10
+ export declare const getCircularReplacer: () => (_key: string, value: unknown) => unknown;
11
+ export declare const jsonReplacer: (_key: string, value: unknown) => unknown;
12
+ export declare function getRandomBigInt(bits?: number): bigint;
13
+ export declare function generateId(length?: number): string;
14
+ export declare function generateZeroXId(): `0x${string}`;
15
+ export declare function _sleep(ms: number): Promise<unknown>;
16
+ /**
17
+ * Wait for balance to be updated after a transaction.
18
+ * Checks the balance immediately first, then polls with delays if needed.
19
+ *
20
+ * @param getBalance - Function that returns the current balance
21
+ * @param expectedMinBalance - Minimum expected balance
22
+ * @param maxRetries - Maximum number of retry attempts (default: 5)
23
+ * @param delayMs - Delay between retries in milliseconds (default: 1000)
24
+ * @returns The updated balance
25
+ * @throws Error if balance doesn't reach expected minimum after all retries
26
+ */
27
+ export declare function waitForBalanceUpdate({ getBalance, expectedMinBalance, maxRetries, delayMs, }: {
28
+ getBalance: () => Promise<bigint>;
29
+ expectedMinBalance: bigint;
30
+ maxRetries?: number;
31
+ delayMs?: number;
32
+ }): Promise<bigint>;
33
+ export declare function urlSafeBase64Encode(input: Uint8Array): string;
34
+ export declare function urlSafeBase64Decode(input: string): Uint8Array;
35
+ export declare function encryptMessage(message: string, receiverPublicKey: string): Promise<string>;
36
+ export declare function serializeECIES(ecies: ECIES): string;
37
+ export declare function deserializeECIES(serialized: string): ECIES;
38
+ export declare function decryptMessage(encryptedMessage: string, privateKey: string | any): Promise<string>;
39
+ export {};
40
+ //# sourceMappingURL=helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAInD,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAIhC,UAAU,KAAK;IACb,EAAE,EAAE,MAAM,CAAA;IACV,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,MAAM,CAAA;IAClB,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,eAAO,MAAM,UAAU,GAAI,KAAK,MAAM,EAAE,QAAQ,WAAW,QAY1D,CAAA;AAED,eAAO,MAAM,mBAAmB,SAEtB,MAAM,MAAM,EAAE,OAAO,OAAO,YASrC,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,MAAM,MAAM,EAAE,OAAO,OAAO,YAGxD,CAAA;AAED,wBAAgB,eAAe,CAAC,IAAI,SAAM,GAAG,MAAM,CAWlD;AAED,wBAAgB,UAAU,CAAC,MAAM,SAAK,UAMrC;AAED,wBAAgB,eAAe,IAAI,KAAK,MAAM,EAAE,CAE/C;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,MAAM,oBAEhC;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,oBAAoB,CAAC,EACzC,UAAU,EACV,kBAAkB,EAClB,UAAc,EACd,OAAc,GACf,EAAE;IACD,UAAU,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,CAAA;IACjC,kBAAkB,EAAE,MAAM,CAAA;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CAsBlB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAO7D;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAY7D;AAED,wBAAsB,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,mBAmB9E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,UAoB1C;AAED,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,KAAK,CAyB1D;AAED,wBAAsB,cAAc,CAAC,gBAAgB,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,GAAG,mBAqBtF"}
@@ -0,0 +1,189 @@
1
+ import { decrypt, encrypt } from 'eciesjs';
2
+ import { v4 } from 'uuid';
3
+ import { keccak256, toBytes } from 'viem';
4
+ import { URL } from 'whatwg-url';
5
+ import { noZeroX } from './ConversionTypeHelpers.js';
6
+ export const buildQuery = (url, query) => {
7
+ const fullUrl = new URL(url);
8
+ if (!query) {
9
+ return fullUrl;
10
+ }
11
+ fullUrl.searchParams.append('sort', decodeURIComponent(JSON.stringify(query.sort)));
12
+ fullUrl.searchParams.append('offset', query.offset?.toString());
13
+ fullUrl.searchParams.append('page', query.page?.toString());
14
+ return fullUrl;
15
+ };
16
+ export const getCircularReplacer = () => {
17
+ const seen = new WeakSet();
18
+ return (_key, value) => {
19
+ if (typeof value === 'object' && value !== null) {
20
+ if (seen.has(value)) {
21
+ return;
22
+ }
23
+ seen.add(value);
24
+ }
25
+ return value;
26
+ };
27
+ };
28
+ export const jsonReplacer = (_key, value) => {
29
+ // Modify the value or return undefined to exclude the property
30
+ return typeof value === 'bigint' ? value.toString() : value;
31
+ };
32
+ export function getRandomBigInt(bits = 128) {
33
+ const bytes = Math.ceil(bits / 8);
34
+ const array = new Uint8Array(bytes);
35
+ crypto.getRandomValues(array);
36
+ let result = 0n;
37
+ for (const byte of array) {
38
+ result = (result << 8n) | BigInt(byte);
39
+ }
40
+ return result;
41
+ }
42
+ export function generateId(length = 64) {
43
+ let id = '';
44
+ while (id.length < length) {
45
+ id += v4().replace(/-/g, '');
46
+ }
47
+ return id.slice(0, length);
48
+ }
49
+ export function generateZeroXId() {
50
+ return keccak256(toBytes(Math.random().toString()));
51
+ }
52
+ export function _sleep(ms) {
53
+ return new Promise((resolve) => setTimeout(resolve, ms));
54
+ }
55
+ /**
56
+ * Wait for balance to be updated after a transaction.
57
+ * Checks the balance immediately first, then polls with delays if needed.
58
+ *
59
+ * @param getBalance - Function that returns the current balance
60
+ * @param expectedMinBalance - Minimum expected balance
61
+ * @param maxRetries - Maximum number of retry attempts (default: 5)
62
+ * @param delayMs - Delay between retries in milliseconds (default: 1000)
63
+ * @returns The updated balance
64
+ * @throws Error if balance doesn't reach expected minimum after all retries
65
+ */
66
+ export async function waitForBalanceUpdate({ getBalance, expectedMinBalance, maxRetries = 5, delayMs = 1000, }) {
67
+ // Check immediately first (no delay)
68
+ let currentBalance = await getBalance();
69
+ if (currentBalance >= expectedMinBalance) {
70
+ return currentBalance;
71
+ }
72
+ // If not satisfied, start polling with delays
73
+ for (let i = 0; i < maxRetries; i++) {
74
+ await _sleep(delayMs);
75
+ currentBalance = await getBalance();
76
+ if (currentBalance >= expectedMinBalance) {
77
+ return currentBalance;
78
+ }
79
+ }
80
+ // Failed to reach expected balance
81
+ throw new Error(`Balance did not reach expected minimum after ${maxRetries} retries. Expected at least ${expectedMinBalance}, got ${currentBalance}`);
82
+ }
83
+ export function urlSafeBase64Encode(input) {
84
+ let binary = '';
85
+ const len = input.byteLength;
86
+ for (let i = 0; i < len; i++) {
87
+ binary += String.fromCharCode(input[i]);
88
+ }
89
+ return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
90
+ }
91
+ export function urlSafeBase64Decode(input) {
92
+ input = input.replace(/-/g, '+').replace(/_/g, '/');
93
+ while (input.length % 4) {
94
+ input += '=';
95
+ }
96
+ const binary = atob(input);
97
+ const len = binary.length;
98
+ const bytes = new Uint8Array(len);
99
+ for (let i = 0; i < len; i++) {
100
+ bytes[i] = binary.charCodeAt(i);
101
+ }
102
+ return bytes;
103
+ }
104
+ export async function encryptMessage(message, receiverPublicKey) {
105
+ const publicKeyBuffer = Buffer.from(noZeroX(receiverPublicKey), 'hex');
106
+ const messageBuffer = Buffer.from(message);
107
+ try {
108
+ const ecies = await encrypt(publicKeyBuffer, messageBuffer);
109
+ // Handle both cases: when encrypt returns a Buffer or an ECIES object
110
+ if (Buffer.isBuffer(ecies)) {
111
+ // If it returns a Buffer, we need to handle it differently
112
+ // This might be the case with some versions of eciesjs
113
+ return ecies.toString('base64');
114
+ }
115
+ else {
116
+ // If it returns an ECIES object, serialize it
117
+ return serializeECIES(ecies);
118
+ }
119
+ }
120
+ catch (error) {
121
+ throw new Error(`Encryption failed: ${error}`);
122
+ }
123
+ }
124
+ export function serializeECIES(ecies) {
125
+ // Validate that all required properties exist
126
+ if (!ecies || typeof ecies !== 'object') {
127
+ throw new Error('Invalid ECIES object: must be a valid object');
128
+ }
129
+ const requiredProps = ['iv', 'ephemPublicKey', 'ciphertext', 'mac'];
130
+ for (const prop of requiredProps) {
131
+ if (!ecies[prop]) {
132
+ throw new Error(`Invalid ECIES object: missing required property '${prop}'`);
133
+ }
134
+ }
135
+ const serialized = JSON.stringify({
136
+ iv: Buffer.from(ecies.iv).toString('base64'),
137
+ ephemPublicKey: Buffer.from(ecies.ephemPublicKey).toString('base64'),
138
+ ciphertext: Buffer.from(ecies.ciphertext).toString('base64'),
139
+ mac: Buffer.from(ecies.mac).toString('base64'),
140
+ });
141
+ return serialized;
142
+ }
143
+ export function deserializeECIES(serialized) {
144
+ if (!serialized || typeof serialized !== 'string') {
145
+ throw new Error('Invalid serialized ECIES: must be a valid string');
146
+ }
147
+ let _obj;
148
+ try {
149
+ _obj = JSON.parse(serialized);
150
+ }
151
+ catch (error) {
152
+ throw new Error('Invalid serialized ECIES: not a valid JSON string');
153
+ }
154
+ const requiredProps = ['iv', 'ephemPublicKey', 'ciphertext', 'mac'];
155
+ for (const prop of requiredProps) {
156
+ if (!_obj[prop]) {
157
+ throw new Error(`Invalid serialized ECIES: missing required property '${prop}'`);
158
+ }
159
+ }
160
+ return {
161
+ iv: Buffer.from(_obj.iv, 'base64'),
162
+ ephemPublicKey: Buffer.from(_obj.ephemPublicKey, 'base64'),
163
+ ciphertext: Buffer.from(_obj.ciphertext, 'base64'),
164
+ mac: Buffer.from(_obj.mac, 'base64'),
165
+ };
166
+ }
167
+ export async function decryptMessage(encryptedMessage, privateKey) {
168
+ const pk = typeof privateKey === 'string' ? noZeroX(privateKey) : privateKey;
169
+ const privateKeyBuffer = Buffer.from(pk, 'hex');
170
+ // Try to parse as JSON first (ECIES object)
171
+ try {
172
+ const ecies = deserializeECIES(encryptedMessage);
173
+ // For eciesjs, we need to serialize the ECIES object back to a buffer
174
+ const eciesBuffer = Buffer.concat([ecies.iv, ecies.ephemPublicKey, ecies.ciphertext, ecies.mac]);
175
+ const decrypted = await decrypt(privateKeyBuffer, eciesBuffer);
176
+ return decrypted.toString();
177
+ }
178
+ catch (error) {
179
+ // If JSON parsing fails, try as base64 Buffer
180
+ try {
181
+ const encryptedBuffer = Buffer.from(encryptedMessage, 'base64');
182
+ const decrypted = await decrypt(privateKeyBuffer, encryptedBuffer);
183
+ return decrypted.toString();
184
+ }
185
+ catch (secondError) {
186
+ throw new Error(`Failed to decrypt message: ${secondError}`);
187
+ }
188
+ }
189
+ }
@@ -0,0 +1,5 @@
1
+ export * from './ConversionTypeHelpers.js';
2
+ export * from './DeploymentInfo.js';
3
+ export * from './helpers.js';
4
+ export * from './Network.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,qBAAqB,CAAA;AACnC,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA"}