@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,99 @@
1
+ import { recoverMessageAddress, toHex } from 'viem';
2
+ import { Instantiable } from '../../Instantiable.abstract.js';
3
+ import { NvmAccountError } from '../../errors/NeverminedErrors.js';
4
+ import { keccak256 } from './BlockchainViemUtils.js';
5
+ export class SignatureUtils extends Instantiable {
6
+ constructor(config) {
7
+ super();
8
+ this.setInstanceConfig(config);
9
+ }
10
+ async signText(text, account) {
11
+ const message = typeof text === 'string' ? text : toHex(text);
12
+ if (account.type === 'smart') {
13
+ const result = await account.signMessage({ message });
14
+ return result;
15
+ }
16
+ else if (account.type === 'local') {
17
+ return account.signMessage({
18
+ message: message,
19
+ });
20
+ }
21
+ else if (account.type === 'json-rpc') {
22
+ const message = typeof text === 'string' ? text : toHex(text);
23
+ return await this.walletClient.signMessage({
24
+ account: account.address,
25
+ message: message,
26
+ });
27
+ }
28
+ else {
29
+ throw new NvmAccountError('The account type is not supported for signing');
30
+ }
31
+ }
32
+ async signTypedData(domain, types, value, account) {
33
+ if (account.type === 'smart') {
34
+ const signature = await account.signTypedData({
35
+ domain,
36
+ types: types,
37
+ message: value,
38
+ primaryType: 'Nevermined',
39
+ });
40
+ return signature;
41
+ }
42
+ else if (account.type === 'local') {
43
+ return await account.signTypedData({
44
+ domain,
45
+ types: types,
46
+ message: value,
47
+ primaryType: 'Nevermined',
48
+ });
49
+ }
50
+ else if (account.type === 'json-rpc') {
51
+ return await this.walletClient.signTypedData({
52
+ domain,
53
+ types: types,
54
+ message: value,
55
+ primaryType: 'Nevermined',
56
+ account: account.address,
57
+ });
58
+ }
59
+ else {
60
+ throw new NvmAccountError('The account type is not supported for typed signing');
61
+ }
62
+ }
63
+ async signTransaction(tx, account) {
64
+ // if (account.type === 'smart') {
65
+ // return await account?.signTransaction({ data: tx })
66
+ // }
67
+ if (account.type === 'local') {
68
+ return account.signTransaction({
69
+ data: tx,
70
+ });
71
+ }
72
+ else if (account.type === 'json-rpc') {
73
+ return await this.walletClient.signTransaction({
74
+ data: tx,
75
+ account: account.address,
76
+ chain: this.client.chain,
77
+ });
78
+ }
79
+ else {
80
+ throw new NvmAccountError('The account type is not supported for signing');
81
+ }
82
+ }
83
+ async verifyIsSigner(text, signature, signerAddress) {
84
+ return this.client.public.verifyMessage({
85
+ message: text,
86
+ signature: signature,
87
+ address: signerAddress,
88
+ });
89
+ }
90
+ static async recoverSignerAddress(message, signature) {
91
+ return recoverMessageAddress({
92
+ message,
93
+ signature: signature,
94
+ });
95
+ }
96
+ static hash(seed) {
97
+ return keccak256(seed).replace(/^0x([a-f0-9]{64})(:!.+)?$/i, '0x$1');
98
+ }
99
+ }
@@ -0,0 +1,30 @@
1
+ import { BodyInit, Response } from 'node-fetch';
2
+ import { ReadStream } from 'fs';
3
+ import { URL } from 'whatwg-url';
4
+ import { InstantiableConfig } from '../../Instantiable.abstract.js';
5
+ /**
6
+ * Provides a common interface to web services.
7
+ */
8
+ export declare class WebServiceConnector {
9
+ config: InstantiableConfig;
10
+ constructor(config: InstantiableConfig);
11
+ post(url: string, payload: BodyInit, headers?: {
12
+ [header: string]: string;
13
+ }): Promise<Response>;
14
+ get(url: string | URL, headers?: {
15
+ [header: string]: string;
16
+ }): Promise<Response>;
17
+ put(url: string, payload: BodyInit, headers?: {
18
+ [header: string]: string;
19
+ }): Promise<Response>;
20
+ delete(url: string, payload?: BodyInit, headers?: {
21
+ [header: string]: string;
22
+ }): Promise<Response>;
23
+ downloadUrl(url: string, headers?: any): Promise<string>;
24
+ uploadMessage(url: string, data: string, encrypt?: boolean): Promise<any>;
25
+ uploadFile(url: string, data: ReadStream, encrypt?: boolean): Promise<any>;
26
+ fetchToken(url: string, grantToken: string, sessionKey?: string, numberTries?: number, apiKeyHash?: string): Promise<Response>;
27
+ private fetch;
28
+ private _sleep;
29
+ }
30
+ //# sourceMappingURL=WebServiceConnector.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"WebServiceConnector.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/WebServiceConnector.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,QAAQ,EAAe,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAA;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAgBnE;;GAEG;AACH,qBAAa,mBAAmB;IAG9B,MAAM,EAAE,kBAAkB,CAAA;gBAEd,MAAM,EAAE,kBAAkB;IAM/B,IAAI,CACT,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,QAAQ,EACjB,OAAO,GAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,GACzC,OAAO,CAAC,QAAQ,CAAC;IAWb,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,EAAE,OAAO,GAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IASrF,GAAG,CACR,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,QAAQ,EACjB,OAAO,GAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,GACzC,OAAO,CAAC,QAAQ,CAAC;IAWb,MAAM,CACX,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,QAAQ,EAClB,OAAO,GAAE;QAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAA;KAAO,GACzC,OAAO,CAAC,QAAQ,CAAC;IAgEP,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC;IAQxD,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IASzE,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,GAAG,CAAC;IAS1E,UAAU,CACrB,GAAG,EAAE,MAAM,EACX,UAAU,EAAE,MAAM,EAClB,UAAU,CAAC,EAAE,MAAM,EACnB,WAAW,SAAI,EACf,UAAU,CAAC,EAAE,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;YA2BN,KAAK;IAiBnB,OAAO,CAAC,MAAM;CAGf"}
@@ -0,0 +1,170 @@
1
+ import FormData from 'form-data';
2
+ import { HttpError } from '../../errors/NeverminedErrors.js';
3
+ import { JwtUtils } from '../../nevermined/utils/JwtUtils.js';
4
+ let fetch;
5
+ async function initializeFetch() {
6
+ if (typeof window !== 'undefined') {
7
+ fetch = window.fetch.bind(window);
8
+ }
9
+ else {
10
+ const nodeFetch = await import('node-fetch');
11
+ fetch = nodeFetch.default;
12
+ }
13
+ return fetch;
14
+ }
15
+ fetch = initializeFetch();
16
+ /**
17
+ * Provides a common interface to web services.
18
+ */
19
+ export class WebServiceConnector {
20
+ // extends Instantiable {
21
+ config;
22
+ constructor(config) {
23
+ // super()
24
+ // this.setInstanceConfig(config)
25
+ this.config = config;
26
+ }
27
+ post(url, payload, headers = {}) {
28
+ return this.fetch(url, {
29
+ method: 'POST',
30
+ body: payload,
31
+ headers: {
32
+ 'Content-type': 'application/json',
33
+ ...headers,
34
+ },
35
+ });
36
+ }
37
+ get(url, headers = {}) {
38
+ return this.fetch(url, {
39
+ method: 'GET',
40
+ headers: {
41
+ ...headers,
42
+ },
43
+ });
44
+ }
45
+ put(url, payload, headers = {}) {
46
+ return this.fetch(url, {
47
+ method: 'PUT',
48
+ body: payload,
49
+ headers: {
50
+ 'Content-type': 'application/json',
51
+ ...headers,
52
+ },
53
+ });
54
+ }
55
+ delete(url, payload, headers = {}) {
56
+ return this.fetch(url, {
57
+ method: 'DELETE',
58
+ body: payload,
59
+ headers: {
60
+ 'Content-type': 'application/json',
61
+ ...headers,
62
+ },
63
+ });
64
+ }
65
+ // public async downloadFile(
66
+ // url: string,
67
+ // destination?: string,
68
+ // index?: number,
69
+ // headers?: { [key: string]: string },
70
+ // ): Promise<string> {
71
+ // const { response, name } = await this.getFileResponse(url, index, headers)
72
+ // if (destination) {
73
+ // await new Promise((resolve, reject) => {
74
+ // // @ts-ignore
75
+ // fs.mkdirSync(destination, { recursive: true })
76
+ // const fileStream = fs.createWriteStream(`${destination}${name}`)
77
+ // response.body.pipe(fileStream)
78
+ // response.body.on('error', reject)
79
+ // fileStream.on('finish', resolve)
80
+ // fileStream.on('close', resolve)
81
+ // })
82
+ // } else {
83
+ // const buff = await response.arrayBuffer()
84
+ // fileDownload(buff, name)
85
+ // destination = process.cwd()
86
+ // }
87
+ // const d = path.join(destination, name)
88
+ // return d
89
+ // }
90
+ // private async getFileResponse(
91
+ // url: string,
92
+ // index?: number,
93
+ // headers?: { [key: string]: string },
94
+ // ): Promise<{ response: Response; name: string }> {
95
+ // const response = await this.get(url, headers)
96
+ // if (!response.ok) {
97
+ // throw new Error('Response error.')
98
+ // }
99
+ // let name: string
100
+ // try {
101
+ // // @ts-ignore
102
+ // ;[, name] = response.headers.get('content-disposition').match(/attachment;filename=(.+)/)
103
+ // } catch {
104
+ // try {
105
+ // // @ts-ignore
106
+ // name = url.split('/').pop()
107
+ // } catch {
108
+ // name = `file${index}`
109
+ // }
110
+ // }
111
+ // return { response, name }
112
+ // }
113
+ async downloadUrl(url, headers) {
114
+ const response = await this.get(url, headers);
115
+ if (!response.ok) {
116
+ throw new Error('Response error.');
117
+ }
118
+ return await response.text();
119
+ }
120
+ async uploadMessage(url, data, encrypt) {
121
+ const form = new FormData();
122
+ form.append('message', data);
123
+ if (encrypt) {
124
+ form.append('encrypt', 'true');
125
+ }
126
+ return this.fetch(url, { method: 'POST', body: form });
127
+ }
128
+ async uploadFile(url, data, encrypt) {
129
+ const form = new FormData();
130
+ form.append('file', data);
131
+ if (encrypt) {
132
+ form.append('encrypt', 'true');
133
+ }
134
+ return this.fetch(url, { method: 'POST', body: form });
135
+ }
136
+ async fetchToken(url, grantToken, sessionKey, numberTries = 1, apiKeyHash) {
137
+ const bodyParams = new URLSearchParams({
138
+ client_assertion_type: JwtUtils.CLIENT_ASSERTION_TYPE,
139
+ client_assertion: grantToken,
140
+ });
141
+ if (sessionKey) {
142
+ bodyParams.append('sessionKey', sessionKey);
143
+ }
144
+ if (apiKeyHash) {
145
+ bodyParams.append('nvm_key_hash', apiKeyHash);
146
+ }
147
+ return await fetch(url, {
148
+ method: 'POST',
149
+ body: bodyParams.toString(),
150
+ headers: {
151
+ 'Content-type': 'application/x-www-form-urlencoded',
152
+ },
153
+ }, numberTries);
154
+ }
155
+ async fetch(url, opts, numberTries = 1) {
156
+ let counterTries = 1;
157
+ let result;
158
+ while (counterTries <= numberTries) {
159
+ result = await fetch(url, opts);
160
+ if (result.ok)
161
+ return result;
162
+ counterTries++;
163
+ await this._sleep(500);
164
+ }
165
+ throw new HttpError(`Request ${opts.method} ${url} fail - ${await result.clone().text()}`, result.status);
166
+ }
167
+ _sleep(ms) {
168
+ return new Promise((resolve) => setTimeout(resolve, ms));
169
+ }
170
+ }
@@ -0,0 +1,38 @@
1
+ import { Abi } from 'viem';
2
+ import { Policy } from '@zerodev/permissions';
3
+ export declare function getPolicy(permissions: any[]): Policy;
4
+ export declare function getPermissions(config: any, functionNames: string[]): any[];
5
+ export declare function getERC20ApprovePermissions(contractAddress: `0x${string}`): {
6
+ target: `0x${string}`;
7
+ abi: Abi;
8
+ functionName: string;
9
+ };
10
+ export declare const getERC20ApprovePolicy: (contractAddress: `0x${string}`) => Policy;
11
+ export declare const getAgentRegistrationPolicy: () => Policy;
12
+ export declare const getPricingPlanRegistrationPolicy: () => Policy;
13
+ export declare const getRegisterAssetsPolicy: () => Policy;
14
+ export declare const getOrderPolicy: () => Policy;
15
+ export declare const getMintNFTPolicy: () => Policy;
16
+ export declare const getBurnNFTPolicy: () => Policy;
17
+ export declare const getRegisterPolicy: () => Policy;
18
+ export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) => Policy;
19
+ export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) => Policy;
20
+ export type BurnPolicyOptions = {
21
+ contractAddress: `0x${string}`;
22
+ planId: bigint;
23
+ subscriberAddress: `0x${string}`;
24
+ maxAmount: bigint;
25
+ count?: number;
26
+ };
27
+ export declare const getZeroDevBurnPolicies: (burnPolicyOptions: BurnPolicyOptions) => Policy[];
28
+ export type OrderPolicyOptions = {
29
+ contractAddress: `0x${string}`;
30
+ planId: bigint;
31
+ subscriberAddress: `0x${string}`;
32
+ numberOfPurchases: bigint;
33
+ totalAmount: bigint;
34
+ count?: number;
35
+ erc20ContractAddress?: `0x${string}`;
36
+ };
37
+ export declare const getZeroDevOrderPolicies: (orderPolicyOptions: OrderPolicyOptions) => Policy[];
38
+ //# sourceMappingURL=ZeroDevPolicies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,GAAG,EAAoC,MAAM,MAAM,CAAA;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAgB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,UAK3C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,SAelE;AAED,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,KAAK,MAAM,EAAE;;SAK/D,GAAG;;EAGZ;AACD,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WACV,CAAA;AAE1D,eAAO,MAAM,0BAA0B,cACwB,CAAA;AAE/D,eAAO,MAAM,gCAAgC,cAC2C,CAAA;AAExF,eAAO,MAAM,uBAAuB,cACuC,CAAA;AAE3E,eAAO,MAAM,cAAc,cAM1B,CAAA;AAED,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,iBAAiB,cAU3B,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,EAAE,iBAAiB,KAAK,MAAM,EAAE,WAoBhF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WAgBjE,CAAA;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,KAAK,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,mBAAmB,iBAAiB,KAAG,MAAM,EAkCnF,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,KAAK,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,iBAAiB,EAAE,MAAM,CAAA;IACzB,WAAW,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oBAAoB,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;CACrC,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,oBAAoB,kBAAkB,KAAG,MAAM,EA8EtF,CAAA"}
@@ -0,0 +1,196 @@
1
+ import { CallPolicyVersion, ParamCondition, toCallPolicy, toRateLimitPolicy, } from '@zerodev/permissions/policies';
2
+ import { assetsRegistryConfig, fixedPaymentTemplateConfig, nft1155CreditsConfig, payAsYouGoTemplateAddress, payAsYouGoTemplateConfig, } from '../../artifacts/generated.js';
3
+ import { isAddress, parseAbi, zeroAddress } from 'viem';
4
+ export function getPolicy(permissions) {
5
+ return toCallPolicy({
6
+ policyVersion: CallPolicyVersion.V0_0_4,
7
+ permissions,
8
+ });
9
+ }
10
+ export function getPermissions(config, functionNames) {
11
+ const permissions = [];
12
+ functionNames.forEach((functionName) => {
13
+ const abis = config.abi.filter((item) => item.type === 'function' && item.name === functionName);
14
+ abis.forEach((abi) => {
15
+ permissions.push({
16
+ target: config.address,
17
+ abi: [abi],
18
+ functionName,
19
+ });
20
+ });
21
+ });
22
+ return permissions;
23
+ }
24
+ export function getERC20ApprovePermissions(contractAddress) {
25
+ return {
26
+ target: contractAddress,
27
+ abi: parseAbi([
28
+ 'function approve(address spender, uint256 amount) external returns (bool)',
29
+ ]),
30
+ functionName: 'approve',
31
+ };
32
+ }
33
+ export const getERC20ApprovePolicy = (contractAddress) => getPolicy([getERC20ApprovePermissions(contractAddress)]);
34
+ export const getAgentRegistrationPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['register']));
35
+ export const getPricingPlanRegistrationPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['createPlan', 'createPlanWithHooks']));
36
+ export const getRegisterAssetsPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['registerAgentAndPlan']));
37
+ export const getOrderPolicy = () => {
38
+ const perms = [
39
+ ...getPermissions(fixedPaymentTemplateConfig, ['order']),
40
+ ...getPermissions(payAsYouGoTemplateAddress, ['order']),
41
+ ];
42
+ return getPolicy(perms);
43
+ };
44
+ export const getMintNFTPolicy = () => getPolicy(getPermissions(nft1155CreditsConfig, ['mint']));
45
+ export const getBurnNFTPolicy = () => getPolicy(getPermissions(nft1155CreditsConfig, ['burn']));
46
+ export const getRegisterPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, [
47
+ 'register',
48
+ 'createPlan',
49
+ 'createPlanWithHooks',
50
+ 'registerAgentAndPlan',
51
+ 'addPlanToAgent',
52
+ 'removePlanFromAgent',
53
+ ]));
54
+ export const buildPolicy = (permissions, contractAddress) => {
55
+ const perms = [
56
+ ...(permissions.includes('register')
57
+ ? getPermissions(assetsRegistryConfig, [
58
+ 'register',
59
+ 'createPlan',
60
+ 'createPlanWithHooks',
61
+ 'registerAgentAndPlan',
62
+ 'addPlanToAgent',
63
+ 'removePlanFromAgent',
64
+ ])
65
+ : []),
66
+ ...(permissions.includes('mint') ? getPermissions(nft1155CreditsConfig, ['mint']) : []),
67
+ ...(permissions.includes('burn') ? getPermissions(nft1155CreditsConfig, ['burn']) : []),
68
+ ...(permissions.includes('order') ? getPermissions(fixedPaymentTemplateConfig, ['order']) : []),
69
+ ...(permissions.includes('order') ? getPermissions(payAsYouGoTemplateConfig, ['order']) : []),
70
+ ...(permissions.includes('order') ? [getERC20ApprovePermissions(contractAddress)] : []),
71
+ ];
72
+ return getPolicy(perms);
73
+ };
74
+ export const getAllContractsPolicy = (contractAddress) => getPolicy([
75
+ ...getPermissions(assetsRegistryConfig, [
76
+ 'register',
77
+ 'createPlan',
78
+ 'createPlanWithHooks',
79
+ 'registerAgentAndPlan',
80
+ 'addPlanToAgent',
81
+ 'removePlanFromAgent',
82
+ ]),
83
+ ...getPermissions(fixedPaymentTemplateConfig, ['order']),
84
+ ...getPermissions(payAsYouGoTemplateConfig, ['order']),
85
+ ...getPermissions(nft1155CreditsConfig, ['mint', 'burn']),
86
+ getERC20ApprovePermissions(contractAddress),
87
+ ].filter(Boolean));
88
+ export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
89
+ const policies = [];
90
+ const burnPolicy = {
91
+ target: burnPolicyOptions.contractAddress,
92
+ abi: parseAbi([
93
+ 'function burn(address _from, uint256 _planId, uint256 _value, uint256 _keyspace, bytes calldata _signature) external',
94
+ ]),
95
+ valueLimit: 0n,
96
+ functionName: 'burn',
97
+ args: [
98
+ {
99
+ condition: ParamCondition.EQUAL,
100
+ value: burnPolicyOptions.subscriberAddress,
101
+ },
102
+ {
103
+ condition: ParamCondition.EQUAL,
104
+ value: '0x' + burnPolicyOptions.planId.toString(16).padStart(64, '0'),
105
+ },
106
+ {
107
+ condition: ParamCondition.LESS_THAN_OR_EQUAL,
108
+ value: burnPolicyOptions.maxAmount,
109
+ },
110
+ ],
111
+ };
112
+ policies.push(getPolicy([burnPolicy]));
113
+ if (burnPolicyOptions.count) {
114
+ const rateLimitPolicy = toRateLimitPolicy({
115
+ count: burnPolicyOptions.count,
116
+ });
117
+ policies.push(rateLimitPolicy);
118
+ }
119
+ return policies;
120
+ };
121
+ export const getZeroDevOrderPolicies = (orderPolicyOptions) => {
122
+ const policies = [];
123
+ let abi;
124
+ let args;
125
+ if (orderPolicyOptions.contractAddress === payAsYouGoTemplateAddress) {
126
+ abi = parseAbi([
127
+ 'function order(bytes32 _seed, uint256 _planId, bytes[] memory _params) external payable',
128
+ ]);
129
+ args = [
130
+ null,
131
+ {
132
+ condition: ParamCondition.EQUAL,
133
+ value: '0x' + orderPolicyOptions.planId.toString(16).padStart(64, '0'),
134
+ },
135
+ ];
136
+ }
137
+ else {
138
+ abi = parseAbi([
139
+ 'function order(bytes32 _seed, uint256 _planId, address _creditsReceiver, uint256 _numberOfPurchases, bytes[] memory _params) external payable',
140
+ ]);
141
+ args = [
142
+ null,
143
+ {
144
+ condition: ParamCondition.EQUAL,
145
+ value: '0x' + orderPolicyOptions.planId.toString(16).padStart(64, '0'),
146
+ },
147
+ {
148
+ condition: ParamCondition.EQUAL,
149
+ value: orderPolicyOptions.subscriberAddress,
150
+ },
151
+ {
152
+ condition: ParamCondition.EQUAL,
153
+ value: orderPolicyOptions.numberOfPurchases,
154
+ },
155
+ ];
156
+ }
157
+ const orderCallPolicy = {
158
+ target: orderPolicyOptions.contractAddress,
159
+ abi,
160
+ valueLimit: 0n,
161
+ functionName: 'order',
162
+ args,
163
+ };
164
+ if (orderPolicyOptions.erc20ContractAddress &&
165
+ isAddress(orderPolicyOptions.erc20ContractAddress)) {
166
+ const approvePolicy = {
167
+ target: orderPolicyOptions.erc20ContractAddress,
168
+ abi: parseAbi([
169
+ 'function approve(address spender, uint256 amount) external returns (bool)',
170
+ ]),
171
+ valueLimit: 0n,
172
+ functionName: 'approve',
173
+ args: [
174
+ {
175
+ condition: ParamCondition.NOT_EQUAL,
176
+ value: zeroAddress,
177
+ },
178
+ {
179
+ condition: ParamCondition.LESS_THAN_OR_EQUAL,
180
+ value: orderPolicyOptions.totalAmount,
181
+ },
182
+ ],
183
+ };
184
+ policies.push(getPolicy([orderCallPolicy, approvePolicy]));
185
+ }
186
+ else {
187
+ policies.push(getPolicy([orderCallPolicy]));
188
+ }
189
+ if (orderPolicyOptions.count) {
190
+ const rateLimitPolicy = toRateLimitPolicy({
191
+ count: orderPolicyOptions.count,
192
+ });
193
+ policies.push(rateLimitPolicy);
194
+ }
195
+ return policies;
196
+ };
@@ -0,0 +1,7 @@
1
+ export * from './BlockchainViemUtils.js';
2
+ export * from './JwtUtils.js';
3
+ export * from './SignatureUtils.js';
4
+ export * from './WebServiceConnector.js';
5
+ export * from './ZeroDevPolicies.js';
6
+ export * from './AgentUtils.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,0BAA0B,CAAA;AACxC,cAAc,eAAe,CAAA;AAC7B,cAAc,qBAAqB,CAAA;AACnC,cAAc,0BAA0B,CAAA;AACxC,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA"}
@@ -0,0 +1,6 @@
1
+ export * from './BlockchainViemUtils.js';
2
+ export * from './JwtUtils.js';
3
+ export * from './SignatureUtils.js';
4
+ export * from './WebServiceConnector.js';
5
+ export * from './ZeroDevPolicies.js';
6
+ export * from './AgentUtils.js';
@@ -0,0 +1,7 @@
1
+ import { Instantiable, InstantiableConfig } from '../Instantiable.abstract.js';
2
+ export declare class Api extends Instantiable {
3
+ constructor(config: InstantiableConfig);
4
+ protected get url(): string | undefined;
5
+ validateAssertion(clientAssertion: string, sessionKey?: string): Promise<string>;
6
+ }
7
+ //# sourceMappingURL=Api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Api.d.ts","sourceRoot":"","sources":["../../src/services/Api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAK9E,qBAAa,GAAI,SAAQ,YAAY;gBACvB,MAAM,EAAE,kBAAkB;IAKtC,SAAS,KAAK,GAAG,uBAEhB;IAEY,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAmB9F"}
@@ -0,0 +1,25 @@
1
+ import { Instantiable } from '../Instantiable.abstract.js';
2
+ import { ApiError, HttpError } from '../errors/NeverminedErrors.js';
3
+ const authPath = '/api/v1/api-keys';
4
+ export class Api extends Instantiable {
5
+ constructor(config) {
6
+ super();
7
+ this.setInstanceConfig(config);
8
+ }
9
+ get url() {
10
+ return this.config.backendUrl;
11
+ }
12
+ async validateAssertion(clientAssertion, sessionKey) {
13
+ try {
14
+ const response = await this.nevermined.utils.fetch.fetchToken(`${this.url}${authPath}/validate-assertion`, clientAssertion, sessionKey);
15
+ if (!response.ok) {
16
+ throw new HttpError(`Error Login - ${response.statusText} ${response.url}`, response.status);
17
+ }
18
+ const backendAuthToken = (await response.json()).hash;
19
+ return backendAuthToken;
20
+ }
21
+ catch (error) {
22
+ throw new ApiError(error instanceof Error ? error.message : String(error));
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,16 @@
1
+ import { NewProfile, Profile, ReducedProfile } from '@nvm-monorepo/commons';
2
+ import { Api } from './Api.js';
3
+ export declare class Profiles extends Api {
4
+ /**
5
+ * Create user profile
6
+ */
7
+ create(newProfile: NewProfile, backendAuthToken: string): Promise<Profile>;
8
+ /**
9
+ * Update user profile
10
+ */
11
+ update(userId: string, profile: Partial<NewProfile>, backendAuthToken: string): Promise<Profile>;
12
+ findOneByUserId(userId: string, backendAuthToken: string): Promise<Profile>;
13
+ findOneByAddress(address: string): Promise<ReducedProfile>;
14
+ disableOneByUserId(userId: string, backendAuthToken: string): Promise<Profile>;
15
+ }
16
+ //# sourceMappingURL=Profiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Profiles.d.ts","sourceRoot":"","sources":["../../src/services/Profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAE3E,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAA;AAI9B,qBAAa,QAAS,SAAQ,GAAG;IAC/B;;OAEG;IACU,MAAM,CAAC,UAAU,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoBvF;;OAEG;IACU,MAAM,CACjB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,EAC5B,gBAAgB,EAAE,MAAM,GACvB,OAAO,CAAC,OAAO,CAAC;IAqBN,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAqB3E,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAmB1D,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAoB5F"}