@nevermined-io/core-kit 0.0.2-rc19 → 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.
- package/dist/contracts/AssetRegistry.d.ts.map +1 -1
- package/dist/contracts/AssetRegistry.js +2 -1
- package/dist/contracts/ContractBase.d.ts +9 -0
- package/dist/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +102 -9
- package/dist/contracts/FixedPaymentTemplate.d.ts +4 -1
- package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -1
- package/dist/contracts/FixedPaymentTemplate.js +46 -1
- package/dist/models/AgentAccessToken.d.ts +123 -0
- package/dist/models/AgentAccessToken.d.ts.map +1 -0
- package/dist/models/AgentAccessToken.js +164 -0
- package/dist/models/NeverminedOptions.d.ts +1 -14
- package/dist/models/NeverminedOptions.d.ts.map +1 -1
- package/dist/models/NeverminedOptions.js +1 -19
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +1 -0
- package/dist/nevermined/api/PaymentsApi.d.ts +0 -1
- package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -1
- package/dist/nevermined/api/PaymentsApi.js +14 -32
- package/dist/nevermined/utils/AgentUtils.d.ts +8 -0
- package/dist/nevermined/utils/AgentUtils.d.ts.map +1 -0
- package/dist/nevermined/utils/AgentUtils.js +42 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +2 -2
- package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -1
- package/dist/nevermined/utils/JwtUtils.js +3 -0
- package/dist/nevermined/utils/WebServiceConnector.d.ts +1 -1
- package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -1
- package/dist/nevermined/utils/WebServiceConnector.js +4 -1
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -1
- package/dist/nevermined/utils/ZeroDevPolicies.js +4 -1
- package/dist/nevermined/utils/index.d.ts +1 -0
- package/dist/nevermined/utils/index.d.ts.map +1 -1
- package/dist/nevermined/utils/index.js +1 -0
- package/dist/services/Api.d.ts +1 -1
- package/dist/services/Api.d.ts.map +1 -1
- package/dist/services/Api.js +3 -3
- package/package.json +1 -1
- package/dist/services/MarketplaceAPI.d.ts +0 -7
- package/dist/services/MarketplaceAPI.d.ts.map +0 -1
- package/dist/services/MarketplaceAPI.js +0 -25
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AssetRegistry.d.ts","sourceRoot":"","sources":["../../src/contracts/AssetRegistry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAC/F,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAa,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAC3E,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAS7E,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAEhD,qBAAa,aAAc,SAAQ,YAAY;WAChB,WAAW,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,aAAa,CAAC;IAS/E,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC;IAIzD,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMxC,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAIvC,QAAQ,CAAC,EACpB,OAAO,EACP,GAAG,EACH,KAAK,EACL,KAAK,EACL,QAAQ,GACT,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,GAAG,EAA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B,QAAQ,CAAC,EAAE,YAAY,CAAA;KACxB,GAAG,OAAO,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;IAWzC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMtC,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxC,cAAc,CACzB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;IAIxC,mBAAmB,CAC9B,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY,GACtB,OAAO,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;IAIxC,mBAAmB,CAC9B,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,EAC5B,OAAO,UAAO;;;;;;;;;;;;;;;;;;;;IAwBH,UAAU,CACrB,YAAY,EAAE,WAAW,EACzB,cAAc,EAAE,aAAa,EAC7B,KAAK,EAAE,OAAO,EACd,OAAO,UAAO,EACd,KAAK,SAAK,GACT,OAAO,CAAC,MAAM,CAAC;IAcL,yBAAyB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAOrE,6BAA6B,CACxC,WAAW,EAAE,WAAW,EACxB,aAAa,EAAE,aAAa,GAC3B,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;CAOjC"}
|
|
@@ -29,7 +29,8 @@ export class AssetRegistry extends ContractBase {
|
|
|
29
29
|
async createPlan({ priceConfig, creditsConfig, owner, nonce = 0n, addFees = true, isTrialPlan = false, txParams, }) {
|
|
30
30
|
const _config = await this.planConfigPreFilter(priceConfig, creditsConfig, addFees);
|
|
31
31
|
if (isTrialPlan) {
|
|
32
|
-
|
|
32
|
+
const hooks = [oneTimeCreatorHookAddress];
|
|
33
|
+
return this.send('createPlanWithHooks', owner, [_config.priceConfig, _config.creditsConfig, hooks, nonce], txParams);
|
|
33
34
|
}
|
|
34
35
|
else {
|
|
35
36
|
return this.send('createPlan', owner, [_config.priceConfig, _config.creditsConfig, nonce], txParams);
|
|
@@ -2,6 +2,12 @@ import { Abi, Account, Address, TransactionReceipt } from 'viem';
|
|
|
2
2
|
import { SmartAccount, UserOperationReceipt } from 'viem/account-abstraction';
|
|
3
3
|
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract.js';
|
|
4
4
|
import { TxParameters } from '../models/Transactions.js';
|
|
5
|
+
export interface MulticallEntry {
|
|
6
|
+
contractAddress: Address;
|
|
7
|
+
abi: Abi;
|
|
8
|
+
functionName: string;
|
|
9
|
+
args: any[];
|
|
10
|
+
}
|
|
5
11
|
export declare abstract class ContractBase extends Instantiable {
|
|
6
12
|
readonly contractName: string;
|
|
7
13
|
contract: any;
|
|
@@ -14,8 +20,11 @@ export declare abstract class ContractBase extends Instantiable {
|
|
|
14
20
|
call<T>(functionName: string, args: any[], from?: string): Promise<T>;
|
|
15
21
|
getTransactionReceipt(txHash: UserOperationReceipt | TransactionReceipt): Promise<TransactionReceipt>;
|
|
16
22
|
getTransactionLogs(txReceipt: TransactionReceipt | UserOperationReceipt, eventName?: string): any[];
|
|
23
|
+
multicall(calls: MulticallEntry[], from: Account | SmartAccount, params?: TxParameters): Promise<TransactionReceipt | undefined>;
|
|
17
24
|
send(functionName: string, from: Account | SmartAccount, args: any[], params?: TxParameters): Promise<TransactionReceipt | UserOperationReceipt>;
|
|
25
|
+
private internalMulticallSmartAccount;
|
|
18
26
|
private internalSendSmartAccount;
|
|
19
27
|
private localAccountSend;
|
|
28
|
+
private localAccountMulticall;
|
|
20
29
|
}
|
|
21
30
|
//# sourceMappingURL=ContractBase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"AACA,OAAO,EACL,GAAG,EACH,OAAO,EACP,OAAO,EAQP,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE7E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;
|
|
1
|
+
{"version":3,"file":"ContractBase.d.ts","sourceRoot":"","sources":["../../src/contracts/ContractBase.ts"],"names":[],"mappings":"AACA,OAAO,EACL,GAAG,EACH,OAAO,EACP,OAAO,EAQP,kBAAkB,EACnB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAA;AAE7E,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAIxD,MAAM,WAAW,cAAc;IAC7B,eAAe,EAAE,OAAO,CAAA;IACxB,GAAG,EAAE,GAAG,CAAA;IACR,YAAY,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,GAAG,EAAE,CAAA;CACZ;AAED,8BAAsB,YAAa,SAAQ,YAAY;IACrD,SAAgB,YAAY,EAAE,MAAM,CAAA;IAC7B,QAAQ,EAAE,GAAG,CAAA;IACb,OAAO,EAAE,OAAO,CAAA;gBAEX,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO;cAMlC,IAAI,CAClB,MAAM,EAAE,kBAAkB,EAC1B,cAAc,EAAE;QAAE,OAAO,EAAE,KAAK,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,GAAG,CAAA;KAAE;IAYzC,IAAI,CAAC,CAAC,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAiBrE,qBAAqB,CAChC,MAAM,EAAE,oBAAoB,GAAG,kBAAkB,GAChD,OAAO,CAAC,kBAAkB,CAAC;IAgBvB,kBAAkB,CACvB,SAAS,EAAE,kBAAkB,GAAG,oBAAoB,EACpD,SAAS,CAAC,EAAE,MAAM,GAOZ,GAAG,EAAE;IAGA,SAAS,CACpB,KAAK,EAAE,cAAc,EAAE,EACvB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,MAAM,GAAE,YAAiB;IAgBd,IAAI,CACf,YAAY,EAAE,MAAM,EACpB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,IAAI,EAAE,GAAG,EAAE,EACX,MAAM,GAAE,YAAiB,GACxB,OAAO,CAAC,kBAAkB,GAAG,oBAAoB,CAAC;YAiBvC,6BAA6B;YA+E7B,wBAAwB;YA8HxB,gBAAgB;YAkGhB,qBAAqB;CAepC"}
|
|
@@ -2,8 +2,7 @@ import { createKernelAccountClient, createZeroDevPaymasterClient } from '@zerode
|
|
|
2
2
|
import { BaseError, ContractFunctionRevertedError, encodeFunctionData, getContract, http, parseAbi, parseEventLogs, } from 'viem';
|
|
3
3
|
import { ContractsError } from '../errors/index.js';
|
|
4
4
|
import { Instantiable } from '../Instantiable.abstract.js';
|
|
5
|
-
import { getInputsOfFunctionFormatted,
|
|
6
|
-
import { jsonReplacer } from '../utils/helpers.js';
|
|
5
|
+
import { getInputsOfFunctionFormatted, getTransactionReceipt } from '../nevermined/index.js';
|
|
7
6
|
import { getChain } from '../utils/Network.js';
|
|
8
7
|
export class ContractBase extends Instantiable {
|
|
9
8
|
contractName;
|
|
@@ -63,6 +62,23 @@ export class ContractBase extends Instantiable {
|
|
|
63
62
|
strict: false,
|
|
64
63
|
});
|
|
65
64
|
}
|
|
65
|
+
async multicall(calls, from, params = {}) {
|
|
66
|
+
if (from.type === 'local') {
|
|
67
|
+
this.logger.debug(`Blockchain Multicall using Local account`);
|
|
68
|
+
return await this.localAccountMulticall(calls, from, params, params.progress);
|
|
69
|
+
}
|
|
70
|
+
else if (from.type === 'json-rpc') {
|
|
71
|
+
this.logger.debug(`Blockchain Multicall using JSON-RPC account`);
|
|
72
|
+
return await this.localAccountMulticall(calls, from, params, params.progress);
|
|
73
|
+
}
|
|
74
|
+
else if (from.type === 'smart') {
|
|
75
|
+
this.logger.debug(`Blockchain Multicall using ZeroDev account`);
|
|
76
|
+
return await this.internalMulticallSmartAccount(calls, from, params, params.progress);
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
throw new ContractsError(`Account not supported`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
66
82
|
async send(functionName, from, args, params = {}) {
|
|
67
83
|
if (from.type === 'local') {
|
|
68
84
|
this.logger.debug(`Blockchain Send using Local account with functionName: ${functionName} and following args: ${args}`);
|
|
@@ -80,6 +96,73 @@ export class ContractBase extends Instantiable {
|
|
|
80
96
|
throw new ContractsError(`Account not supported`);
|
|
81
97
|
}
|
|
82
98
|
}
|
|
99
|
+
async internalMulticallSmartAccount(calls, from, txparams, progress) {
|
|
100
|
+
if (progress) {
|
|
101
|
+
progress({
|
|
102
|
+
stage: 'multicall-sending',
|
|
103
|
+
args: [],
|
|
104
|
+
method: '',
|
|
105
|
+
from: from,
|
|
106
|
+
contractAddress: this.address,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
const ZERODEV_RPC = `https://rpc.zerodev.app/api/v3/${this.config.zeroDevProjectId}/chain/${this.config.chainId}`;
|
|
110
|
+
const zerodevPaymaster = createZeroDevPaymasterClient({
|
|
111
|
+
chain: getChain(this.config.chainId),
|
|
112
|
+
transport: http(ZERODEV_RPC),
|
|
113
|
+
});
|
|
114
|
+
const kernelClient = createKernelAccountClient({
|
|
115
|
+
account: from,
|
|
116
|
+
chain: getChain(this.config.chainId),
|
|
117
|
+
bundlerTransport: http(ZERODEV_RPC),
|
|
118
|
+
client: this.contract.publicClient,
|
|
119
|
+
paymaster: {
|
|
120
|
+
getPaymasterData: (userOperation) => {
|
|
121
|
+
return zerodevPaymaster.sponsorUserOperation({
|
|
122
|
+
userOperation,
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
const encodedCalls = [];
|
|
128
|
+
calls.map((call) => {
|
|
129
|
+
encodedCalls.push({
|
|
130
|
+
to: call.contractAddress || this.address,
|
|
131
|
+
value: txparams.value || 0n,
|
|
132
|
+
data: encodeFunctionData({
|
|
133
|
+
abi: call.abi,
|
|
134
|
+
functionName: call.functionName,
|
|
135
|
+
args: call.args,
|
|
136
|
+
}),
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
try {
|
|
140
|
+
const userOpHash = await kernelClient.sendUserOperation({
|
|
141
|
+
callData: await kernelClient.account.encodeCalls(encodedCalls),
|
|
142
|
+
});
|
|
143
|
+
if (progress) {
|
|
144
|
+
progress({
|
|
145
|
+
stage: 'multicall-sent',
|
|
146
|
+
args: [],
|
|
147
|
+
method: '',
|
|
148
|
+
from: from,
|
|
149
|
+
contractAddress: this.address,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
// Wait for the transaction to be mined
|
|
153
|
+
this.logger.debug(`Waiting for transaction to be mined...`, userOpHash);
|
|
154
|
+
const txReceipt = await kernelClient.waitForUserOperationReceipt({ hash: userOpHash });
|
|
155
|
+
this.logger.debug(`Transaction mined: ${userOpHash}`);
|
|
156
|
+
return txReceipt.receipt;
|
|
157
|
+
}
|
|
158
|
+
catch (err) {
|
|
159
|
+
if (err instanceof BaseError) {
|
|
160
|
+
const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError);
|
|
161
|
+
this.logger.error('revertError', revertError);
|
|
162
|
+
}
|
|
163
|
+
throw new ContractsError(`Multicall failed: ${err}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
83
166
|
async internalSendSmartAccount(name, from, args, txparams, progress) {
|
|
84
167
|
const functionInputs = getInputsOfFunctionFormatted(this.contract.abi, name, args);
|
|
85
168
|
const { gasLimit, value } = txparams;
|
|
@@ -186,13 +269,13 @@ export class ContractBase extends Instantiable {
|
|
|
186
269
|
async localAccountSend(name, from, args, txparams, progress) {
|
|
187
270
|
const functionInputs = getInputsOfFunctionFormatted(this.contract.abi, name, args);
|
|
188
271
|
// Uncomment to debug contract calls
|
|
189
|
-
if (name === 'createAgreement') {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
272
|
+
// if (name === 'createAgreement') {
|
|
273
|
+
// const functionSignature = getSignatureOfFunction(this.contract.abi, name, args)
|
|
274
|
+
// this.logger.debug(`Making contract call ....: ${name} - ${from}`)
|
|
275
|
+
// this.logger.debug(`With args`, args)
|
|
276
|
+
// this.logger.debug(`And signature - ${JSON.stringify(functionSignature, jsonReplacer)}`)
|
|
277
|
+
// this.logger.debug('And amount: ', txparams.value)
|
|
278
|
+
// }
|
|
196
279
|
// abi.filter(({name, inputs}) => name === 'closeSignals' && inputs.length === 1)
|
|
197
280
|
// const abiFilter = this.contract.abi.filter((abi) => abi.name === name && abi.inputs.length === args.length)
|
|
198
281
|
// const abiFilter = this.contract.abi.filter((abi) => abi.name === name && abi.type === 'function')
|
|
@@ -267,4 +350,14 @@ export class ContractBase extends Instantiable {
|
|
|
267
350
|
}
|
|
268
351
|
return txReceipt;
|
|
269
352
|
}
|
|
353
|
+
async localAccountMulticall(calls, from, txparams, progress) {
|
|
354
|
+
const receipts = [];
|
|
355
|
+
for (const call of calls) {
|
|
356
|
+
receipts.push(await this.localAccountSend(call.functionName, from, call.args, txparams, progress));
|
|
357
|
+
}
|
|
358
|
+
if (receipts.length > 0)
|
|
359
|
+
return receipts.pop();
|
|
360
|
+
else
|
|
361
|
+
throw new ContractsError(`No receipts found for multicall`);
|
|
362
|
+
}
|
|
270
363
|
}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { Account } from 'viem';
|
|
1
|
+
import { Account, Address } from 'viem';
|
|
2
2
|
import { SmartAccount } from 'viem/account-abstraction';
|
|
3
3
|
import { InstantiableConfig } from '../Instantiable.abstract.js';
|
|
4
4
|
import { TxParameters } from '../models/Transactions.js';
|
|
5
5
|
import { ContractBase } from './ContractBase.js';
|
|
6
6
|
export declare class FixedPaymentTemplate extends ContractBase {
|
|
7
|
+
private TOKEN_APPROVE_ABI;
|
|
7
8
|
static getInstance(config: InstantiableConfig): Promise<FixedPaymentTemplate>;
|
|
8
9
|
createAgreement(planId: bigint, owner: Account | SmartAccount, txParams?: TxParameters): Promise<import("viem").TransactionReceipt | import("viem/account-abstraction").UserOperationReceipt>;
|
|
10
|
+
approveERC20(totalAmount: bigint, tokenAddress: Address, owner: Account | SmartAccount, txParams?: TxParameters): Promise<import("viem").TransactionReceipt | undefined>;
|
|
11
|
+
createAgreementWithApprovals(planId: bigint, totalAmount: bigint, tokenAddress: Address, owner: Account | SmartAccount, txParams?: TxParameters): Promise<import("viem").TransactionReceipt | undefined>;
|
|
9
12
|
}
|
|
10
13
|
//# sourceMappingURL=FixedPaymentTemplate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FixedPaymentTemplate.d.ts","sourceRoot":"","sources":["../../src/contracts/FixedPaymentTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"FixedPaymentTemplate.d.ts","sourceRoot":"","sources":["../../src/contracts/FixedPaymentTemplate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,OAAO,EAAE,OAAO,EAAY,MAAM,MAAM,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAMvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,OAAO,EAAE,YAAY,EAAkB,MAAM,mBAAmB,CAAA;AAEhE,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,OAAO,CAAC,iBAAiB,CAEhB;WAEoB,WAAW,CACtC,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,oBAAoB,CAAC;IASnB,eAAe,CAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY;IAMZ,YAAY,CACvB,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY;IAmBZ,4BAA4B,CACvC,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY;CA0B1B"}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { parseAbi } from 'viem';
|
|
2
|
+
import { fixedPaymentTemplateConfig, lockPaymentConditionAddress, paymentsVaultAddress, } from '../artifacts/generated.js';
|
|
2
3
|
import { generateZeroXId } from '../utils/helpers.js';
|
|
3
4
|
import { ContractBase } from './ContractBase.js';
|
|
4
5
|
export class FixedPaymentTemplate extends ContractBase {
|
|
6
|
+
TOKEN_APPROVE_ABI = parseAbi([
|
|
7
|
+
'function approve(address spender, uint256 amount) external returns (bool)',
|
|
8
|
+
]);
|
|
5
9
|
static async getInstance(config) {
|
|
6
10
|
const fixedPaymentTemplate = new FixedPaymentTemplate('FixedPaymentTemplate', fixedPaymentTemplateConfig.address);
|
|
7
11
|
await fixedPaymentTemplate.init(config, fixedPaymentTemplateConfig);
|
|
@@ -11,4 +15,45 @@ export class FixedPaymentTemplate extends ContractBase {
|
|
|
11
15
|
const agreementIdSeed = generateZeroXId();
|
|
12
16
|
return this.send('createAgreement', owner, [agreementIdSeed, planId, []], txParams);
|
|
13
17
|
}
|
|
18
|
+
async approveERC20(totalAmount, tokenAddress, owner, txParams) {
|
|
19
|
+
const calls = [
|
|
20
|
+
{
|
|
21
|
+
contractAddress: tokenAddress,
|
|
22
|
+
abi: this.TOKEN_APPROVE_ABI,
|
|
23
|
+
functionName: 'approve',
|
|
24
|
+
args: [lockPaymentConditionAddress, totalAmount],
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
contractAddress: tokenAddress,
|
|
28
|
+
abi: this.TOKEN_APPROVE_ABI,
|
|
29
|
+
functionName: 'approve',
|
|
30
|
+
args: [paymentsVaultAddress, totalAmount],
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
return await this.multicall(calls, owner, txParams);
|
|
34
|
+
}
|
|
35
|
+
async createAgreementWithApprovals(planId, totalAmount, tokenAddress, owner, txParams) {
|
|
36
|
+
const agreementIdSeed = generateZeroXId();
|
|
37
|
+
const calls = [
|
|
38
|
+
{
|
|
39
|
+
contractAddress: tokenAddress,
|
|
40
|
+
abi: this.TOKEN_APPROVE_ABI,
|
|
41
|
+
functionName: 'approve',
|
|
42
|
+
args: [lockPaymentConditionAddress, totalAmount],
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
contractAddress: tokenAddress,
|
|
46
|
+
abi: this.TOKEN_APPROVE_ABI,
|
|
47
|
+
functionName: 'approve',
|
|
48
|
+
args: [paymentsVaultAddress, totalAmount],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
contractAddress: this.address,
|
|
52
|
+
abi: this.contract.abi,
|
|
53
|
+
functionName: 'createAgreement',
|
|
54
|
+
args: [agreementIdSeed, planId, []],
|
|
55
|
+
},
|
|
56
|
+
];
|
|
57
|
+
return await this.multicall(calls, owner, txParams);
|
|
58
|
+
}
|
|
14
59
|
}
|
|
@@ -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,E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C,gBAAgB,CAAC;IA8Bf,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAWxD,eAAe,IAAI,kBAAkB;IAiB5C;;;OAGG;IACI,SAAS,IAAI,MAAM;IAI1B;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAUzB;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;WAYvB,OAAO,CACnB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,OAAO,GAAG,YAAY,GACpC,gBAAgB;IAWnB;;;;OAIG;WACW,SAAS,CAAC,GAAG,EAAE,MAAM;IAInC;;;OAGG;IACI,IAAI;IAIX;;;;OAIG;IACH,MAAM,CAAC,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;
|
|
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
|
-
|
|
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
|
*/
|
package/dist/models/index.d.ts
CHANGED
|
@@ -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"}
|
package/dist/models/index.js
CHANGED
|
@@ -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,
|
|
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 {
|
|
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
|
-
|
|
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
|
|
59
|
+
throw new NotEnoughBalance(`Insufficient balance (${erc20Balance} < ${totalAmount}) for ERC20 ${tokenAddress}`);
|
|
78
60
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
84
|
+
throw new NotEnoughBalance(`Insufficient balance (${nativeTokenBalance} < ${totalAmount}) for native token payment`);
|
|
103
85
|
}
|
|
104
|
-
|
|
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
|
+
}
|
|
@@ -66,8 +66,8 @@ export declare function getContractInstance(contractAddress: string, abi: Abi, c
|
|
|
66
66
|
};
|
|
67
67
|
getEvents: {
|
|
68
68
|
[x: string]: (...parameters: [options?: {
|
|
69
|
-
strict?: boolean | undefined;
|
|
70
69
|
blockHash?: `0x${string}` | undefined;
|
|
70
|
+
strict?: boolean | undefined;
|
|
71
71
|
fromBlock?: bigint | import("viem").BlockTag | undefined;
|
|
72
72
|
toBlock?: bigint | import("viem").BlockTag | undefined;
|
|
73
73
|
} | undefined] | [args?: readonly unknown[] | {
|
|
@@ -84,8 +84,8 @@ export declare function getContractInstance(contractAddress: string, abi: Abi, c
|
|
|
84
84
|
batch?: undefined;
|
|
85
85
|
pollingInterval?: undefined;
|
|
86
86
|
} | undefined, options?: {
|
|
87
|
-
strict?: boolean | undefined;
|
|
88
87
|
blockHash?: `0x${string}` | undefined;
|
|
88
|
+
strict?: boolean | undefined;
|
|
89
89
|
fromBlock?: bigint | import("viem").BlockTag | undefined;
|
|
90
90
|
toBlock?: bigint | import("viem").BlockTag | undefined;
|
|
91
91
|
} | undefined]) => Promise<import("viem").GetContractEventsReturnType<Abi, string>>;
|
|
@@ -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,
|
|
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,EAA4D,MAAM,MAAM,CAAA;AAC7F,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;AAGpD,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,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,C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,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,
|
|
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',
|
|
@@ -1 +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"}
|
|
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"}
|
package/dist/services/Api.d.ts
CHANGED
|
@@ -2,6 +2,6 @@ import { Instantiable, InstantiableConfig } from '../Instantiable.abstract.js';
|
|
|
2
2
|
export declare class Api extends Instantiable {
|
|
3
3
|
constructor(config: InstantiableConfig);
|
|
4
4
|
protected get url(): string | undefined;
|
|
5
|
-
validateAssertion(clientAssertion: string): Promise<string>;
|
|
5
|
+
validateAssertion(clientAssertion: string, sessionKey?: string): Promise<string>;
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=Api.d.ts.map
|
|
@@ -1 +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,GAAG,OAAO,CAAC,MAAM,CAAC;
|
|
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"}
|
package/dist/services/Api.js
CHANGED
|
@@ -9,13 +9,13 @@ export class Api extends Instantiable {
|
|
|
9
9
|
get url() {
|
|
10
10
|
return this.config.backendUrl;
|
|
11
11
|
}
|
|
12
|
-
async validateAssertion(clientAssertion) {
|
|
12
|
+
async validateAssertion(clientAssertion, sessionKey) {
|
|
13
13
|
try {
|
|
14
|
-
const response = await this.nevermined.utils.fetch.fetchToken(`${this.url}${authPath}/validate-assertion`, clientAssertion);
|
|
14
|
+
const response = await this.nevermined.utils.fetch.fetchToken(`${this.url}${authPath}/validate-assertion`, clientAssertion, sessionKey);
|
|
15
15
|
if (!response.ok) {
|
|
16
16
|
throw new HttpError(`Error Login - ${response.statusText} ${response.url}`, response.status);
|
|
17
17
|
}
|
|
18
|
-
const backendAuthToken = (await response.json()).
|
|
18
|
+
const backendAuthToken = (await response.json()).hash;
|
|
19
19
|
return backendAuthToken;
|
|
20
20
|
}
|
|
21
21
|
catch (error) {
|
package/package.json
CHANGED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract.js';
|
|
2
|
-
export declare class MarketplaceApi extends Instantiable {
|
|
3
|
-
constructor(config: InstantiableConfig);
|
|
4
|
-
protected get url(): string | undefined;
|
|
5
|
-
login(clientAssertion: string): Promise<string>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=MarketplaceAPI.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"MarketplaceAPI.d.ts","sourceRoot":"","sources":["../../src/services/MarketplaceAPI.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAA;AAK9E,qBAAa,cAAe,SAAQ,YAAY;gBAClC,MAAM,EAAE,kBAAkB;IAKtC,SAAS,KAAK,GAAG,uBAEhB;IAEY,KAAK,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAkB7D"}
|
|
@@ -1,25 +0,0 @@
|
|
|
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 MarketplaceApi extends Instantiable {
|
|
5
|
-
constructor(config) {
|
|
6
|
-
super();
|
|
7
|
-
this.setInstanceConfig(config);
|
|
8
|
-
}
|
|
9
|
-
get url() {
|
|
10
|
-
return this.config.backendUrl;
|
|
11
|
-
}
|
|
12
|
-
async login(clientAssertion) {
|
|
13
|
-
try {
|
|
14
|
-
const response = await this.nevermined.utils.fetch.fetchToken(`${this.url}${authPath}/login`, clientAssertion);
|
|
15
|
-
if (!response.ok) {
|
|
16
|
-
throw new HttpError(`Error Login - ${response.statusText} ${response.url}`, response.status);
|
|
17
|
-
}
|
|
18
|
-
const backendAuthToken = (await response.json()).access_token;
|
|
19
|
-
return backendAuthToken;
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
throw new ApiError(error instanceof Error ? error.message : String(error));
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|