@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.
Files changed (137) hide show
  1. package/README.md +15 -0
  2. package/dist/Instantiable.abstract.d.ts +35 -0
  3. package/dist/Instantiable.abstract.d.ts.map +1 -0
  4. package/dist/Instantiable.abstract.js +102 -0
  5. package/dist/artifacts/generated.d.ts +29912 -0
  6. package/dist/artifacts/generated.d.ts.map +1 -0
  7. package/dist/artifacts/generated.js +16797 -0
  8. package/dist/contracts/AccessManager.d.ts +17 -0
  9. package/dist/contracts/AccessManager.d.ts.map +1 -0
  10. package/dist/contracts/AccessManager.js +15 -0
  11. package/dist/contracts/AssetRegistry.d.ts +65 -0
  12. package/dist/contracts/AssetRegistry.d.ts.map +1 -0
  13. package/dist/contracts/AssetRegistry.js +103 -0
  14. package/dist/contracts/ContractBase.d.ts +21 -0
  15. package/dist/contracts/ContractBase.d.ts.map +1 -0
  16. package/dist/contracts/ContractBase.js +270 -0
  17. package/dist/contracts/ContractsApi.d.ts +62 -0
  18. package/dist/contracts/ContractsApi.d.ts.map +1 -0
  19. package/dist/contracts/ContractsApi.js +66 -0
  20. package/dist/contracts/FiatPaymentTemplate.d.ts +10 -0
  21. package/dist/contracts/FiatPaymentTemplate.d.ts.map +1 -0
  22. package/dist/contracts/FiatPaymentTemplate.js +14 -0
  23. package/dist/contracts/FiatSettlementCondition.d.ts +11 -0
  24. package/dist/contracts/FiatSettlementCondition.d.ts.map +1 -0
  25. package/dist/contracts/FiatSettlementCondition.js +18 -0
  26. package/dist/contracts/FixedPaymentTemplate.d.ts +10 -0
  27. package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -0
  28. package/dist/contracts/FixedPaymentTemplate.js +14 -0
  29. package/dist/contracts/NFT1155Base.d.ts +41 -0
  30. package/dist/contracts/NFT1155Base.d.ts.map +1 -0
  31. package/dist/contracts/NFT1155Base.js +21 -0
  32. package/dist/contracts/NFT1155Credits.d.ts +6 -0
  33. package/dist/contracts/NFT1155Credits.d.ts.map +1 -0
  34. package/dist/contracts/NFT1155Credits.js +9 -0
  35. package/dist/contracts/NFT1155ExpirableCredits.d.ts +34 -0
  36. package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +1 -0
  37. package/dist/contracts/NFT1155ExpirableCredits.js +18 -0
  38. package/dist/contracts/NVMConfig.d.ts +10 -0
  39. package/dist/contracts/NVMConfig.d.ts.map +1 -0
  40. package/dist/contracts/NVMConfig.js +18 -0
  41. package/dist/contracts/ProtocolStandardFees.d.ts +9 -0
  42. package/dist/contracts/ProtocolStandardFees.d.ts.map +1 -0
  43. package/dist/contracts/ProtocolStandardFees.js +15 -0
  44. package/dist/contracts/Roles.d.ts +13 -0
  45. package/dist/contracts/Roles.d.ts.map +1 -0
  46. package/dist/contracts/Roles.js +12 -0
  47. package/dist/contracts/index.d.ts +3 -0
  48. package/dist/contracts/index.d.ts.map +1 -0
  49. package/dist/contracts/index.js +2 -0
  50. package/dist/errors/NeverminedErrors.d.ts +71 -0
  51. package/dist/errors/NeverminedErrors.d.ts.map +1 -0
  52. package/dist/errors/NeverminedErrors.js +123 -0
  53. package/dist/errors/index.d.ts +2 -0
  54. package/dist/errors/index.d.ts.map +1 -0
  55. package/dist/errors/index.js +1 -0
  56. package/dist/index.d.ts +8 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +11 -0
  59. package/dist/models/Logger.d.ts +9 -0
  60. package/dist/models/Logger.d.ts.map +1 -0
  61. package/dist/models/Logger.js +27 -0
  62. package/dist/models/NeverminedOptions.d.ts +55 -0
  63. package/dist/models/NeverminedOptions.d.ts.map +1 -0
  64. package/dist/models/NeverminedOptions.js +58 -0
  65. package/dist/models/NvmApiKey.d.ts +137 -0
  66. package/dist/models/NvmApiKey.d.ts.map +1 -0
  67. package/dist/models/NvmApiKey.js +234 -0
  68. package/dist/models/Transactions.d.ts +11 -0
  69. package/dist/models/Transactions.d.ts.map +1 -0
  70. package/dist/models/Transactions.js +1 -0
  71. package/dist/models/index.d.ts +5 -0
  72. package/dist/models/index.d.ts.map +1 -0
  73. package/dist/models/index.js +4 -0
  74. package/dist/nevermined/DID.d.ts +45 -0
  75. package/dist/nevermined/DID.d.ts.map +1 -0
  76. package/dist/nevermined/DID.js +90 -0
  77. package/dist/nevermined/Nevermined.d.ts +48 -0
  78. package/dist/nevermined/Nevermined.d.ts.map +1 -0
  79. package/dist/nevermined/Nevermined.js +72 -0
  80. package/dist/nevermined/api/PaymentsApi.d.ts +17 -0
  81. package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -0
  82. package/dist/nevermined/api/PaymentsApi.js +125 -0
  83. package/dist/nevermined/api/ServicesApi.d.ts +28 -0
  84. package/dist/nevermined/api/ServicesApi.d.ts.map +1 -0
  85. package/dist/nevermined/api/ServicesApi.js +33 -0
  86. package/dist/nevermined/api/UtilsApi.d.ts +28 -0
  87. package/dist/nevermined/api/UtilsApi.d.ts.map +1 -0
  88. package/dist/nevermined/api/UtilsApi.js +33 -0
  89. package/dist/nevermined/index.d.ts +4 -0
  90. package/dist/nevermined/index.d.ts.map +1 -0
  91. package/dist/nevermined/index.js +3 -0
  92. package/dist/nevermined/utils/BlockchainViemUtils.d.ts +276 -0
  93. package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -0
  94. package/dist/nevermined/utils/BlockchainViemUtils.js +376 -0
  95. package/dist/nevermined/utils/JwtUtils.d.ts +27 -0
  96. package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -0
  97. package/dist/nevermined/utils/JwtUtils.js +154 -0
  98. package/dist/nevermined/utils/SignatureUtils.d.ts +14 -0
  99. package/dist/nevermined/utils/SignatureUtils.d.ts.map +1 -0
  100. package/dist/nevermined/utils/SignatureUtils.js +99 -0
  101. package/dist/nevermined/utils/WebServiceConnector.d.ts +32 -0
  102. package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -0
  103. package/dist/nevermined/utils/WebServiceConnector.js +191 -0
  104. package/dist/nevermined/utils/ZeroDevPolicies.d.ts +19 -0
  105. package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -0
  106. package/dist/nevermined/utils/ZeroDevPolicies.js +78 -0
  107. package/dist/nevermined/utils/index.d.ts +6 -0
  108. package/dist/nevermined/utils/index.d.ts.map +1 -0
  109. package/dist/nevermined/utils/index.js +5 -0
  110. package/dist/services/Api.d.ts +7 -0
  111. package/dist/services/Api.d.ts.map +1 -0
  112. package/dist/services/Api.js +25 -0
  113. package/dist/services/MarketplaceAPI.d.ts +7 -0
  114. package/dist/services/MarketplaceAPI.d.ts.map +1 -0
  115. package/dist/services/MarketplaceAPI.js +25 -0
  116. package/dist/services/MetadataService.d.ts +90 -0
  117. package/dist/services/MetadataService.d.ts.map +1 -0
  118. package/dist/services/MetadataService.js +277 -0
  119. package/dist/services/Profiles.d.ts +16 -0
  120. package/dist/services/Profiles.d.ts.map +1 -0
  121. package/dist/services/Profiles.js +84 -0
  122. package/dist/services/index.d.ts +4 -0
  123. package/dist/services/index.d.ts.map +1 -0
  124. package/dist/services/index.js +3 -0
  125. package/dist/utils/ConversionTypeHelpers.d.ts +8 -0
  126. package/dist/utils/ConversionTypeHelpers.d.ts.map +1 -0
  127. package/dist/utils/ConversionTypeHelpers.js +31 -0
  128. package/dist/utils/Network.d.ts +5 -0
  129. package/dist/utils/Network.d.ts.map +1 -0
  130. package/dist/utils/Network.js +224 -0
  131. package/dist/utils/helpers.d.ts +21 -0
  132. package/dist/utils/helpers.d.ts.map +1 -0
  133. package/dist/utils/helpers.js +109 -0
  134. package/dist/utils/index.d.ts +4 -0
  135. package/dist/utils/index.d.ts.map +1 -0
  136. package/dist/utils/index.js +3 -0
  137. package/package.json +27 -0
