@nevermined-io/core-kit 0.0.59 → 0.1.1
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/artifacts/generated.d.ts +1229 -327
- package/dist/artifacts/generated.d.ts.map +1 -1
- package/dist/artifacts/generated.js +443 -122
- package/dist/contracts/AssetRegistry.js +2 -2
- package/dist/contracts/ContractBase.d.ts.map +1 -1
- package/dist/contracts/ContractBase.js +7 -31
- package/dist/contracts/FixedPaymentTemplate.d.ts +1 -0
- package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -1
- package/dist/contracts/FixedPaymentTemplate.js +4 -0
- package/dist/models/AgentX402AccessToken.d.ts +59 -0
- package/dist/models/AgentX402AccessToken.d.ts.map +1 -0
- package/dist/models/AgentX402AccessToken.js +78 -0
- 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.map +1 -1
- package/dist/nevermined/api/PaymentsApi.js +0 -2
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +11 -0
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -1
- package/dist/nevermined/utils/BlockchainViemUtils.js +42 -0
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +28 -11
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -1
- package/dist/nevermined/utils/ZeroDevPolicies.js +68 -1
- package/package.json +3 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { isAddress, zeroAddress } from 'viem';
|
|
2
|
-
import { assetsRegistryConfig, nft1155CreditsAddress,
|
|
2
|
+
import { assetsRegistryConfig, nft1155CreditsAddress, nft1155ExpirableCreditsV2Address, oneTimeCreatorHookAddress, payAsYouGoTemplateAddress, protocolStandardFeesAddress, } from '../artifacts/generated.js';
|
|
3
3
|
import { AgentNotFound, PlanNotFound } from '../errors/NeverminedErrors.js';
|
|
4
4
|
import { zeroX, toAgentId } from '../utils/ConversionTypeHelpers.js';
|
|
5
5
|
import { ContractBase } from './ContractBase.js';
|
|
@@ -86,7 +86,7 @@ export class AssetRegistry extends ContractBase {
|
|
|
86
86
|
_priceConfig.templateAddress = zeroAddress;
|
|
87
87
|
if (!creditsConfig.nftAddress || !isAddress(creditsConfig.nftAddress)) {
|
|
88
88
|
if (creditsConfig.durationSecs > 0n) {
|
|
89
|
-
_creditsConfig.nftAddress =
|
|
89
|
+
_creditsConfig.nftAddress = nft1155ExpirableCreditsV2Address;
|
|
90
90
|
}
|
|
91
91
|
else {
|
|
92
92
|
_creditsConfig.nftAddress = nft1155CreditsAddress;
|
|
@@ -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;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,E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BpB,gBAAgB;YAkGhB,qBAAqB;CAepC"}
|
|
@@ -285,38 +285,14 @@ export class ContractBase extends Instantiable {
|
|
|
285
285
|
return txReceipt;
|
|
286
286
|
}
|
|
287
287
|
async internalSimulateSmartAccount(name, from, args, txparams) {
|
|
288
|
-
const ZERODEV_RPC = `https://rpc.zerodev.app/api/v3/${this.config.zeroDevProjectId}/chain/${this.config.chainId}`;
|
|
289
288
|
try {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
account: from,
|
|
296
|
-
|
|
297
|
-
chain: getChain(this.config.chainId),
|
|
298
|
-
// Find the RPC in your ZeroDev dashboard
|
|
299
|
-
bundlerTransport: http(ZERODEV_RPC),
|
|
300
|
-
// Required - the public client
|
|
301
|
-
client: this.contract.publicClient,
|
|
302
|
-
// Optional -- only if you want to use a paymaster
|
|
303
|
-
paymaster: {
|
|
304
|
-
getPaymasterData: (userOperation) => {
|
|
305
|
-
return zerodevPaymaster.sponsorUserOperation({
|
|
306
|
-
userOperation,
|
|
307
|
-
});
|
|
308
|
-
},
|
|
309
|
-
},
|
|
310
|
-
});
|
|
311
|
-
const data = encodeFunctionData({ abi: this.contract.abi, functionName: name, args });
|
|
312
|
-
kernelClient.estimateUserOperationGas({
|
|
313
|
-
callData: await kernelClient.account.encodeCalls([
|
|
314
|
-
{
|
|
315
|
-
to: this.address,
|
|
316
|
-
value: txparams.value || 0n,
|
|
317
|
-
data,
|
|
318
|
-
},
|
|
319
|
-
]),
|
|
289
|
+
await this.client.public.simulateContract({
|
|
290
|
+
address: this.address,
|
|
291
|
+
abi: this.contract.abi,
|
|
292
|
+
functionName: name,
|
|
293
|
+
args,
|
|
294
|
+
account: from.address,
|
|
295
|
+
...(txparams.value && { value: txparams.value }),
|
|
320
296
|
});
|
|
321
297
|
return true;
|
|
322
298
|
}
|
|
@@ -7,6 +7,7 @@ export declare class FixedPaymentTemplate extends ContractBase {
|
|
|
7
7
|
private TOKEN_APPROVE_ABI;
|
|
8
8
|
static getInstance(config: InstantiableConfig): Promise<FixedPaymentTemplate>;
|
|
9
9
|
order(planId: bigint, owner: Account | SmartAccount, creditsReceiver?: Address, numberOfPurchases?: bigint, txParams?: TxParameters): Promise<import("viem").TransactionReceipt | import("viem/account-abstraction").UserOperationReceipt>;
|
|
10
|
+
simulateOrder(planId: bigint, owner: Account | SmartAccount, creditsReceiver?: Address, numberOfPurchases?: bigint, txParams?: TxParameters): Promise<boolean>;
|
|
10
11
|
approveERC20(totalAmount: bigint, tokenAddress: Address, owner: Account | SmartAccount, txParams?: TxParameters): Promise<import("viem").TransactionReceipt | undefined>;
|
|
11
12
|
orderWithApprovals(planId: bigint, totalAmount: bigint, tokenAddress: Address, owner: Account | SmartAccount, creditsReceiver?: Address, numberOfPurchases?: bigint, txParams?: TxParameters): Promise<import("viem").TransactionReceipt | undefined>;
|
|
12
13
|
}
|
|
@@ -1 +1 @@
|
|
|
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,KAAK,CAChB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,eAAe,CAAC,EAAE,OAAO,EACzB,iBAAiB,SAAK,EACtB,QAAQ,C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AY,EAAE,OAAO,EACrB,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,QAAQ,CAAC,EAAE,YAAY;IAmBZ,kBAAkB,CAC7B,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,OAAO,EACrB,KAAK,EAAE,OAAO,GAAG,YAAY,EAC7B,eAAe,CAAC,EAAE,OAAO,EACzB,iBAAiB,SAAK,EACtB,QAAQ,CAAC,EAAE,YAAY;CA0B1B"}
|
|
@@ -15,6 +15,10 @@ export class FixedPaymentTemplate extends ContractBase {
|
|
|
15
15
|
const agreementIdSeed = generateZeroXId();
|
|
16
16
|
return this.send('order', owner, [agreementIdSeed, planId, creditsReceiver || owner.address, numberOfPurchases, []], txParams);
|
|
17
17
|
}
|
|
18
|
+
async simulateOrder(planId, owner, creditsReceiver, numberOfPurchases = 1n, txParams) {
|
|
19
|
+
const agreementIdSeed = generateZeroXId();
|
|
20
|
+
return this.simulate('order', owner, [agreementIdSeed, planId, creditsReceiver || owner.address, numberOfPurchases, []], txParams);
|
|
21
|
+
}
|
|
18
22
|
async approveERC20(totalAmount, tokenAddress, owner, txParams) {
|
|
19
23
|
const calls = [
|
|
20
24
|
{
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { PublicClient } from 'viem';
|
|
2
|
+
import { SmartAccount } from 'viem/account-abstraction';
|
|
3
|
+
export type AgentX402AccessToken = {
|
|
4
|
+
x402Version: number;
|
|
5
|
+
scheme: string;
|
|
6
|
+
network: string;
|
|
7
|
+
payload: {
|
|
8
|
+
signature: `0x${string}`;
|
|
9
|
+
authorization: {
|
|
10
|
+
sessionKeysProvider: string;
|
|
11
|
+
sessionKeys: {
|
|
12
|
+
id: string;
|
|
13
|
+
data: string;
|
|
14
|
+
}[];
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export type NeverminedTypedDataDomain = {
|
|
19
|
+
name: 'Nevermined';
|
|
20
|
+
version: '1';
|
|
21
|
+
chainId: number;
|
|
22
|
+
verifyingContract: `0x${string}`;
|
|
23
|
+
};
|
|
24
|
+
export type NeverminedTypedData = {
|
|
25
|
+
SessionKey: [{
|
|
26
|
+
name: 'id';
|
|
27
|
+
type: 'string';
|
|
28
|
+
}, {
|
|
29
|
+
name: 'data';
|
|
30
|
+
type: 'string';
|
|
31
|
+
}];
|
|
32
|
+
SessionKeys: [{
|
|
33
|
+
name: 'sessionKeys';
|
|
34
|
+
type: 'SessionKey[]';
|
|
35
|
+
}];
|
|
36
|
+
Authorization: [
|
|
37
|
+
{
|
|
38
|
+
name: 'sessionKeysProvider';
|
|
39
|
+
type: 'string';
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'sessionKeys';
|
|
43
|
+
type: 'SessionKey[]';
|
|
44
|
+
}
|
|
45
|
+
];
|
|
46
|
+
};
|
|
47
|
+
export declare const NeverminedTypedDataTypes: NeverminedTypedData;
|
|
48
|
+
export type NeverminedTypedDataMessage = {
|
|
49
|
+
sessionKeysProvider: string;
|
|
50
|
+
sessionKeys: {
|
|
51
|
+
id: string;
|
|
52
|
+
data: string;
|
|
53
|
+
}[];
|
|
54
|
+
};
|
|
55
|
+
export declare const generateAgentX402AccessToken: (subscriber: SmartAccount, orderSessionKey: string, burnSessionKey: string, publicClient: PublicClient) => Promise<AgentX402AccessToken>;
|
|
56
|
+
export declare const verifyAgentX402AccessToken: (accessToken: AgentX402AccessToken, publicClient: PublicClient, subscriberAddress: `0x${string}`) => Promise<boolean>;
|
|
57
|
+
export declare const b64EncodeX402AccessToken: (accessToken: AgentX402AccessToken) => string;
|
|
58
|
+
export declare const b64DecodeX402AccessToken: (encoded: string) => AgentX402AccessToken;
|
|
59
|
+
//# sourceMappingURL=AgentX402AccessToken.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AgentX402AccessToken.d.ts","sourceRoot":"","sources":["../../src/models/AgentX402AccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,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AAM,CAAA;IAC3B,WAAW,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAA;CAC5C,CAAA;AAED,eAAO,MAAM,4BAA4B,GACvC,YAAY,YAAY,EACxB,iBAAiB,MAAM,EACvB,gBAAgB,MAAM,EACtB,cAAc,YAAY,KACzB,OAAO,CAAC,oBAAoB,CA+C9B,CAAA;AAED,eAAO,MAAM,0BAA0B,GACrC,aAAa,oBAAoB,EACjC,cAAc,YAAY,EAC1B,mBAAmB,KAAK,MAAM,EAAE,KAC/B,OAAO,CAAC,OAAO,CAiBjB,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,aAAa,oBAAoB,KAAG,MAE5E,CAAA;AAED,eAAO,MAAM,wBAAwB,GAAI,SAAS,MAAM,KAAG,oBAE1D,CAAA"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { keccak256, toBytes } from 'viem';
|
|
2
|
+
export const NeverminedTypedDataTypes = {
|
|
3
|
+
SessionKey: [
|
|
4
|
+
{ name: 'id', type: 'string' },
|
|
5
|
+
{ name: 'data', type: 'string' },
|
|
6
|
+
],
|
|
7
|
+
SessionKeys: [{ name: 'sessionKeys', type: 'SessionKey[]' }],
|
|
8
|
+
Authorization: [
|
|
9
|
+
{ name: 'sessionKeysProvider', type: 'string' },
|
|
10
|
+
{ name: 'sessionKeys', type: 'SessionKey[]' },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
13
|
+
export const generateAgentX402AccessToken = async (subscriber, orderSessionKey, burnSessionKey, publicClient) => {
|
|
14
|
+
// hash the session keys
|
|
15
|
+
const burnSessionKeyHash = keccak256(toBytes(burnSessionKey));
|
|
16
|
+
const orderSessionKeyHash = keccak256(toBytes(orderSessionKey));
|
|
17
|
+
// generate the message
|
|
18
|
+
const message = {
|
|
19
|
+
sessionKeysProvider: 'zerodev',
|
|
20
|
+
sessionKeys: [
|
|
21
|
+
{
|
|
22
|
+
id: 'order',
|
|
23
|
+
data: orderSessionKeyHash,
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
id: 'redeem',
|
|
27
|
+
data: burnSessionKeyHash,
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
};
|
|
31
|
+
const domain = {
|
|
32
|
+
name: 'Nevermined',
|
|
33
|
+
version: '1',
|
|
34
|
+
chainId: publicClient.chain?.id,
|
|
35
|
+
verifyingContract: subscriber.address,
|
|
36
|
+
};
|
|
37
|
+
// generate the eip712 data
|
|
38
|
+
const eip712Data = {
|
|
39
|
+
domain,
|
|
40
|
+
types: NeverminedTypedDataTypes,
|
|
41
|
+
primaryType: 'Authorization',
|
|
42
|
+
message,
|
|
43
|
+
};
|
|
44
|
+
const signature = await subscriber.signTypedData(eip712Data);
|
|
45
|
+
return {
|
|
46
|
+
x402Version: 2,
|
|
47
|
+
scheme: 'contract',
|
|
48
|
+
network: publicClient.chain?.name,
|
|
49
|
+
payload: {
|
|
50
|
+
signature,
|
|
51
|
+
authorization: message,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
export const verifyAgentX402AccessToken = async (accessToken, publicClient, subscriberAddress) => {
|
|
56
|
+
const domain = {
|
|
57
|
+
name: 'Nevermined',
|
|
58
|
+
version: '1',
|
|
59
|
+
chainId: publicClient.chain?.id,
|
|
60
|
+
verifyingContract: subscriberAddress,
|
|
61
|
+
};
|
|
62
|
+
const { signature, authorization } = accessToken.payload;
|
|
63
|
+
const isValid = await publicClient.verifyTypedData({
|
|
64
|
+
address: subscriberAddress,
|
|
65
|
+
signature,
|
|
66
|
+
types: NeverminedTypedDataTypes,
|
|
67
|
+
domain,
|
|
68
|
+
message: authorization,
|
|
69
|
+
primaryType: 'Authorization',
|
|
70
|
+
});
|
|
71
|
+
return isValid;
|
|
72
|
+
};
|
|
73
|
+
export const b64EncodeX402AccessToken = (accessToken) => {
|
|
74
|
+
return Buffer.from(JSON.stringify(accessToken)).toString('base64');
|
|
75
|
+
};
|
|
76
|
+
export const b64DecodeX402AccessToken = (encoded) => {
|
|
77
|
+
return JSON.parse(Buffer.from(encoded, 'base64').toString('utf-8'));
|
|
78
|
+
};
|
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;AACjC,cAAc,uBAAuB,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;AACrC,cAAc,2BAA2B,CAAA"}
|
package/dist/models/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PaymentsApi.d.ts","sourceRoot":"","sources":["../../../src/nevermined/api/PaymentsApi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAA8B,MAAM,uBAAuB,CAAA;AACrF,OAAO,EAAE,OAAO,EAAE,OAAO,EAAoC,MAAM,MAAM,CAAA;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAA;AAOjF,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,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAChD,aAAa,EAAE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EAAE,MAAM,EACd,YAAY,EAAE,OAAO,EACrB,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,iBAAiB,SAAK,GACrB,OAAO,CAAC,WAAW,CAAC;IA0BV,eAAe,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,YAAY,EAC5B,YAAY,CAAC,EAAE,OAAO,EACtB,iBAAiB,SAAK,GACrB,OAAO,CAAC,WAAW,CAAC;IAKV,mBAAmB,CAC9B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,GAAG,YAAY,GAC3B,OAAO,CAAC,WAAW,CAAC;YAKT,gBAAgB;CAqH/B"}
|
|
@@ -89,14 +89,12 @@ export class PaymentsApi extends Instantiable {
|
|
|
89
89
|
this.logger.debug(`Setting up Fixed Payment order...`);
|
|
90
90
|
return this._orderCryptoPlan(planId, plan, from, 'fixed', planReceiver, numberOfPurchases);
|
|
91
91
|
}
|
|
92
|
-
// simulateCreditsRedemption
|
|
93
92
|
async orderPayAsYouGoPlan(planId, plan, from) {
|
|
94
93
|
this.logger.debug(`Setting up Pay-As-You-Go order...`);
|
|
95
94
|
return this._orderCryptoPlan(planId, plan, from, 'payAsYouGo');
|
|
96
95
|
}
|
|
97
96
|
async _orderCryptoPlan(planId, plan, from, planType, planReceiver, numberOfPurchases = 1n) {
|
|
98
97
|
try {
|
|
99
|
-
// const plan = await this.nevermined.contracts.assetRegistry.getPlan(planId)
|
|
100
98
|
const tokenAddress = plan.price.tokenAddress;
|
|
101
99
|
const totalAmount = plan.price.amounts.reduce((a, b) => a + b, 0n) * numberOfPurchases;
|
|
102
100
|
this.logger.debug(`Ordering ${tokenAddress} ${totalAmount}`);
|
|
@@ -260,6 +260,17 @@ export declare function getApproval(signer: Signer, publicClient: any, policies:
|
|
|
260
260
|
export declare function useSessionKey(approval: string, signer: Signer, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
|
|
261
261
|
export declare function createSessionKey(signer: Signer, publicClient: any, policies: any[]): Promise<string>;
|
|
262
262
|
export declare function getSessionKey(serializedSessionKey: string, publicClient: any): Promise<import("@zerodev/sdk").CreateKernelAccountReturnType<"0.7">>;
|
|
263
|
+
/**
|
|
264
|
+
* Creates a delegated session key for an existing kernel account.
|
|
265
|
+
* The resulting serialized session key can be deserialized into a SmartAccount
|
|
266
|
+
* that shares the same address as the kernel account but enforces the given policies.
|
|
267
|
+
*
|
|
268
|
+
* @param kernelAccount The existing SmartAccount (kernel) to delegate from
|
|
269
|
+
* @param publicClient Viem PublicClient instance
|
|
270
|
+
* @param policies Array of policies to enforce for this session key
|
|
271
|
+
* @returns Serialized session key string
|
|
272
|
+
*/
|
|
273
|
+
export declare function createDelegatedSessionKeyFromKernel(kernelAccount: SmartAccount, publicClient: PublicClient, policies: any[]): Promise<string>;
|
|
263
274
|
export declare const WalletUtils: {
|
|
264
275
|
makeWallet: typeof makeWallet;
|
|
265
276
|
makeWallets: typeof makeWallets;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BlockchainViemUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/BlockchainViemUtils.ts"],"names":[],"mappings":"AAOA,OAAO,EAML,mBAAmB,
|
|
1
|
+
{"version":3,"file":"BlockchainViemUtils.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/BlockchainViemUtils.ts"],"names":[],"mappings":"AAOA,OAAO,EAML,mBAAmB,EAEpB,MAAM,cAAc,CAAA;AAErB,OAAO,EACL,OAAO,EAaP,KAAK,GAAG,EACR,KAAK,QAAQ,EACb,KAAK,WAAW,EAChB,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACxB,MAAM,MAAM,CAAA;AACb,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAQvD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,gCAAg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BAAmB,CAAC,CAyB9B;AAED,wBAAsB,wBAAwB,CAC5C,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,YAAY,CAAC,CAcvB;AAED,wBAAsB,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,mBAyBnF;AAED,wBAAsB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,wEAatF;AAED,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,EAAE,mBA6BxF;AAED,wBAAsB,aAAa,CAAC,oBAAoB,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,wEASlF;AAED;;;;;;;;;GASG;AACH,wBAAsB,mCAAmC,CACvD,aAAa,EAAE,YAAY,EAC3B,YAAY,EAAE,YAAY,EAC1B,QAAQ,EAAE,GAAG,EAAE,GACd,OAAO,CAAC,MAAM,CAAC,CAsCjB;AAED,eAAO,MAAM,WAAW;;;;;CAKvB,CAAA"}
|
|
@@ -358,6 +358,48 @@ export async function getSessionKey(serializedSessionKey, publicClient) {
|
|
|
358
358
|
const sessionKeyAccount = await deserializePermissionAccount(publicClient, getEntryPoint(ENTRY_POINT_VERSION), KERNEL_V3_1, serializedSessionKey);
|
|
359
359
|
return sessionKeyAccount;
|
|
360
360
|
}
|
|
361
|
+
/**
|
|
362
|
+
* Creates a delegated session key for an existing kernel account.
|
|
363
|
+
* The resulting serialized session key can be deserialized into a SmartAccount
|
|
364
|
+
* that shares the same address as the kernel account but enforces the given policies.
|
|
365
|
+
*
|
|
366
|
+
* @param kernelAccount The existing SmartAccount (kernel) to delegate from
|
|
367
|
+
* @param publicClient Viem PublicClient instance
|
|
368
|
+
* @param policies Array of policies to enforce for this session key
|
|
369
|
+
* @returns Serialized session key string
|
|
370
|
+
*/
|
|
371
|
+
export async function createDelegatedSessionKeyFromKernel(kernelAccount, publicClient, policies) {
|
|
372
|
+
// 1) Generate ephemeral session private key (used only for the permission plugin)
|
|
373
|
+
const sessionPrivateKey = generatePrivateKey();
|
|
374
|
+
const sessionAccount = privateKeyToAccount(sessionPrivateKey);
|
|
375
|
+
// 2) Wrap ephemeral key as ECDSA signer for permissions
|
|
376
|
+
const sessionKeySigner = await toECDSASigner({ signer: sessionAccount });
|
|
377
|
+
// 3) Create the permission validator plugin
|
|
378
|
+
const permissionValidator = await toPermissionValidator(publicClient, {
|
|
379
|
+
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
380
|
+
signer: sessionKeySigner,
|
|
381
|
+
policies,
|
|
382
|
+
kernelVersion: KERNEL_V3_1,
|
|
383
|
+
});
|
|
384
|
+
// 4) Extract the sudo validator from the existing kernel account
|
|
385
|
+
const kernelAccountTyped = kernelAccount;
|
|
386
|
+
const sudoValidator = kernelAccountTyped.kernelPluginManager.sudoValidator;
|
|
387
|
+
if (!sudoValidator) {
|
|
388
|
+
throw new Error('Kernel account does not have a sudo validator');
|
|
389
|
+
}
|
|
390
|
+
// 5) Create a new kernel account with both sudo (from original) and permission validator
|
|
391
|
+
const sessionKeyAccount = await createKernelAccount(publicClient, {
|
|
392
|
+
entryPoint: getEntryPoint(ENTRY_POINT_VERSION),
|
|
393
|
+
plugins: {
|
|
394
|
+
sudo: sudoValidator, // Use existing sudo validator
|
|
395
|
+
regular: permissionValidator,
|
|
396
|
+
},
|
|
397
|
+
kernelVersion: KERNEL_V3_1,
|
|
398
|
+
});
|
|
399
|
+
// 6) Serialize the session key account with the ephemeral private key
|
|
400
|
+
const serialized = await serializePermissionAccount(sessionKeyAccount, sessionPrivateKey);
|
|
401
|
+
return serialized;
|
|
402
|
+
}
|
|
361
403
|
export const WalletUtils = {
|
|
362
404
|
makeWallet,
|
|
363
405
|
makeWallets,
|
|
@@ -1,19 +1,36 @@
|
|
|
1
1
|
import { Abi } from 'viem';
|
|
2
|
-
|
|
2
|
+
import { Policy } from '@zerodev/permissions';
|
|
3
|
+
export declare function getPolicy(permissions: any[]): Policy;
|
|
3
4
|
export declare function getPermissions(config: any, functionNames: string[]): any[];
|
|
4
5
|
export declare function getERC20ApprovePermissions(contractAddress: `0x${string}`): {
|
|
5
6
|
target: `0x${string}`;
|
|
6
7
|
abi: Abi;
|
|
7
8
|
functionName: string;
|
|
8
9
|
};
|
|
9
|
-
export declare const getERC20ApprovePolicy: (contractAddress: `0x${string}`) =>
|
|
10
|
-
export declare const getAgentRegistrationPolicy: () =>
|
|
11
|
-
export declare const getPricingPlanRegistrationPolicy: () =>
|
|
12
|
-
export declare const getRegisterAssetsPolicy: () =>
|
|
13
|
-
export declare const getOrderPolicy: () =>
|
|
14
|
-
export declare const getMintNFTPolicy: () =>
|
|
15
|
-
export declare const getBurnNFTPolicy: () =>
|
|
16
|
-
export declare const getRegisterPolicy: () =>
|
|
17
|
-
export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) =>
|
|
18
|
-
export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) =>
|
|
10
|
+
export declare const getERC20ApprovePolicy: (contractAddress: `0x${string}`) => Policy;
|
|
11
|
+
export declare const getAgentRegistrationPolicy: () => Policy;
|
|
12
|
+
export declare const getPricingPlanRegistrationPolicy: () => Policy;
|
|
13
|
+
export declare const getRegisterAssetsPolicy: () => Policy;
|
|
14
|
+
export declare const getOrderPolicy: () => Policy;
|
|
15
|
+
export declare const getMintNFTPolicy: () => Policy;
|
|
16
|
+
export declare const getBurnNFTPolicy: () => Policy;
|
|
17
|
+
export declare const getRegisterPolicy: () => Policy;
|
|
18
|
+
export declare const buildPolicy: (permissions: string[], contractAddress: `0x${string}`) => Policy;
|
|
19
|
+
export declare const getAllContractsPolicy: (contractAddress: `0x${string}`) => Policy;
|
|
20
|
+
export type BurnPolicyOptions = {
|
|
21
|
+
contractAddress: `0x${string}`;
|
|
22
|
+
planId: bigint;
|
|
23
|
+
subscriberAddress: `0x${string}`;
|
|
24
|
+
maxAmount: bigint;
|
|
25
|
+
count?: number;
|
|
26
|
+
};
|
|
27
|
+
export declare const getZeroDevBurnPolicies: (burnPolicyOptions: BurnPolicyOptions) => Policy[];
|
|
28
|
+
export type OrderPolicyOptions = {
|
|
29
|
+
contractAddress: `0x${string}`;
|
|
30
|
+
planId: bigint;
|
|
31
|
+
subscriberAddress: `0x${string}`;
|
|
32
|
+
numberOfPurchases: bigint;
|
|
33
|
+
count?: number;
|
|
34
|
+
};
|
|
35
|
+
export declare const getZeroDevOrderPolicies: (orderPolicyOptions: OrderPolicyOptions) => Policy[];
|
|
19
36
|
//# sourceMappingURL=ZeroDevPolicies.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ZeroDevPolicies.d.ts","sourceRoot":"","sources":["../../../src/nevermined/utils/ZeroDevPolicies.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,GAAG,EAAY,MAAM,MAAM,CAAA;AACpC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAE7C,wBAAgB,SAAS,CAAC,WAAW,EAAE,GAAG,EAAE,UAK3C;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,EAAE,SAelE;AAED,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,KAAK,MAAM,EAAE;;SAK/D,GAAG;;EAGZ;AACD,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WACV,CAAA;AAE1D,eAAO,MAAM,0BAA0B,cACwB,CAAA;AAE/D,eAAO,MAAM,gCAAgC,cAC2C,CAAA;AAExF,eAAO,MAAM,uBAAuB,cACuC,CAAA;AAE3E,eAAO,MAAM,cAAc,cAM1B,CAAA;AAED,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,gBAAgB,cAAkE,CAAA;AAE/F,eAAO,MAAM,iBAAiB,cAU3B,CAAA;AAEH,eAAO,MAAM,WAAW,GAAI,aAAa,MAAM,EAAE,EAAE,iBAAiB,KAAK,MAAM,EAAE,WAmBhF,CAAA;AAED,eAAO,MAAM,qBAAqB,GAAI,iBAAiB,KAAK,MAAM,EAAE,WAejE,CAAA;AAEH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,eAAe,EAAE,KAAK,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,sBAAsB,GAAI,mBAAmB,iBAAiB,KAAG,MAAM,EAkCnF,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,KAAK,MAAM,EAAE,CAAA;IAC9B,MAAM,EAAE,MAAM,CAAA;IACd,iBAAiB,EAAE,KAAK,MAAM,EAAE,CAAA;IAChC,iBAAiB,EAAE,MAAM,CAAA;IACzB,KAAK,CAAC,EAAE,MAAM,CAAA;CACf,CAAA;AAED,eAAO,MAAM,uBAAuB,GAAI,oBAAoB,kBAAkB,KAAG,MAAM,EAmCtF,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallPolicyVersion, toCallPolicy } from '@zerodev/permissions/policies';
|
|
1
|
+
import { CallPolicyVersion, ParamCondition, toCallPolicy, toRateLimitPolicy, } from '@zerodev/permissions/policies';
|
|
2
2
|
import { assetsRegistryConfig, fixedPaymentTemplateConfig, nft1155CreditsConfig, payAsYouGoTemplateAddress, } from '../../artifacts/generated.js';
|
|
3
3
|
import { parseAbi } from 'viem';
|
|
4
4
|
export function getPolicy(permissions) {
|
|
@@ -83,3 +83,70 @@ export const getAllContractsPolicy = (contractAddress) => getPolicy([
|
|
|
83
83
|
...getPermissions(nft1155CreditsConfig, ['mint', 'burn']),
|
|
84
84
|
getERC20ApprovePermissions(contractAddress),
|
|
85
85
|
].filter(Boolean));
|
|
86
|
+
export const getZeroDevBurnPolicies = (burnPolicyOptions) => {
|
|
87
|
+
const policies = [];
|
|
88
|
+
const burnPolicy = {
|
|
89
|
+
target: burnPolicyOptions.contractAddress,
|
|
90
|
+
abi: parseAbi([
|
|
91
|
+
'function burn(address _from, uint256 _planId, uint256 _value, uint256 _keyspace, bytes calldata _signature) external',
|
|
92
|
+
]),
|
|
93
|
+
valueLimit: 0n,
|
|
94
|
+
functionName: 'burn',
|
|
95
|
+
args: [
|
|
96
|
+
{
|
|
97
|
+
condition: ParamCondition.EQUAL,
|
|
98
|
+
value: burnPolicyOptions.subscriberAddress,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
condition: ParamCondition.EQUAL,
|
|
102
|
+
value: '0x' + burnPolicyOptions.planId.toString(16).padStart(64, '0'),
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
condition: ParamCondition.LESS_THAN_OR_EQUAL,
|
|
106
|
+
value: burnPolicyOptions.maxAmount,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
};
|
|
110
|
+
policies.push(getPolicy([burnPolicy]));
|
|
111
|
+
if (burnPolicyOptions.count) {
|
|
112
|
+
const rateLimitPolicy = toRateLimitPolicy({
|
|
113
|
+
count: burnPolicyOptions.count,
|
|
114
|
+
});
|
|
115
|
+
policies.push(rateLimitPolicy);
|
|
116
|
+
}
|
|
117
|
+
return policies;
|
|
118
|
+
};
|
|
119
|
+
export const getZeroDevOrderPolicies = (orderPolicyOptions) => {
|
|
120
|
+
const policies = [];
|
|
121
|
+
const orderCallPolicy = {
|
|
122
|
+
target: orderPolicyOptions.contractAddress,
|
|
123
|
+
abi: parseAbi([
|
|
124
|
+
'function order(bytes32 _seed, uint256 _planId, address _creditsReceiver, uint256 _numberOfPurchases, bytes[] memory _params) external payable',
|
|
125
|
+
]),
|
|
126
|
+
valueLimit: 0n,
|
|
127
|
+
functionName: 'order',
|
|
128
|
+
args: [
|
|
129
|
+
null,
|
|
130
|
+
{
|
|
131
|
+
condition: ParamCondition.EQUAL,
|
|
132
|
+
value: '0x' + orderPolicyOptions.planId.toString(16).padStart(64, '0'),
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
condition: ParamCondition.EQUAL,
|
|
136
|
+
value: orderPolicyOptions.subscriberAddress,
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
condition: ParamCondition.EQUAL,
|
|
140
|
+
value: orderPolicyOptions.numberOfPurchases,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
};
|
|
144
|
+
policies.push(getPolicy([orderCallPolicy]));
|
|
145
|
+
if (orderPolicyOptions.count) {
|
|
146
|
+
const rateLimitPolicy = toRateLimitPolicy({
|
|
147
|
+
count: orderPolicyOptions.count,
|
|
148
|
+
});
|
|
149
|
+
policies.push(rateLimitPolicy);
|
|
150
|
+
}
|
|
151
|
+
return policies;
|
|
152
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nevermined-io/core-kit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"e2e": {
|
|
30
30
|
"executor": "nx:run-commands",
|
|
31
31
|
"options": {
|
|
32
|
-
"command": "
|
|
32
|
+
"command": "tsx ../../node_modules/.bin/mocha --config ./tests/integration/.mocharc.json",
|
|
33
33
|
"cwd": "packages/core-kit"
|
|
34
34
|
},
|
|
35
35
|
"dependsOn": [
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"e2e:external": {
|
|
46
46
|
"executor": "nx:run-commands",
|
|
47
47
|
"options": {
|
|
48
|
-
"command": "
|
|
48
|
+
"command": "tsx ../../node_modules/.bin/mocha --config ./tests/external/.mocharc.json",
|
|
49
49
|
"cwd": "packages/core-kit"
|
|
50
50
|
},
|
|
51
51
|
"dependsOn": [
|