@nevermined-io/core-kit 0.0.2-rc22 → 0.0.2-rc25

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 (40) hide show
  1. package/dist/artifacts/generated.d.ts +166 -32
  2. package/dist/artifacts/generated.d.ts.map +1 -1
  3. package/dist/artifacts/generated.js +124 -16
  4. package/dist/contracts/AssetRegistry.d.ts.map +1 -1
  5. package/dist/contracts/AssetRegistry.js +2 -1
  6. package/dist/contracts/ContractBase.d.ts +9 -0
  7. package/dist/contracts/ContractBase.d.ts.map +1 -1
  8. package/dist/contracts/ContractBase.js +102 -9
  9. package/dist/contracts/FixedPaymentTemplate.d.ts +4 -1
  10. package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -1
  11. package/dist/contracts/FixedPaymentTemplate.js +46 -1
  12. package/dist/models/AgentAccessToken.d.ts +123 -0
  13. package/dist/models/AgentAccessToken.d.ts.map +1 -0
  14. package/dist/models/AgentAccessToken.js +164 -0
  15. package/dist/models/NeverminedOptions.d.ts +1 -14
  16. package/dist/models/NeverminedOptions.d.ts.map +1 -1
  17. package/dist/models/NeverminedOptions.js +1 -19
  18. package/dist/models/index.d.ts +1 -0
  19. package/dist/models/index.d.ts.map +1 -1
  20. package/dist/models/index.js +1 -0
  21. package/dist/nevermined/api/PaymentsApi.d.ts +0 -1
  22. package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -1
  23. package/dist/nevermined/api/PaymentsApi.js +14 -32
  24. package/dist/nevermined/utils/AgentUtils.d.ts +8 -0
  25. package/dist/nevermined/utils/AgentUtils.d.ts.map +1 -0
  26. package/dist/nevermined/utils/AgentUtils.js +42 -0
  27. package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -1
  28. package/dist/nevermined/utils/JwtUtils.js +3 -0
  29. package/dist/nevermined/utils/WebServiceConnector.d.ts +1 -1
  30. package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -1
  31. package/dist/nevermined/utils/WebServiceConnector.js +4 -1
  32. package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -1
  33. package/dist/nevermined/utils/ZeroDevPolicies.js +4 -1
  34. package/dist/nevermined/utils/index.d.ts +1 -0
  35. package/dist/nevermined/utils/index.d.ts.map +1 -1
  36. package/dist/nevermined/utils/index.js +1 -0
  37. package/dist/services/Api.d.ts +1 -1
  38. package/dist/services/Api.d.ts.map +1 -1
  39. package/dist/services/Api.js +3 -3
  40. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ import { JWTPayload } from 'jose';