@@ -0,0 +1,276 @@
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
+ strict?: boolean | undefined;
70
+ blockHash?: `0x${string}` | 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
+ strict?: boolean | undefined;
88
+ blockHash?: `0x${string}` | 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]: import("viem").UnionOmit<import("viem").WriteContractParameters<Abi, string, readonly unknown[], import("viem").Chain | undefined, Account | undefined, chainOverride>, "address" | "abi" | "args" | "functionName">[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
+ * It converts a DID to a Token ID.
175
+ * This is useful because in the Solidity Smart contracts the tokenId is a uint256.
176
+ * @param did the unique identifier of the asset
177
+ * @returns the token id in a bigint format
178
+ */
179
+ export declare function didToTokenId(did: string): bigint;
180
+ /**
181
+ * Given an address it returns that address in checksum format.
182
+ * @param address the address
183
+ * @returns the same address in checksum format
184
+ */
185
+ export declare function getChecksumAddress(address: string): string;
186
+ /**
187
+ * It checks if the address is a valid address.
188
+ * @param address the address to check
189
+ * @returns true of the address is valid
190
+ */
191
+ export declare function isValidAddress(address: string): boolean;
192
+ /**
193
+ * Encodes a UTF-8 string into a byte array.
194
+
195
+ * @param message the string to encode
196
+ * @returns the encoded byte array
197
+ */
198
+ export declare function getBytes(message: string): Uint8Array;
199
+ /**
200
+ * It pads a value with zeros.
201
+ * @param value the value to pad
202
+ * @param length the expected longitutde of the value
203
+ * @returns the padded value
204
+ */
205
+ export declare function zeroPadValue(value: `0x${string}` | Uint8Array, length: number): string;
206
+ /**
207
+ * Encodes a UTF-8 string into a hex string
208
+ * @param message the string to encode
209
+ * @returns the hex string
210
+ */
211
+ export declare function encodeBytes32String(message: string): `0x${string}`;
212
+ /**
213
+ * Given a seedphrase, it returns an account.
214
+ * @param seedphrase - the seedphrase to be used to generate the account
215
+ * @param addressIndex - the address index
216
+ * @returns an account
217
+ */
218
+ export declare function makeWallet(seedphrase: string, addressIndex?: number): Account;
219
+ /**
220
+ * Given a seedphrase generates multiple accounts
221
+ * @param seedphrase - the seedphrase to be used to generate the account
222
+ * @param numAccounts - the number of accounts to create
223
+ * @returns the array of accounts
224
+ */
225
+ export declare function makeWallets(seedphrase: string, numAccounts?: number): Account[];
226
+ /**
227
+ * It generates a random account.
228
+ * @returns a new account
229
+ */
230
+ export declare function makeRandomWallet(): Account;
231
+ /**
232
+ * It generates a list of random accounts
233
+ * @param numAccounts - the number of accounts to create
234
+ * @returns the array of accounts
235
+ */
236
+ export declare function makeRandomWallets(numAccounts?: number): Account[];
237
+ /**
238
+ * It hashes a string using keccak256.
239
+ * @param seed the string to hash
240
+ * @returns the hash
241
+ */
242
+ export declare function keccak256(seed: string): 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 keccak256WithEncode(types: any[], values: any[]): string;
250
+ /**
251
+ * It encodes and hashes a list of primitive values into an ABI-encoded hex value.
252
+ * @param types the types of the values
253
+ * @param values the values to encode
254
+ * @returns the hash
255
+ */
256
+ export declare function keccak256Packed(types: any[], values: any[]): string;
257
+ /**
258
+ * It creates a ZeroDev Kernel client.
259
+ * @param signer the signer account
260
+ * @param chainId the chain id
261
+ * @param zeroDevProjectId the zero dev project id, you can get it from the ZeroDev dashboard
262
+ * @returns the kernel client
263
+ */
264
+ export declare function createKernelClient(kernelAccount: SmartAccount, chainId: number, zeroDevProjectId: string, publicClient: any): Promise<KernelAccountClient>;
265
+ export declare function createKernelSmartAccount(signer: Signer, publicClient: PublicClient): Promise<SmartAccount>;
266
+ export declare function getApproval(signer: Signer, publicClient: any, policies: any[]): Promise<string>;
267
+ export declare function useSessionKey(approval: string, signer: Signer, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
268
+ export declare function createSessionKey(signer: Signer, publicClient: any, policies: any[]): Promise<string>;
269
+ export declare function getSessionKey(serializedSessionKey: string, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
270
+ export declare const WalletUtils: {
271
+ makeWallet: typeof makeWallet;
272
+ makeWallets: typeof makeWallets;
273
+ makeRandomWallet: typeof makeRandomWallet;
274
+ makeRandomWallets: typeof makeRandomWallets;
275
+ };
276
+ //# sourceMappingURL=BlockchainViemUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version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AK,GAAG,OAAO,EAAE,CAG7D;AAID;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAGvE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,MAAM,CAEnE;AAID;;;;;;GAMG;AACH,wBAAsB,kBAAkB,CACtC,aAAa,EAAE,YAAY,EAC3B,OAAO,EAAE,MAAM,EACf,gBAAgB,EAAE,MAAM,EACxB,YAAY,EAAE,GAAG,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAyB9B;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,YAAY,CAAC,CAcvB;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,mBAyBnF;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,wEAatF;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,mBA6BxF;AAED,wBAAsB,aAAa,CAAC,oBAAoB,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,wEASlF;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAA"}
@@ -0,0 +1,376 @@
1
+ import { signerToEcdsaValidator } from '@zerodev/ecdsa-validator';
2
+ import { deserializePermissionAccount, serializePermissionAccount, toPermissionValidator, } from '@zerodev/permissions';
3
+ import { toECDSASigner } from '@zerodev/permissions/signers';
4
+ import { addressToEmptyAccount, createKernelAccount, createKernelAccountClient, createZeroDevPaymasterClient, getUserOperationGasPrice, } from '@zerodev/sdk';
5
+ import { KERNEL_V3_1, getEntryPoint } from '@zerodev/sdk/constants';
6
+ import { TransactionReceiptNotFoundError, encodeAbiParameters, getAbiItem, getAddress, getContract, hexToBigInt, http, isAddress, pad, stringToBytes, stringToHex, toBytes, keccak256 as viemKeccak256, } from 'viem';
7
+ import { english, generateMnemonic, generatePrivateKey, mnemonicToAccount, privateKeyToAccount, } from 'viem/accounts';
8
+ import { Instantiable } from '../../Instantiable.abstract.js';
9
+ import { ContractsError } from '../../errors/NeverminedErrors.js';
10
+ import { didZeroX } from '../../utils/ConversionTypeHelpers.js';
11
+ import { getChain } from '../../utils/Network.js';
12
+ import { _sleep } from '../../utils/helpers.js';
13
+ const ENTRY_POINT_VERSION = '0.7';
14
+ /**
15
+ * Utility class with methods that allow the interaction with the blockchain.
16
+ * This class uses Viem library to interact with the blockchain.
17
+ */
18
+ export class BlockchainViemUtils extends Instantiable {
19
+ constructor(config) {
20
+ super();
21
+ this.setInstanceConfig(config);
22
+ }
23
+ }
24
+ //////////////////////////
25
+ ///// UTILITIES //////////
26
+ //////////////////////////
27
+ ///// CONTRACTS
28
+ /**
29
+ * Given a transaction hash, it returns the transaction receipt.
30
+ * 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.
31
+ * @param txHash - the transaction hash
32
+ * @param iteration - the iteration number
33
+ * @returns the transaction receipt
34
+ */
35
+ export async function getTransactionReceipt({ txHash, iteration = 1, publicClient, }) {
36
+ if (iteration < 10) {
37
+ try {
38
+ return await publicClient.getTransactionReceipt({ hash: txHash });
39
+ }
40
+ catch (error) {
41
+ if (error instanceof TransactionReceiptNotFoundError) {
42
+ // this.logger.log(
43
+ // `Unable to get transaction receipt from hash ${txHash} on iteration ${iteration}. Sleeping and retrying.`,
44
+ // )
45
+ await _sleep(150);
46
+ return getTransactionReceipt({ txHash, iteration: iteration++, publicClient });
47
+ }
48
+ else {
49
+ const errorMessage = `Unknown error getting transaction receipt with hash: ${txHash}. Error: ${error}`;
50
+ // this.logger.error(errorMessage)
51
+ throw new ContractsError(errorMessage);
52
+ }
53
+ }
54
+ }
55
+ else {
56
+ const errorMessage = `Unable to get transaction receipt with hash: ${txHash} after ${iteration} iterations.`;
57
+ // this.logger.error(errorMessage)
58
+ throw new ContractsError(errorMessage);
59
+ }
60
+ }
61
+ /**
62
+ * Given an already deployed contract address and the ABI, it returns the contract instance.
63
+ *
64
+ * @param contractAddress - the contract address
65
+ * @param abi - the contract artifact
66
+ * @param client - the client to interact with the blockchain
67
+ * @returns a contract instance
68
+ */
69
+ export async function getContractInstance(contractAddress, abi, client) {
70
+ return getContract({
71
+ abi,
72
+ address: contractAddress,
73
+ client: { wallet: client.wallet, public: client.public },
74
+ });
75
+ }
76
+ ///// ABIs
77
+ /**
78
+ * It searchs an ABI function in the ABI.
79
+ * @param abi the ABI of the contract
80
+ * @param funcName the function name
81
+ * @param args the args of the function
82
+ * @returns the function found
83
+ */
84
+ export function searchAbiFunction(abi, funcName, args = []) {
85
+ const func = getAbiItem({ abi, name: funcName, args });
86
+ if (!func || func.type !== 'function') {
87
+ throw new ContractsError(`Function "${funcName}" is not part of contract`);
88
+ }
89
+ return func;
90
+ }
91
+ /**
92
+ * It searchs an ABI event in the ABI.
93
+ * @param abi the ABI of the contract
94
+ * @param funcName the event name
95
+ * @returns the event found
96
+ */
97
+ export function searchAbiEvent(abi, eventName) {
98
+ const event = getAbiItem({
99
+ abi,
100
+ name: eventName,
101
+ });
102
+ if (!event || event.type !== 'event') {
103
+ throw new ContractsError(`Event "${event}" is not part of contract`);
104
+ }
105
+ return event;
106
+ }
107
+ /**
108
+ * It searchs an ABI function in the ABI.
109
+ * @param abi the ABI of the contract
110
+ * @param funcName the function name
111
+ * @param args the args of the function
112
+ * @returns the function found
113
+ */
114
+ export function getSignatureOfFunction(abi, funcName, args = []) {
115
+ return searchAbiFunction(abi, funcName, args);
116
+ }
117
+ /**
118
+ * It searchs an ABI function in the ABI and return the inputs.
119
+ * @param abi the ABI of the contract
120
+ * @param funcName the function name
121
+ * @param args the args of the function
122
+ * @returns the function found
123
+ */
124
+ export function getInputsOfFunction(abi, funcName, args = []) {
125
+ return searchAbiFunction(abi, funcName, args).inputs;
126
+ }
127
+ /**
128
+ * It searchs an ABI function in the ABI and return the inputs formatted.
129
+ * @param abi the ABI of the contract
130
+ * @param funcName the function name
131
+ * @param args the args of the function
132
+ * @returns the function found
133
+ */
134
+ export function getInputsOfFunctionFormatted(abi, funcName, args = []) {
135
+ return searchAbiFunction(abi, funcName, args).inputs.map((input, i) => {
136
+ return {
137
+ name: input.name,
138
+ value: args[i],
139
+ };
140
+ });
141
+ }
142
+ //////// UTILS
143
+ /**
144
+ * It converts a DID to a Token ID.
145
+ * This is useful because in the Solidity Smart contracts the tokenId is a uint256.
146
+ * @param did the unique identifier of the asset
147
+ * @returns the token id in a bigint format
148
+ */
149
+ export function didToTokenId(did) {
150
+ return hexToBigInt(didZeroX(did), { size: 32 });
151
+ }
152
+ /**
153
+ * Given an address it returns that address in checksum format.
154
+ * @param address the address
155
+ * @returns the same address in checksum format
156
+ */
157
+ export function getChecksumAddress(address) {
158
+ return getAddress(address);
159
+ }
160
+ /**
161
+ * It checks if the address is a valid address.
162
+ * @param address the address to check
163
+ * @returns true of the address is valid
164
+ */
165
+ export function isValidAddress(address) {
166
+ return isAddress(address);
167
+ }
168
+ /**
169
+ * Encodes a UTF-8 string into a byte array.
170
+
171
+ * @param message the string to encode
172
+ * @returns the encoded byte array
173
+ */
174
+ export function getBytes(message) {
175
+ return stringToBytes(message);
176
+ }
177
+ /**
178
+ * It pads a value with zeros.
179
+ * @param value the value to pad
180
+ * @param length the expected longitutde of the value
181
+ * @returns the padded value
182
+ */
183
+ export function zeroPadValue(value, length) {
184
+ return pad(value, { size: length });
185
+ }
186
+ /**
187
+ * Encodes a UTF-8 string into a hex string
188
+ * @param message the string to encode
189
+ * @returns the hex string
190
+ */
191
+ export function encodeBytes32String(message) {
192
+ return stringToHex(message, { size: 32 });
193
+ }
194
+ ////// ACCOUNTS
195
+ /**
196
+ * Given a seedphrase, it returns an account.
197
+ * @param seedphrase - the seedphrase to be used to generate the account
198
+ * @param addressIndex - the address index
199
+ * @returns an account
200
+ */
201
+ export function makeWallet(seedphrase, addressIndex = 0) {
202
+ return mnemonicToAccount(seedphrase, { addressIndex });
203
+ }
204
+ /**
205
+ * Given a seedphrase generates multiple accounts
206
+ * @param seedphrase - the seedphrase to be used to generate the account
207
+ * @param numAccounts - the number of accounts to create
208
+ * @returns the array of accounts
209
+ */
210
+ export function makeWallets(seedphrase, numAccounts = 10) {
211
+ const accounts = [];
212
+ for (let i = 0; i < numAccounts; i++) {
213
+ accounts.push(makeWallet(seedphrase, i));
214
+ }
215
+ return accounts;
216
+ }
217
+ /**
218
+ * It generates a random account.
219
+ * @returns a new account
220
+ */
221
+ export function makeRandomWallet() {
222
+ const mnemonic = generateMnemonic(english);
223
+ return makeWallet(mnemonic);
224
+ }
225
+ /**
226
+ * It generates a list of random accounts
227
+ * @param numAccounts - the number of accounts to create
228
+ * @returns the array of accounts
229
+ */
230
+ export function makeRandomWallets(numAccounts = 10) {
231
+ const mnemonic = generateMnemonic(english);
232
+ return makeWallets(mnemonic, numAccounts);
233
+ }
234
+ /////// HASHES
235
+ /**
236
+ * It hashes a string using keccak256.
237
+ * @param seed the string to hash
238
+ * @returns the hash
239
+ */
240
+ export function keccak256(seed) {
241
+ return viemKeccak256(toBytes(seed));
242
+ }
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 function keccak256WithEncode(types, values) {
250
+ const encoded = encodeAbiParameters(types, values);
251
+ return keccak256(encoded);
252
+ }
253
+ /**
254
+ * It encodes and hashes a list of primitive values into an ABI-encoded hex value.
255
+ * @param types the types of the values
256
+ * @param values the values to encode
257
+ * @returns the hash
258
+ */
259
+ export function keccak256Packed(types, values) {
260
+ return keccak256WithEncode(types, values);
261
+ }
262
+ /////// ZERO DEV
263
+ /**
264
+ * It creates a ZeroDev Kernel client.
265
+ * @param signer the signer account
266
+ * @param chainId the chain id
267
+ * @param zeroDevProjectId the zero dev project id, you can get it from the ZeroDev dashboard
268
+ * @returns the kernel client
269
+ */
270
+ export async function createKernelClient(kernelAccount, chainId, zeroDevProjectId, publicClient) {
271
+ const ZERODEV_RPC = `https://rpc.zerodev.app/api/v3/${zeroDevProjectId}/chain/${chainId}`;
272
+ return createKernelAccountClient({
273
+ account: kernelAccount,
274
+ chain: getChain(chainId),
275
+ bundlerTransport: http(ZERODEV_RPC),
276
+ client: publicClient,
277
+ paymaster: {
278
+ getPaymasterData: (userOperation) => {
279
+ const zerodevPaymaster = createZeroDevPaymasterClient({
280
+ chain: getChain(chainId),
281
+ transport: http(ZERODEV_RPC),
282
+ });
283
+ return zerodevPaymaster.sponsorUserOperation({
284
+ userOperation,
285
+ });
286
+ },
287
+ },
288
+ userOperation: {
289
+ estimateFeesPerGas: async ({ bundlerClient }) => {
290
+ return getUserOperationGasPrice(bundlerClient);
291
+ },
292
+ },
293
+ });
294
+ }
295
+ export async function createKernelSmartAccount(signer, publicClient) {
296
+ const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
297
+ signer: signer,
298
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
299
+ kernelVersion: KERNEL_V3_1,
300
+ });
301
+ return await createKernelAccount(publicClient, {
302
+ plugins: {
303
+ sudo: ecdsaValidator,
304
+ },
305
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
306
+ kernelVersion: KERNEL_V3_1,
307
+ });
308
+ }
309
+ export async function getApproval(signer, publicClient, policies) {
310
+ const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
311
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
312
+ signer,
313
+ kernelVersion: KERNEL_V3_1,
314
+ });
315
+ const emptyAccount = addressToEmptyAccount(signer.address);
316
+ const emptySessionKeySigner = await toECDSASigner({ signer: emptyAccount });
317
+ const permissionPlugin = await toPermissionValidator(publicClient, {
318
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
319
+ signer: emptySessionKeySigner,
320
+ policies: policies,
321
+ kernelVersion: KERNEL_V3_1,
322
+ });
323
+ const sessionKeyAccount = await createKernelAccount(publicClient, {
324
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
325
+ plugins: {
326
+ sudo: ecdsaValidator,
327
+ regular: permissionPlugin,
328
+ },
329
+ kernelVersion: KERNEL_V3_1,
330
+ });
331
+ return await serializePermissionAccount(sessionKeyAccount);
332
+ }
333
+ export async function useSessionKey(approval, signer, publicClient) {
334
+ const sessionKeySigner = await toECDSASigner({
335
+ signer,
336
+ });
337
+ const sessionKeyAccount = await deserializePermissionAccount(publicClient, getEntryPoint(ENTRY_POINT_VERSION), KERNEL_V3_1, approval, sessionKeySigner);
338
+ return sessionKeyAccount;
339
+ }
340
+ export async function createSessionKey(signer, publicClient, policies) {
341
+ const ecdsaValidator = await signerToEcdsaValidator(publicClient, {
342
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
343
+ signer,
344
+ kernelVersion: KERNEL_V3_1,
345
+ });
346
+ const sessionPrivateKey = generatePrivateKey();
347
+ const masterAccount = privateKeyToAccount(sessionPrivateKey);
348
+ const sessionKeySigner = await toECDSASigner({
349
+ signer: masterAccount,
350
+ });
351
+ const permissionPlugin = await toPermissionValidator(publicClient, {
352
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
353
+ signer: sessionKeySigner,
354
+ policies: policies,
355
+ kernelVersion: KERNEL_V3_1,
356
+ });
357
+ const sessionKeyAccount = await createKernelAccount(publicClient, {
358
+ entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
359
+ plugins: {
360
+ sudo: ecdsaValidator,
361
+ regular: permissionPlugin,
362
+ },
363
+ kernelVersion: KERNEL_V3_1,
364
+ });
365
+ return serializePermissionAccount(sessionKeyAccount, sessionPrivateKey);
366
+ }
367
+ export async function getSessionKey(serializedSessionKey, publicClient) {
368
+ const sessionKeyAccount = await deserializePermissionAccount(publicClient, getEntryPoint(ENTRY_POINT_VERSION), KERNEL_V3_1, serializedSessionKey);
369
+ return sessionKeyAccount;
370
+ }
371
+ export const WalletUtils = {
372
+ makeWallet,
373
+ makeWallets,
374
+ makeRandomWallet,
375
+ makeRandomWallets,
376
+ };
@@ -0,0 +1,27 @@
1
+ import type { Eip712Data } from '@nvm-monorepo/commons';
2
+ import { type JWSHeaderParameters, SignJWT } from 'jose';
3
+ import { type Account } from 'viem';
4
+ import { SmartAccount } from 'viem/account-abstraction';
5
+ import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract.js';
6
+ import { SignatureUtils } from './SignatureUtils.js';
7
+ export declare class EthSignJWT extends SignJWT {
8
+ protectedHeader: JWSHeaderParameters | undefined;
9
+ setProtectedHeader(protectedHeader: JWSHeaderParameters): this;
10
+ ethSign(signatureUtils: SignatureUtils, account: Account | SmartAccount, eip712Data?: Eip712Data): Promise<string>;
11
+ static signText(text: string | Uint8Array, account: Account): Promise<string | undefined>;
12
+ private base64url;
13
+ private concat;
14
+ }
15
+ export declare class JwtUtils extends Instantiable {
16
+ static CLIENT_ASSERTION_TYPE: string;
17
+ tokenCache: Map<string, string>;
18
+ signatureUtils: SignatureUtils;
19
+ constructor(config: InstantiableConfig);
20
+ generateCacheKey(...args: string[]): string;
21
+ accountToJwk(account: Account | SmartAccount): Promise<any>;
22
+ generateClientAssertion(account: Account | SmartAccount, message?: string): Promise<string>;
23
+ isTokenValid(token: string): boolean;
24
+ static createCompressedJwt(token: string): string;
25
+ static decompressJwt(compressedJwt: string): string;
26
+ }
27
+ //# sourceMappingURL=JwtUtils.d.ts.map