2
+ import { Account } from 'viem';
3
+ import { SmartAccount } from 'viem/account-abstraction';
4
+ import { SignatureUtils } from '../nevermined/utils/SignatureUtils.js';
5
+ /**
6
+ * The access to remote agents is granted through an authorization token.
7
+ * This token is generated using the AgentAccessToken JWT structure.
8
+ * AgentAccessToken:
9
+ * authToken: JWTAuthTokenParams
10
+ * proof: JWTRedemptionProofParams
11
+ */
12
+ export interface JWTAuthTokenParams {
13
+ /**
14
+ * The agent identifier related with the authorization token.
15
+ */
16
+ agentId: string;
17
+ /**
18
+ * The plan identifier related with the authorization token.
19
+ */
20
+ planId: string;
21
+ /**
22
+ * The public address of the account the key is issued for.
23
+ */
24
+ sub: `0x${string}`;
25
+ /**
26
+ * The public address of the account issuing the key.
27
+ */
28
+ iss?: `0x${string}`;
29
+ /**
30
+ * The chain id of the network the token is valid for. If zero the key is not having any network limitation
31
+ */
32
+ aud?: string;
33
+ /**
34
+ * JWT Expiration Time
35
+ *
36
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
37
+ */
38
+ exp?: number;
39
+ /**
40
+ * JWT Issued At
41
+ *
42
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
43
+ */
44
+ iat?: number;
45
+ [key: string]: unknown;
46
+ }
47
+ export interface JWTRedemptionProofParams {
48
+ keyspace: string;
49
+ nonce: string;
50
+ planIds: string[];
51
+ }
52
+ export declare class AgentAccessToken implements JWTPayload {
53
+ /**
54
+ * The version of the access token
55
+ */
56
+ ver?: string;
57
+ /**
58
+ * The authorization token used to query the agent.
59
+ * This token is validated by the agent or proxy to ensure the request is authorized
60
+ * {@see {@link AgentAuthTokenParams}}
61
+ */
62
+ authToken?: string;
63
+ /**
64
+ * The proof generated by the subscriber (sub) to prove the request to query the agent
65
+ * {@see {@link JWTRedemptionProofParams}
66
+ */
67
+ proof?: string;
68
+ iss?: string | undefined;
69
+ sub?: string | undefined;
70
+ aud?: string | string[] | undefined;
71
+ exp?: number;
72
+ iat?: number;
73
+ [propName: string]: unknown;
74
+ _signatureUtils: SignatureUtils;
75
+ _issuerAccount: Account | SmartAccount;
76
+ private constructor();
77
+ /**
78
+ * It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
79
+ * The string representing this key can be used to authenticate against the Nevermined API.
80
+ * @param signatureUtils The SignatureUtils instance
81
+ * @param issuerAccount The account issuing the key
82
+
83
+ */
84
+ static generate(signatureUtils: SignatureUtils, issuerAccount: Account | SmartAccount, agentId: string, planId: string | bigint, subscriberAddress: `0x${string}`, expirationTime?: number | string, version?: string): Promise<AgentAccessToken>;
85
+ setRedemptionProof(keyspace: string, nonce: string): Promise<this>;
86
+ decodeAuthToken(): JWTAuthTokenParams;
87
+ /**
88
+ * It serializes the NVM Api Key into a string
89
+ * @returns a string representing the NVM API Key
90
+ */
91
+ serialize(): string;
92
+ /**
93
+ * It serializes the NVM Api Key into a string
94
+ * @returns a string representing the NVM API Key
95
+ */
96
+ toString(): string;
97
+ /**
98
+ * It generates a signed JWT from the NvmApiKey
99
+ * @param signatureUtils The SignatureUtils instance
100
+ * @param issuerAccount The account issuing the key
101
+ * @returns the string in JWT format represeting the NvmApiKey
102
+ */
103
+ toJWT(): Promise<string>;
104
+ static fromJWT(jwtString: string, signatureUtils: SignatureUtils, issuerAddress: Account | SmartAccount): AgentAccessToken;
105
+ /**
106
+ * It decodes a string JWT into a JWTPayload
107
+ * @param str jwt string
108
+ * @returns the JWTPayload
109
+ */
110
+ static decodeJWT(str: string): JWTPayload;
111
+ /**
112
+ * It generates the hash of the NvmApiKey
113
+ * @returns a string representing the hash of the NvmApiKey
114
+ */
115
+ hash(): string;
116
+ /**
117
+ * Given a serialized string, it generates the hash
118
+ * @param serialized the serialized string
119
+ * @returns the hash
120
+ */
121
+ static hash(serialized: string): string;
122
+ }
123
+ //# sourceMappingURL=AgentAccessToken.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentAccessToken.d.ts","sourceRoot":"","sources":["../../src/models/AgentAccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,MAAM,MAAM,CAAA;AAC5C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAGvD,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAEtE;;;;;;GAMG;AAEH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,GAAG,EAAE,KAAK,MAAM,EAAE,CAAA;IAClB;;OAEG;IACH,GAAG,CAAC,EAAE,KAAK,MAAM,EAAE,CAAA;IACnB;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,EAAE,MAAM,CAAA;IAChB,KAAK,EAAE,MAAM,CAAA;IACb,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,qBAAa,gBAAiB,YAAW,UAAU;IACjD;;OAEG;IACH,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,IAAI,CAAC,UAAU,EAAE,MAAM;CAG/B"}
@@ -0,0 +1,164 @@
1
+ import { decodeJwt } from 'jose';
2
+ import { getChecksumAddress } from '../nevermined/utils/BlockchainViemUtils.js';
3
+ import { EthSignJWT } from '../nevermined/utils/JwtUtils.js';
4
+ import { SignatureUtils } from '../nevermined/utils/SignatureUtils.js';
5
+ export class AgentAccessToken {
6
+ /**
7
+ * The version of the access token
8
+ */
9
+ ver;
10
+ /**
11
+ * The authorization token used to query the agent.
12
+ * This token is validated by the agent or proxy to ensure the request is authorized
13
+ * {@see {@link AgentAuthTokenParams}}
14
+ */
15
+ authToken;
16
+ /**
17
+ * The proof generated by the subscriber (sub) to prove the request to query the agent
18
+ * {@see {@link JWTRedemptionProofParams}
19
+ */
20
+ proof;
21
+ iss;
22
+ sub;
23
+ aud;
24
+ exp;
25
+ iat;
26
+ _signatureUtils;
27
+ _issuerAccount;
28
+ constructor(signatureUtils, issuerAccount) {
29
+ this.ver = '1';
30
+ this._signatureUtils = signatureUtils;
31
+ this._issuerAccount = issuerAccount;
32
+ }
33
+ /**
34
+ * It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
35
+ * The string representing this key can be used to authenticate against the Nevermined API.
36
+ * @param signatureUtils The SignatureUtils instance
37
+ * @param issuerAccount The account issuing the key
38
+
39
+ */
40
+ static async generate(signatureUtils, issuerAccount, agentId, planId, subscriberAddress, expirationTime = '1y', version = '1') {
41
+ const issuerAddress = getChecksumAddress(issuerAccount.address);
42
+ const chainId = signatureUtils.client.chain?.id || 0;
43
+ const sub = getChecksumAddress(subscriberAddress);
44
+ const jwtAuth = {
45
+ iss: issuerAddress,
46
+ aud: chainId.toString(),
47
+ sub,
48
+ agentId,
49
+ planId: typeof planId === 'bigint' ? planId.toString() : planId,
50
+ };
51
+ const signedJWTAuth = await new EthSignJWT(jwtAuth)
52
+ .setProtectedHeader({ alg: 'ES256K' })
53
+ .setIssuedAt()
54
+ .setExpirationTime(expirationTime)
55
+ .ethSign(signatureUtils, issuerAccount);
56
+ // const jwtAccessToken: JWTAgentAccessToken = {
57
+ // ver: version,
58
+ // authToken: signedJWTAuth,
59
+ // proof: undefined, // This can be set later when the proof is generated
60
+ // }
61
+ const agentAccessToken = new AgentAccessToken(signatureUtils, issuerAccount);
62
+ agentAccessToken.ver = version;
63
+ agentAccessToken.authToken = signedJWTAuth;
64
+ agentAccessToken.proof = undefined; // This can be set later when the proof is generated
65
+ return agentAccessToken;
66
+ }
67
+ async setRedemptionProof(keyspace, nonce) {
68
+ const jwtPayload = decodeJwt(this.authToken);
69
+ const proofParams = {
70
+ keyspace,
71
+ nonce,
72
+ planIds: [String(jwtPayload.planId)],
73
+ };
74
+ this.proof = JSON.stringify(proofParams);
75
+ return this;
76
+ }
77
+ decodeAuthToken() {
78
+ if (!this.authToken) {
79
+ throw new Error('Auth token is not set');
80
+ }
81
+ const jwt = decodeJwt(this.authToken);
82
+ return {
83
+ agentId: jwt.agentId,
84
+ planId: jwt.planId,
85
+ sub: jwt.sub,
86
+ iss: jwt.iss,
87
+ aud: jwt.aud,
88
+ exp: jwt.exp,
89
+ iat: jwt.iat,
90
+ };
91
+ }
92
+ /**
93
+ * It serializes the NVM Api Key into a string
94
+ * @returns a string representing the NVM API Key
95
+ */
96
+ serialize() {
97
+ return this.toString();
98
+ }
99
+ /**
100
+ * It serializes the NVM Api Key into a string
101
+ * @returns a string representing the NVM API Key
102
+ */
103
+ toString() {
104
+ const params = {};
105
+ Object.keys(this)
106
+ .filter((val) => val !== undefined)
107
+ .forEach((key) => {
108
+ if (!key.startsWith('_'))
109
+ params[key] = this[key];
110
+ });
111
+ return JSON.stringify(params);
112
+ }
113
+ /**
114
+ * It generates a signed JWT from the NvmApiKey
115
+ * @param signatureUtils The SignatureUtils instance
116
+ * @param issuerAccount The account issuing the key
117
+ * @returns the string in JWT format represeting the NvmApiKey
118
+ */
119
+ async toJWT() {
120
+ const params = {};
121
+ Object.keys(this)
122
+ .filter((val) => val !== undefined)
123
+ .forEach((key) => {
124
+ if (!key.startsWith('_'))
125
+ params[key] = this[key];
126
+ });
127
+ const jwt = new EthSignJWT(params).setProtectedHeader({ alg: 'ES256K' });
128
+ return jwt.ethSign(this._signatureUtils, this._issuerAccount);
129
+ }
130
+ static fromJWT(jwtString, signatureUtils, issuerAddress) {
131
+ const jwt = AgentAccessToken.decodeJWT(jwtString);
132
+ const agentAccessToken = new AgentAccessToken(signatureUtils, issuerAddress);
133
+ Object.keys(jwt)
134
+ .filter((val) => val !== undefined)
135
+ .forEach((key) => {
136
+ if (!key.startsWith('_'))
137
+ agentAccessToken[key] = jwt[key];
138
+ });
139
+ return agentAccessToken;
140
+ }
141
+ /**
142
+ * It decodes a string JWT into a JWTPayload
143
+ * @param str jwt string
144
+ * @returns the JWTPayload
145
+ */
146
+ static decodeJWT(str) {
147
+ return decodeJwt(str);
148
+ }
149
+ /**
150
+ * It generates the hash of the NvmApiKey
151
+ * @returns a string representing the hash of the NvmApiKey
152
+ */
153
+ hash() {
154
+ return SignatureUtils.hash(this.serialize());
155
+ }
156
+ /**
157
+ * Given a serialized string, it generates the hash
158
+ * @param serialized the serialized string
159
+ * @returns the hash
160
+ */
161
+ static hash(serialized) {
162
+ return SignatureUtils.hash(serialized);
163
+ }
164
+ }
@@ -12,20 +12,11 @@ export declare class NeverminedOptions {
12
12
  */
13
13
  appUrl?: string;
14
14
  backendUrl?: string;
15
- /**
16
- * Web3 Provider.
17
- */
15
+ agentsProxy?: string;
18
16
  /**
19
17
  * Log level.
20
18
  */
21
19
  logLevel: string;
22
- /**
23
- * Gas multiplier for the fees.
24
- * Can be used to speed up the transactions.
25
- */
26
- /**
27
- * Enpoint for the graph-node http query
28
- */
29
20
  /**
30
21
  * The folder where the nevermined contract artifacts are located.
31
22
  */
@@ -39,10 +30,6 @@ export declare class NeverminedOptions {
39
30
  ipfsGateway?: string;
40
31
  ipfsProjectId?: string;
41
32
  ipfsProjectSecret?: string;
42
- /**
43
- * Use a gas station to calculate transaction fees
44
- */
45
- gasStationUri?: string;
46
33
  /**
47
34
  * ZeroDev project id
48
35
  */
@@ -1 +1 @@
1
- {"version":3,"file":"NeverminedOptions.d.ts","sourceRoot":"","sources":["../../src/models/NeverminedOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,qBAAa,iBAAiB;IACrB,OAAO,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACI,eAAe,CAAC,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACI,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,UAAU,CAAC,EAAE,MAAM,CAAA;IAI1B;;OAEG;IAGH;;OAEG;IACI,QAAQ,SAAS;IAGxB;;;OAGG;IAGH;;OAEG;IAGH;;OAEG;IACI,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IAE3B;;;;OAIG;IACI,WAAW,CAAC,EAAE,MAAM,CAAoB;IAExC,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAEjC;;OAEG;IACI,aAAa,CAAC,EAAE,MAAM,CAAA;IAE7B;;OAEG;IACI,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEhC;;OAEG;IACI,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACjC"}
1
+ {"version":3,"file":"NeverminedOptions.d.ts","sourceRoot":"","sources":["../../src/models/NeverminedOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,qBAAa,iBAAiB;IACrB,OAAO,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACI,eAAe,CAAC,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACI,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,WAAW,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACI,QAAQ,SAAS;IAExB;;OAEG;IACI,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IAE3B;;;;OAIG;IACI,WAAW,CAAC,EAAE,MAAM,CAAoB;IAExC,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAEjC;;OAEG;IACI,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEhC;;OAEG;IACI,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACjC"}
@@ -11,25 +11,11 @@ export class NeverminedOptions {
11
11
  */
12
12
  appUrl;
13
13
  backendUrl;
14
- // public backendAuthToken?: string
15
- /**
16
- * Web3 Provider.
17
- */
18
- // public web3Provider?: any
14
+ agentsProxy;
19
15
  /**
20
16
  * Log level.
21
17
  */
22
18
  logLevel = 'info';
23
- // public verbose?: boolean | LogLevel
24
- /**
25
- * Gas multiplier for the fees.
26
- * Can be used to speed up the transactions.
27
- */
28
- // public gasMultiplier?: number
29
- /**
30
- * Enpoint for the graph-node http query
31
- */
32
- // public graphHttpUri?: string
33
19
  /**
34
20
  * The folder where the nevermined contract artifacts are located.
35
21
  */
@@ -43,10 +29,6 @@ export class NeverminedOptions {
43
29
  ipfsGateway = 'https://ipfs.io';
44
30
  ipfsProjectId;
45
31
  ipfsProjectSecret;
46
- /**
47
- * Use a gas station to calculate transaction fees
48
- */
49
- gasStationUri;
50
32
  /**
51
33
  * ZeroDev project id
52
34
  */
@@ -2,4 +2,5 @@ export * from './Logger.js';
2
2
  export * from './NeverminedOptions.js';
3
3
  export * from './NvmApiKey.js';
4
4
  export * from './Transactions.js';
5
+ export * from './AgentAccessToken.js';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,wBAAwB,CAAA;AACtC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA"}
@@ -2,3 +2,4 @@ export * from './Logger.js';
2
2
  export * from './NeverminedOptions.js';
3
3
  export * from './NvmApiKey.js';
4
4
  export * from './Transactions.js';
5
+ export * from './AgentAccessToken.js';
@@ -9,7 +9,6 @@ export declare class PaymentsApi extends Instantiable {
9
9
  * @returns {@link PaymentsApi}
10
10
  */
11
11
  constructor(config: InstantiableConfig);
12
- private getTokenContract;
13
12
  getERC20Balance(userAddress: Address, tokenAddress: Address): Promise<bigint>;
14
13
  orderFiatPayment(planId: bigint, planReceiver: Address, from: Account | SmartAccount): Promise<OrderResult>;
15
14
  orderCryptoPayment(planId: bigint, plan: Plan, from: Account | SmartAccount): Promise<OrderResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"PaymentsApi.d.ts","sourceRoot":"","sources":["../../../src/nevermined/api/PaymentsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,OAAO,EAAsC,MAAM,MAAM,CAAA;AAChF,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAEjF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,IAAI,EAA8B,MAAM,uBAAuB,CAAA;AAQrF,qBAAa,WAAY,SAAQ,YAAY;IAC3C;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;YAKxB,gBAAgB;IAsBjB,eAAe,CAAC,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB7E,gBAAgB,CAC3B,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;IAqBV,kBAAkB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;CA8ExB"}
1
+ {"version":3,"file":"PaymentsApi.d.ts","sourceRoot":"","sources":["../../../src/nevermined/api/PaymentsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,EAAyB,MAAM,MAAM,CAAA;AAC9D,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,WAAW,EAAE,IAAI,EAA8B,MAAM,uBAAuB,CAAA;AAKrF,qBAAa,WAAY,SAAQ,YAAY;IAC3C;;;;OAIG;gBACS,MAAM,EAAE,kBAAkB;IAKzB,eAAe,CAAC,WAAW,EAAE,OAAO,EAAE,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAgB7E,gBAAgB,CAC3B,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;IAqBV,kBAAkB,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;CAmFxB"}
@@ -1,11 +1,7 @@
1
- import { getContract, parseAbi, zeroAddress } from 'viem';
1
+ import { parseAbi, zeroAddress } from 'viem';
2
2
  import { Instantiable } from '../../Instantiable.abstract.js';
3
- import { lockPaymentConditionAddress } from '../../artifacts/generated.js';
4
- import { createKernelClient } from '../utils/BlockchainViemUtils.js';
5
3
  import { PlanTransactionPaymentType } from '@nvm-monorepo/commons';
6
- const TOKEN_APPROVE_ABI = parseAbi([
7
- 'function approve(address spender, uint256 amount) external returns (bool)',
8
- ]);
4
+ import { NotEnoughBalance } from '../../errors/NeverminedErrors.js';
9
5
  const TOKEN_BALANCE_ABI = parseAbi(['function balanceOf(address) view returns (uint256)']);
10
6
  export class PaymentsApi extends Instantiable {
11
7
  /**
@@ -17,23 +13,6 @@ export class PaymentsApi extends Instantiable {
17
13
  super();
18
14
  this.setInstanceConfig(config);
19
15
  }
20
- async getTokenContract(token, from) {
21
- if (from.type === 'smart') {
22
- const kernelClient = await createKernelClient(from, this.config.chainId, this.config.zeroDevProjectId, this.nevermined.contracts.assetRegistry.publicClient);
23
- return getContract({
24
- address: token,
25
- abi: TOKEN_APPROVE_ABI,
26
- client: kernelClient,
27
- });
28
- }
29
- else {
30
- return getContract({
31
- address: token,
32
- abi: TOKEN_APPROVE_ABI,
33
- client: this.walletClient,
34
- });
35
- }
36
- }
37
16
  async getERC20Balance(userAddress, tokenAddress) {
38
17
  try {
39
18
  return this.client.public.readContract({
@@ -69,20 +48,23 @@ export class PaymentsApi extends Instantiable {
69
48
  const tokenAddress = plan.price.tokenAddress;
70
49
  const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n);
71
50
  this.logger.debug(`Ordering ${tokenAddress} ${totalAmount}`);
51
+ let txHash;
72
52
  if (tokenAddress && tokenAddress !== zeroAddress) {
53
+ this.logger.debug(`Processing ERC20 payment...`);
73
54
  // ERC20 token payment
74
55
  if (totalAmount > 0n) {
75
56
  const erc20Balance = await this.getERC20Balance(from.address, tokenAddress);
57
+ this.logger.debug(`ERC20 balance for ${from.address} in ${tokenAddress}: balance = ${erc20Balance} - total amount = ${totalAmount}`);
76
58
  if (erc20Balance < totalAmount) {
77
- throw new Error(`Insufficient balance (${erc20Balance} < ${totalAmount}) for ERC20 ${tokenAddress}`);
59
+ throw new NotEnoughBalance(`Insufficient balance (${erc20Balance} < ${totalAmount}) for ERC20 ${tokenAddress}`);
78
60
  }
79
- const tokenContract = await this.getTokenContract(tokenAddress, from);
80
- // Approve lockPayment contract
81
- const hash = await tokenContract.write.approve([lockPaymentConditionAddress, totalAmount]);
82
- const receipt = await this.nevermined.contracts.fixedPaymentTemplate.publicClient.waitForTransactionReceipt({ hash });
83
- this.logger.debug('Approving token transfer to lockPayment contract', receipt);
61
+ txHash =
62
+ await this.nevermined.contracts.fixedPaymentTemplate.createAgreementWithApprovals(planId, totalAmount, tokenAddress, from);
63
+ this.logger.debug(`Token approved + Agreement Created: ${txHash}`);
64
+ }
65
+ else {
66
+ txHash = await this.nevermined.contracts.fixedPaymentTemplate.createAgreement(planId, from);
84
67
  }
85
- const txHash = await this.nevermined.contracts.fixedPaymentTemplate.createAgreement(planId, from);
86
68
  const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
87
69
  return {
88
70
  txHash: txReceipt.transactionHash,
@@ -99,9 +81,9 @@ export class PaymentsApi extends Instantiable {
99
81
  // Native token payment
100
82
  const nativeTokenBalance = await this.client.public.getBalance({ address: from.address });
101
83
  if (nativeTokenBalance < totalAmount) {
102
- throw new Error(`Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`);
84
+ throw new NotEnoughBalance(`Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`);
103
85
  }
104
- const txHash = await this.nevermined.contracts.fixedPaymentTemplate.createAgreement(planId, from, {
86
+ txHash = await this.nevermined.contracts.fixedPaymentTemplate.createAgreement(planId, from, {
105
87
  value: totalAmount,
106
88
  });
107
89
  const txReceipt = await this.nevermined.contracts.assetRegistry.getTransactionReceipt(txHash);
@@ -0,0 +1,8 @@
1
+ import { ApiEndpoint } from '@nvm-monorepo/commons';
2
+ export declare function isEndpointRequestedIncluded(requestEndpoint: string, requestedHTTPVerb: string, agentEndpoints: ApiEndpoint[], agentOpenEndpoints?: string[]): {
3
+ matches: boolean;
4
+ urlMatching?: URL;
5
+ verbMatching?: string;
6
+ };
7
+ export declare function areUrlsEqualIgnoringQuery(url1: URL, url2: URL): boolean;
8
+ //# sourceMappingURL=AgentUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/AgentUtils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAGnD,wBAAgB,2BAA2B,CACzC,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,EACzB,cAAc,EAAE,WAAW,EAAE,EAC7B,kBAAkB,GAAE,MAAM,EAAO,GAChC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,GAAG,CAAC;IAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAoChE;AAED,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,GAAG,OAAO,CAOvE"}
@@ -0,0 +1,42 @@
1
+ import { match } from 'path-to-regexp';
2
+ export function isEndpointRequestedIncluded(requestEndpoint, requestedHTTPVerb, agentEndpoints, agentOpenEndpoints = []) {
3
+ try {
4
+ let matches = false;
5
+ requestedHTTPVerb = requestedHTTPVerb.toLowerCase();
6
+ let urlMatching, verbMatching;
7
+ const requestedUrl = new URL(requestEndpoint);
8
+ // Is the endpoint an open endpoint?
9
+ agentOpenEndpoints.forEach((openEndpoint) => {
10
+ const agentUrl = new URL(openEndpoint);
11
+ if (areUrlsEqualIgnoringQuery(agentUrl, requestedUrl)) {
12
+ urlMatching = new URL(openEndpoint);
13
+ matches = true;
14
+ }
15
+ });
16
+ if (matches)
17
+ return { matches: true, urlMatching };
18
+ // check if the endpoint/verb is part of the list
19
+ agentEndpoints.forEach((ep) => {
20
+ const [verb, url] = Object.entries(ep)[0];
21
+ const _url = new URL(url);
22
+ const fn = match(_url.pathname, { decode: decodeURIComponent });
23
+ if (fn(requestedUrl.pathname) && (verb.toLowerCase() === requestedHTTPVerb || verb === '*')) {
24
+ matches = true;
25
+ urlMatching = _url;
26
+ verbMatching = verb;
27
+ return;
28
+ }
29
+ });
30
+ return { matches, urlMatching, verbMatching };
31
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
32
+ }
33
+ catch (error) {
34
+ return { matches: false };
35
+ }
36
+ }
37
+ export function areUrlsEqualIgnoringQuery(url1, url2) {
38
+ return (url1.protocol === url2.protocol &&
39
+ url1.hostname === url2.hostname &&
40
+ url1.port === url2.port &&
41
+ url1.pathname === url2.pathname);
42
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"JwtUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/JwtUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAEvD,OAAO,EAAE,KAAK,mBAAmB,EAAE,OAAO,EAAwB,MAAM,MAAM,CAAA;AAC9E,OAAO,EAAE,KAAK,OAAO,EAAmD,MAAM,MAAM,CAAA;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AACvD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAGjF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAEpD,qBAAa,UAAW,SAAQ,OAAO;IACrC,eAAe,EAAE,mBAAmB,GAAG,SAAS,CAAA;IAEvC,kBAAkB,CAAC,eAAe,EAAE,mBAAmB;IAKnD,OAAO,CAClB,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,OAAO,GAAG,YAAY,EAC/B,UAAU,CAAC,EAAE,UAAU,GACtB,OAAO,CAAC,MAAM,CAAC;WAoDE,QAAQ,CAC1B,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAY9B,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,MAAM;CAUf;AAED,qBAAa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tB,OAAO,CAAC,MAAM,CAAC;WAoDE,QAAQ,CAC1B,IAAI,EAAE,MAAM,GAAG,UAAU,EACzB,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAY9B,OAAO,CAAC,SAAS;IAKjB,OAAO,CAAC,MAAM;CAUf;AAED,qBAAa,QAAS,SAAQ,YAAY;IACxC,MAAM,CAAC,qBAAqB,SAA2D;IAGvF,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,cAAc,EAAE,cAAc,CAAA;gBAElB,MAAM,EAAE,kBAAkB;IAO/B,gBAAgB,CAAC,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,MAAM;IAIrC,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC;IAqB3D,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,YAAY,EAAE,OAAO,CAAC,EAAE,MAAM;IAyB/E,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAc3C,MAAM,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM;IAKxC,MAAM,CAAC,aAAa,CAAC,aAAa,EAAE,MAAM;CAK3C"}
@@ -5,6 +5,7 @@ import { Instantiable } from '../../Instantiable.abstract.js';
5
5
  import { urlSafeBase64Decode, urlSafeBase64Encode } from '../../utils/helpers.js';
6
6
  import { getChecksumAddress } from './BlockchainViemUtils.js';
7
7
  import { SignatureUtils } from './SignatureUtils.js';
8
+ import { NVM_INFRA_ADMIN_ROLE } from '../../contracts/Roles.js';
8
9
  export class EthSignJWT extends SignJWT {
9
10
  protectedHeader;
10
11
  setProtectedHeader(protectedHeader) {
@@ -122,8 +123,10 @@ export class JwtUtils extends Instantiable {
122
123
  };
123
124
  }
124
125
  const address = getChecksumAddress(account.address);
126
+ const isAdmin = await this.nevermined.contracts.accessManager.hasRole(NVM_INFRA_ADMIN_ROLE, address);
125
127
  return new EthSignJWT({
126
128
  iss: address,
129
+ roles: isAdmin[0] ? ['admin'] : [],
127
130
  })
128
131
  .setProtectedHeader({ alg: 'ES256K' })
129
132
  .setIssuedAt()
@@ -23,7 +23,7 @@ export declare class WebServiceConnector {
23
23
  downloadUrl(url: string, headers?: any): Promise<string>;
24
24
  uploadMessage(url: string, data: string, encrypt?: boolean): Promise<any>;
25
25
  uploadFile(url: string, data: ReadStream, encrypt?: boolean): Promise<any>;
26
- fetchToken(url: string, grantToken: string, numberTries?: number, apiKeyHash?: string): Promise<Response>;
26
+ fetchToken(url: string, grantToken: string, sessionKey?: string, numberTries?: number, apiKeyHash?: string): Promise<Response>;
27
27
  fetchCID(cid: string): Promise<string>;
28
28
  private static getIPFSAuthToken;
29
29
  private fetch;
@@ -1 +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,E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,MAAM,GAClB,OAAO,CAAC,QAAQ,CAAC;IA2BP,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBnD,OAAO,CAAC,MAAM,CAAC,gBAAgB;YAUjB,KAAK;IAiBnB,OAAO,CAAC,MAAM;CAGf"}
@@ -133,11 +133,14 @@ export class WebServiceConnector {
133
133
  }
134
134
  return this.fetch(url, { method: 'POST', body: form });
135
135
  }
136
- async fetchToken(url, grantToken, numberTries = 1, apiKeyHash) {
136
+ async fetchToken(url, grantToken, sessionKey, numberTries = 1, apiKeyHash) {
137
137
  const bodyParams = new URLSearchParams({
138
138
  client_assertion_type: JwtUtils.CLIENT_ASSERTION_TYPE,
139
139
  client_assertion: grantToken,
140
140
  });
141
+ if (sessionKey) {
142
+ bodyParams.append('sessionKey', sessionKey);
143
+ }
141
144
  if (apiKeyHash) {
142
145
  bodyParams.append('nvm_key_hash', apiKeyHash);
143
146
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAY,MAAM,MAAM,CAAA;AAEpC,wBAAgB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,yCAK3C;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,0CACV,CAAA;AAE1D,eAAO,MAAM,0BAA0B,6CACwB,CAAA;AAE/D,eAAO,MAAM,gCAAgC,6CACoB,CAAA;AAEjE,eAAO,MAAM,uBAAuB,6CACuC,CAAA;AAE3E,eAAO,MAAM,cAAc,6CACiD,CAAA;AAE5E,eAAO,MAAM,gBAAgB,6CAAkE,CAAA;AAE/F,eAAO,MAAM,gBAAgB,6CAAkE,CAAA;AAE/F,eAAO,MAAM,iBAAiB,6CAS3B,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,EAAE,iBAAiB,KAAK,MAAM,EAAE,0CAoBhF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,0CAcjE,CAAA"}
1
+ {"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,GAAG,EAAY,MAAM,MAAM,CAAA;AAEpC,wBAAgB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,yCAK3C;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,0CACV,CAAA;AAE1D,eAAO,MAAM,0BAA0B,6CACwB,CAAA;AAE/D,eAAO,MAAM,gCAAgC,6CAC2C,CAAA;AAExF,eAAO,MAAM,uBAAuB,6CACuC,CAAA;AAE3E,eAAO,MAAM,cAAc,6CACiD,CAAA;AAE5E,eAAO,MAAM,gBAAgB,6CAAkE,CAAA;AAE/F,eAAO,MAAM,gBAAgB,6CAAkE,CAAA;AAE/F,eAAO,MAAM,iBAAiB,6CAU3B,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,EAAE,iBAAiB,KAAK,MAAM,EAAE,0CAqBhF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,0CAejE,CAAA"}
@@ -32,7 +32,7 @@ export function getERC20ApprovePermissions(contractAddress) {
32
32
  }
33
33
  export const getERC20ApprovePolicy = (contractAddress) => getPolicy([getERC20ApprovePermissions(contractAddress)]);
34
34
  export const getAgentRegistrationPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['register']));
35
- export const getPricingPlanRegistrationPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['createPlan']));
35
+ export const getPricingPlanRegistrationPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['createPlan', 'createPlanWithHooks']));
36
36
  export const getRegisterAssetsPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, ['registerAssetAndPlan']));
37
37
  export const getOrderPolicy = () => getPolicy(getPermissions(fixedPaymentTemplateConfig, ['createAgreement']));
38
38
  export const getMintNFTPolicy = () => getPolicy(getPermissions(nft1155CreditsConfig, ['mint']));
@@ -40,6 +40,7 @@ export const getBurnNFTPolicy = () => getPolicy(getPermissions(nft1155CreditsCon
40
40
  export const getRegisterPolicy = () => getPolicy(getPermissions(assetsRegistryConfig, [
41
41
  'register',
42
42
  'createPlan',
43
+ 'createPlanWithHooks',
43
44
  'registerAssetAndPlan',
44
45
  'addPlanToAsset',
45
46
  'removePlanFromAsset',
@@ -50,6 +51,7 @@ export const buildPolicy = (permissions, contractAddress) => {
50
51
  ? getPermissions(assetsRegistryConfig, [
51
52
  'register',
52
53
  'createPlan',
54
+ 'createPlanWithHooks',
53
55
  'registerAssetAndPlan',
54
56
  'addPlanToAsset',
55
57
  'removePlanFromAsset',
@@ -68,6 +70,7 @@ export const getAllContractsPolicy = (contractAddress) => getPolicy([
68
70
  ...getPermissions(assetsRegistryConfig, [
69
71
  'register',
70
72
  'createPlan',
73
+ 'createPlanWithHooks',
71
74
  'registerAssetAndPlan',
72
75
  'addPlanToAsset',
73
76
  'removePlanFromAsset',