@nevermined-io/core-kit 0.4.5 → 0.5.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.
Files changed (105) hide show
  1. package/dist/Instantiable.abstract.js +15 -13
  2. package/dist/Instantiable.abstract.js.map +1 -0
  3. package/dist/artifacts/generated.d.ts +174 -40
  4. package/dist/artifacts/generated.d.ts.map +1 -1
  5. package/dist/artifacts/generated.js +22805 -7111
  6. package/dist/artifacts/generated.js.map +1 -0
  7. package/dist/contracts/AccessManager.js +12 -3
  8. package/dist/contracts/AccessManager.js.map +1 -0
  9. package/dist/contracts/AssetRegistry.d.ts +1 -0
  10. package/dist/contracts/AssetRegistry.d.ts.map +1 -1
  11. package/dist/contracts/AssetRegistry.js +134 -69
  12. package/dist/contracts/AssetRegistry.js.map +1 -0
  13. package/dist/contracts/ContractBase.d.ts.map +1 -1
  14. package/dist/contracts/ContractBase.js +173 -140
  15. package/dist/contracts/ContractBase.js.map +1 -0
  16. package/dist/contracts/ContractsApi.js +6 -54
  17. package/dist/contracts/ContractsApi.js.map +1 -0
  18. package/dist/contracts/CryptoTemplateBase.js +23 -11
  19. package/dist/contracts/CryptoTemplateBase.js.map +1 -0
  20. package/dist/contracts/FiatPaymentTemplate.js +9 -1
  21. package/dist/contracts/FiatPaymentTemplate.js.map +1 -0
  22. package/dist/contracts/FiatSettlementCondition.js +8 -1
  23. package/dist/contracts/FiatSettlementCondition.js.map +1 -0
  24. package/dist/contracts/FixedPaymentTemplate.js +42 -10
  25. package/dist/contracts/FixedPaymentTemplate.js.map +1 -0
  26. package/dist/contracts/NFT1155Base.js +48 -12
  27. package/dist/contracts/NFT1155Base.js.map +1 -0
  28. package/dist/contracts/NFT1155Credits.js +2 -0
  29. package/dist/contracts/NFT1155Credits.js.map +1 -0
  30. package/dist/contracts/NFT1155ExpirableCredits.js +26 -6
  31. package/dist/contracts/NFT1155ExpirableCredits.js.map +1 -0
  32. package/dist/contracts/NVMConfig.js +2 -0
  33. package/dist/contracts/NVMConfig.js.map +1 -0
  34. package/dist/contracts/PayAsYouGoTemplate.js +36 -10
  35. package/dist/contracts/PayAsYouGoTemplate.js.map +1 -0
  36. package/dist/contracts/ProtocolStandardFees.js +7 -1
  37. package/dist/contracts/ProtocolStandardFees.js.map +1 -0
  38. package/dist/contracts/Roles.js +2 -0
  39. package/dist/contracts/Roles.js.map +1 -0
  40. package/dist/contracts/index.js +2 -0
  41. package/dist/contracts/index.js.map +1 -0
  42. package/dist/errors/NeverminedErrors.js +27 -26
  43. package/dist/errors/NeverminedErrors.js.map +1 -0
  44. package/dist/errors/index.js +2 -0
  45. package/dist/errors/index.js.map +1 -0
  46. package/dist/index.js +2 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/models/AgentX402AccessToken.js +78 -46
  49. package/dist/models/AgentX402AccessToken.js.map +1 -0
  50. package/dist/models/Logger.js +12 -12
  51. package/dist/models/Logger.js.map +1 -0
  52. package/dist/models/NeverminedOptions.d.ts +3 -3
  53. package/dist/models/NeverminedOptions.d.ts.map +1 -1
  54. package/dist/models/NeverminedOptions.js +3 -28
  55. package/dist/models/NeverminedOptions.js.map +1 -0
  56. package/dist/models/NvmApiKey.js +96 -147
  57. package/dist/models/NvmApiKey.js.map +1 -0
  58. package/dist/models/Transactions.js +3 -1
  59. package/dist/models/Transactions.js.map +1 -0
  60. package/dist/models/index.js +2 -0
  61. package/dist/models/index.js.map +1 -0
  62. package/dist/nevermined/Nevermined.js +20 -42
  63. package/dist/nevermined/Nevermined.js.map +1 -0
  64. package/dist/nevermined/api/PaymentsApi.js +38 -43
  65. package/dist/nevermined/api/PaymentsApi.js.map +1 -0
  66. package/dist/nevermined/api/ServicesApi.js +7 -15
  67. package/dist/nevermined/api/ServicesApi.js.map +1 -0
  68. package/dist/nevermined/api/UtilsApi.js +7 -19
  69. package/dist/nevermined/api/UtilsApi.js.map +1 -0
  70. package/dist/nevermined/index.js +2 -0
  71. package/dist/nevermined/index.js.map +1 -0
  72. package/dist/nevermined/utils/AgentUtils.js +25 -23
  73. package/dist/nevermined/utils/AgentUtils.js.map +1 -0
  74. package/dist/nevermined/utils/AnvilHelpers.js +34 -19
  75. package/dist/nevermined/utils/AnvilHelpers.js.map +1 -0
  76. package/dist/nevermined/utils/BlockchainViemUtils.d.ts +4 -4
  77. package/dist/nevermined/utils/BlockchainViemUtils.js +102 -108
  78. package/dist/nevermined/utils/BlockchainViemUtils.js.map +1 -0
  79. package/dist/nevermined/utils/JwtUtils.js +33 -28
  80. package/dist/nevermined/utils/JwtUtils.js.map +1 -0
  81. package/dist/nevermined/utils/SignatureUtils.js +23 -27
  82. package/dist/nevermined/utils/SignatureUtils.js.map +1 -0
  83. package/dist/nevermined/utils/WebServiceConnector.js +18 -20
  84. package/dist/nevermined/utils/WebServiceConnector.js.map +1 -0
  85. package/dist/nevermined/utils/ZeroDevPolicies.js +115 -75
  86. package/dist/nevermined/utils/ZeroDevPolicies.js.map +1 -0
  87. package/dist/nevermined/utils/index.js +2 -0
  88. package/dist/nevermined/utils/index.js.map +1 -0
  89. package/dist/services/Api.js +11 -5
  90. package/dist/services/Api.js.map +1 -0
  91. package/dist/services/Profiles.js +15 -20
  92. package/dist/services/Profiles.js.map +1 -0
  93. package/dist/services/index.js +2 -0
  94. package/dist/services/index.js.map +1 -0
  95. package/dist/utils/ConversionTypeHelpers.js +13 -6
  96. package/dist/utils/ConversionTypeHelpers.js.map +1 -0
  97. package/dist/utils/DeploymentInfo.js +12 -7
  98. package/dist/utils/DeploymentInfo.js.map +1 -0
  99. package/dist/utils/Network.js +27 -19
  100. package/dist/utils/Network.js.map +1 -0
  101. package/dist/utils/helpers.js +42 -31
  102. package/dist/utils/helpers.js.map +1 -0
  103. package/dist/utils/index.js +2 -0
  104. package/dist/utils/index.js.map +1 -0
  105. package/package.json +17 -1
@@ -1,27 +1,27 @@
1
1
  import { pino } from 'pino';
2
2
  let loggerInstance;
3
- export const createLogger = (config = {}) => {
3
+ export const createLogger = (config = {})=>{
4
4
  const { level = 'info', pretty = false } = config;
5
5
  return pino({
6
6
  level,
7
- transport: pretty
8
- ? {
9
- target: 'pino-pretty',
10
- options: {
11
- colorize: true,
12
- translateTime: 'HH:MM:ss',
13
- ignore: 'pid,hostname',
14
- },
7
+ transport: pretty ? {
8
+ target: 'pino-pretty',
9
+ options: {
10
+ colorize: true,
11
+ translateTime: 'HH:MM:ss',
12
+ ignore: 'pid,hostname'
15
13
  }
16
- : undefined,
14
+ } : undefined
17
15
  });
18
16
  };
19
- export const LoggerInstance = () => {
17
+ export const LoggerInstance = ()=>{
20
18
  if (!loggerInstance) {
21
19
  loggerInstance = createLogger({
22
20
  level: 'debug',
23
- pretty: true,
21
+ pretty: true
24
22
  });
25
23
  }
26
24
  return loggerInstance;
27
25
  };
26
+
27
+ //# sourceMappingURL=Logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/Logger.ts"],"sourcesContent":["import { pino, Logger as PinoLogger } from 'pino'\n\nexport type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent'\n\nexport interface LoggerConfig {\n level?: LogLevel\n pretty?: boolean\n}\n\nlet loggerInstance: PinoLogger | undefined\n\nexport const createLogger = (config: LoggerConfig = {}) => {\n const { level = 'info', pretty = false } = config\n\n return pino({\n level,\n transport: pretty\n ? {\n target: 'pino-pretty',\n options: {\n colorize: true,\n translateTime: 'HH:MM:ss',\n ignore: 'pid,hostname',\n },\n }\n : undefined,\n })\n}\n\nexport const LoggerInstance = () => {\n if (!loggerInstance) {\n loggerInstance = createLogger({\n level: 'debug',\n pretty: true,\n })\n }\n return loggerInstance\n}\n"],"names":["pino","loggerInstance","createLogger","config","level","pretty","transport","target","options","colorize","translateTime","ignore","undefined","LoggerInstance"],"mappings":"AAAA,SAASA,IAAI,QAA8B,OAAM;AASjD,IAAIC;AAEJ,OAAO,MAAMC,eAAe,CAACC,SAAuB,CAAC,CAAC;IACpD,MAAM,EAAEC,QAAQ,MAAM,EAAEC,SAAS,KAAK,EAAE,GAAGF;IAE3C,OAAOH,KAAK;QACVI;QACAE,WAAWD,SACP;YACEE,QAAQ;YACRC,SAAS;gBACPC,UAAU;gBACVC,eAAe;gBACfC,QAAQ;YACV;QACF,IACAC;IACN;AACF,EAAC;AAED,OAAO,MAAMC,iBAAiB;IAC5B,IAAI,CAACZ,gBAAgB;QACnBA,iBAAiBC,aAAa;YAC5BE,OAAO;YACPC,QAAQ;QACV;IACF;IACA,OAAOJ;AACT,EAAC"}
@@ -1,5 +1,5 @@
1
1
  import { Account } from 'viem';
2
- export declare class NeverminedOptions {
2
+ export interface NeverminedOptions {
3
3
  chainId: number;
4
4
  /**
5
5
  * Ethereum Web3 Provider URL. This Url allows the SDK to connect to a blockchain.
@@ -14,9 +14,9 @@ export declare class NeverminedOptions {
14
14
  backendUrl?: string;
15
15
  agentsProxy?: string;
16
16
  /**
17
- * Log level.
17
+ * Log level. Defaults to `'info'` when consumed by `Instantiable.abstract.ts`.
18
18
  */
19
- logLevel: string;
19
+ logLevel?: string;
20
20
  accounts?: Account[];
21
21
  /**
22
22
  * ZeroDev project id
@@ -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;IAEnB,WAAW,CAAC,EAAE,MAAM,CAAA;IAE3B;;OAEG;IACI,QAAQ,SAAS;IAEjB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IAE3B;;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,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,MAAM,CAAA;IACf;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,UAAU,CAAC,EAAE,MAAM,CAAA;IAEnB,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IAEjB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IAEpB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEzB;;OAEG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAA;CAC1B"}
@@ -1,28 +1,3 @@
1
- export class NeverminedOptions {
2
- chainId;
3
- /**
4
- * Ethereum Web3 Provider URL. This Url allows the SDK to connect to a blockchain.
5
- * This provider depends on the network where you want to connect (Ethereum Mainnet, Rinkeby, Polygon Matic, etc).
6
- * It's possible to use a public available provider or a private/paid one like Infura, Alchemy, etc.
7
- */
8
- web3ProviderUri;
9
- /**
10
- * The Nevermined App URL.
11
- */
12
- appUrl;
13
- backendUrl;
14
- agentsProxy;
15
- /**
16
- * Log level.
17
- */
18
- logLevel = 'info';
19
- accounts;
20
- /**
21
- * ZeroDev project id
22
- */
23
- zeroDevProjectId;
24
- /**
25
- * Contracts version
26
- */
27
- contractsVersion;
28
- }
1
+ export { };
2
+
3
+ //# sourceMappingURL=NeverminedOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/NeverminedOptions.ts"],"sourcesContent":["import { Account } from 'viem'\n\nexport interface NeverminedOptions {\n chainId: number\n /**\n * Ethereum Web3 Provider URL. This Url allows the SDK to connect to a blockchain.\n * This provider depends on the network where you want to connect (Ethereum Mainnet, Rinkeby, Polygon Matic, etc).\n * It's possible to use a public available provider or a private/paid one like Infura, Alchemy, etc.\n */\n web3ProviderUri?: string\n\n /**\n * The Nevermined App URL.\n */\n appUrl?: string\n\n backendUrl?: string\n\n agentsProxy?: string\n\n /**\n * Log level. Defaults to `'info'` when consumed by `Instantiable.abstract.ts`.\n */\n logLevel?: string\n\n accounts?: Account[]\n\n /**\n * ZeroDev project id\n */\n zeroDevProjectId?: string\n\n /**\n * Contracts version\n */\n contractsVersion?: string\n}\n"],"names":[],"mappings":"AAEA,WAkCC"}
@@ -6,60 +6,25 @@ import { SignatureUtils } from '../nevermined/utils/SignatureUtils.js';
6
6
  import { decryptMessage, encryptMessage, urlSafeBase64Decode } from '../utils/helpers.js';
7
7
  export class NvmApiKey {
8
8
  /**
9
- * The public address of the account issuing the key.
10
- */
11
- iss;
12
- /**
13
- * The chain id of the network the key is valid for. If zero the key is not having any network limitation
14
- */
15
- aud;
16
- /**
17
- * The public address of the account the key is issued for.
18
- */
19
- sub;
20
- /**
21
- * The version of the key
22
- */
23
- ver = 'v1';
24
- /**
25
- * The ZeroDev session key
26
- */
27
- zsk;
28
- /**
29
- * The Marketplace auth token
30
- */
31
- // nvt?: string
32
- /**
33
- * JWT Expiration Time
34
- *
35
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
36
- */
37
- exp;
38
- /**
39
- * JWT Issued At
40
- *
41
- * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
42
- */
43
- iat;
44
- /**
45
- * It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
46
- * The string representing this key can be used to authenticate against the Nevermined API.
47
- * @param signatureUtils The SignatureUtils instance
48
- * @param issuerAccount The account issuing the key
49
- * @param zeroDevSessionKey The ZeroDev session key
50
- * @param receiverAddress The address of the account the key is issued for
51
- * @param receiverPublicKey The public key of the account the key is issued for
52
- * @param chainId The chain id of the network the key is valid for
53
- * @param additionalParams Addintional params to be added to the Key generated
54
- * @returns The encrypted string representing the @see {@link NvmApiKey}
55
- */
56
- static async generate(signatureUtils, issuerAccount, zeroDevSessionKey, receiverAddress, receiverPublicKey, expirationTime = '1y', additionalParams = {}, nvmApiKeyVersion = 'v1') {
9
+ * It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
10
+ * The string representing this key can be used to authenticate against the Nevermined API.
11
+ * @param signatureUtils The SignatureUtils instance
12
+ * @param issuerAccount The account issuing the key
13
+ * @param zeroDevSessionKey The ZeroDev session key
14
+ * @param receiverAddress The address of the account the key is issued for
15
+ * @param receiverPublicKey The public key of the account the key is issued for
16
+ * @param chainId The chain id of the network the key is valid for
17
+ * @param additionalParams Addintional params to be added to the Key generated
18
+ * @returns The encrypted string representing the @see {@link NvmApiKey}
19
+ */ static async generate(signatureUtils, issuerAccount, zeroDevSessionKey, receiverAddress, receiverPublicKey, expirationTime = '1y', additionalParams = {}, nvmApiKeyVersion = 'v1') {
57
20
  const issuerAddress = getChecksumAddress(issuerAccount.address);
58
21
  const chainId = signatureUtils.client.chain?.id || 0;
59
22
  const sub = getChecksumAddress(receiverAddress);
60
23
  const eip712Data = {
61
24
  message: 'Sign this message to generate the Encrypted Nevermined API Key',
62
- ...(chainId > 0 && { chainId }),
25
+ ...chainId > 0 && {
26
+ chainId
27
+ }
63
28
  };
64
29
  const params = {
65
30
  iss: issuerAddress,
@@ -68,168 +33,152 @@ export class NvmApiKey {
68
33
  ver: nvmApiKeyVersion,
69
34
  zsk: zeroDevSessionKey,
70
35
  eip712Data,
71
- ...additionalParams,
36
+ ...additionalParams
72
37
  };
73
- const signedJWT = await new EthSignJWT(params)
74
- .setProtectedHeader({ alg: 'ES256K' })
75
- .setIssuedAt()
76
- .setExpirationTime(expirationTime)
77
- .ethSign(signatureUtils, issuerAccount);
38
+ const signedJWT = await new EthSignJWT(params).setProtectedHeader({
39
+ alg: 'ES256K'
40
+ }).setIssuedAt().setExpirationTime(expirationTime).ethSign(signatureUtils, issuerAccount);
78
41
  return encryptMessage(signedJWT, receiverPublicKey);
79
42
  }
80
43
  /**
81
- * Given an encrypted JWT and a private key, it decrypts and decodes the JWT into a NvmApiKey
82
- * @param encryptedJwt The encrypted JWT
83
- * @param privateKey The private key representing the account
84
- * @returns The @see {@link NvmApiKey}
85
- */
86
- static async decryptAndDecode(encryptedJwt, privateKey) {
44
+ * Given an encrypted JWT and a private key, it decrypts and decodes the JWT into a NvmApiKey
45
+ * @param encryptedJwt The encrypted JWT
46
+ * @param privateKey The private key representing the account
47
+ * @returns The @see {@link NvmApiKey}
48
+ */ static async decryptAndDecode(encryptedJwt, privateKey) {
87
49
  const decrypted = await decryptMessage(encryptedJwt, privateKey);
88
50
  return NvmApiKey.fromJWT(decrypted);
89
51
  }
90
52
  /**
91
- * Given a signed JWT, it recovers the signer address
92
- * @param jwtString The signed JWT
93
- * @returns The signer address
94
- */
95
- static async getSignerAddress(jwtString) {
53
+ * Given a signed JWT, it recovers the signer address
54
+ * @param jwtString The signed JWT
55
+ * @returns The signer address
56
+ */ static async getSignerAddress(jwtString) {
96
57
  try {
97
58
  const tokens = jwtString.split('.');
98
59
  const signature = bytesToHex(urlSafeBase64Decode(tokens[2]));
99
60
  return SignatureUtils.recoverSignerAddress(`${tokens[0]}.${tokens[1]}`, signature);
100
- }
101
- catch (e) {
61
+ } catch (e) {
102
62
  if (e instanceof Error) {
103
63
  throw new Error(`Error recovering signer address: ${e.message}`);
104
- }
105
- else {
64
+ } else {
106
65
  throw new Error(`Error recovering signer address`);
107
66
  }
108
67
  }
109
68
  }
110
69
  /**
111
- * It checks if the NVM API Key attributes are valid
112
- * @param chainId The chain id of the network the key is valid for
113
- * @returns true if the key is valid, false otherwise
114
- */
115
- isValid(chainId = 0) {
70
+ * It checks if the NVM API Key attributes are valid
71
+ * @param chainId The chain id of the network the key is valid for
72
+ * @returns true if the key is valid, false otherwise
73
+ */ isValid(chainId = 0) {
116
74
  if (this.exp) {
117
75
  const now = new Date();
118
- if (now.getTime() > Number(this.exp) * 1000)
119
- return false;
76
+ if (now.getTime() > Number(this.exp) * 1000) return false;
120
77
  }
121
78
  if (chainId !== 0) {
122
- if (Number(this.aud) !== chainId)
123
- return false;
79
+ if (Number(this.aud) !== chainId) return false;
124
80
  }
125
81
  return true;
126
82
  }
127
83
  /**
128
- * It generates a signed JWT from the NvmApiKey
129
- * @param signatureUtils The SignatureUtils instance
130
- * @param issuerAccount The account issuing the key
131
- * @returns the string in JWT format represeting the NvmApiKey
132
- */
133
- async toJWT(signatureUtils, issuerAccount) {
84
+ * It generates a signed JWT from the NvmApiKey
85
+ * @param signatureUtils The SignatureUtils instance
86
+ * @param issuerAccount The account issuing the key
87
+ * @returns the string in JWT format represeting the NvmApiKey
88
+ */ async toJWT(signatureUtils, issuerAccount) {
134
89
  const params = {};
135
- Object.keys(this)
136
- .filter((val) => val !== undefined)
137
- .forEach((key) => {
138
- if (!key.startsWith('_'))
139
- params[key] = this[key];
90
+ Object.keys(this).filter((val)=>val !== undefined).forEach((key)=>{
91
+ if (!key.startsWith('_')) params[key] = this[key];
140
92
  });
141
- const jwt = new EthSignJWT(params).setProtectedHeader({ alg: 'ES256K' }).setIssuedAt(this.iat);
142
- if (this.exp)
143
- jwt.setExpirationTime(this.exp);
93
+ const jwt = new EthSignJWT(params).setProtectedHeader({
94
+ alg: 'ES256K'
95
+ }).setIssuedAt(this.iat);
96
+ if (this.exp) jwt.setExpirationTime(this.exp);
144
97
  return jwt.ethSign(signatureUtils, issuerAccount);
145
98
  }
146
99
  /**
147
- * It generates the hash in JWT format of the NvmApiKey
148
- * @param signatureUtils the SignatureUtils instance
149
- * @param issuerAccount the account issuing the key
150
- * @returns a JWT string representing the hash of the NvmApiKey
151
- */
152
- async hashJWT(signatureUtils, issuerAccount, heliconeApiKey) {
100
+ * It generates the hash in JWT format of the NvmApiKey
101
+ * @param signatureUtils the SignatureUtils instance
102
+ * @param issuerAccount the account issuing the key
103
+ * @returns a JWT string representing the hash of the NvmApiKey
104
+ */ async hashJWT(signatureUtils, issuerAccount, heliconeApiKey) {
153
105
  const issuerAddress = getChecksumAddress(issuerAccount.address);
154
- return (new EthSignJWT({
155
- iss: issuerAddress, // the account generating the hash (node/provider, etc) is the issuer of the hash
156
- sub: this.iss, // the issuer of the NVMApiKey (the user) is the subject of the hash
106
+ return new EthSignJWT({
107
+ iss: issuerAddress,
108
+ sub: this.iss,
157
109
  jti: this.hash(),
158
110
  exp: this.exp,
159
- o11y: heliconeApiKey,
160
- })
161
- .setProtectedHeader({ alg: 'ES256K' })
162
- // .setIssuedAt() // WARNING: If enabled, the hash will change for the same NvmApiKey
163
- .ethSign(signatureUtils, issuerAccount));
111
+ o11y: heliconeApiKey
112
+ }).setProtectedHeader({
113
+ alg: 'ES256K'
114
+ })// .setIssuedAt() // WARNING: If enabled, the hash will change for the same NvmApiKey
115
+ .ethSign(signatureUtils, issuerAccount);
164
116
  }
165
117
  /**
166
- * It regenerates the NvmApiKey from a JSON object
167
- * @param jwt JWTPayload in JSON format
168
- * @returns the @see {@link NvmApiKey}
169
- */
170
- static fromJSON(jwt) {
118
+ * It regenerates the NvmApiKey from a JSON object
119
+ * @param jwt JWTPayload in JSON format
120
+ * @returns the @see {@link NvmApiKey}
121
+ */ static fromJSON(jwt) {
171
122
  const nvmKey = new NvmApiKey();
172
123
  const str = JSON.stringify(jwt);
173
124
  const _obj = JSON.parse(str);
174
- Object.keys(_obj)
175
- .filter((val) => val !== undefined)
176
- .forEach((key) => {
125
+ Object.keys(_obj).filter((val)=>val !== undefined).forEach((key)=>{
177
126
  nvmKey[key] = _obj[key];
178
127
  });
179
128
  return nvmKey;
180
129
  }
181
130
  /**
182
- * It regenerates the NvmApiKey from a JWT
183
- * @param jwtString the string in JWT format represeting the NvmApiKey
184
- * @returns the @see {@link NvmApiKey}
185
- */
186
- static fromJWT(jwtString) {
131
+ * It regenerates the NvmApiKey from a JWT
132
+ * @param jwtString the string in JWT format represeting the NvmApiKey
133
+ * @returns the @see {@link NvmApiKey}
134
+ */ static fromJWT(jwtString) {
187
135
  const jwt = NvmApiKey.decodeJWT(jwtString);
188
136
  return NvmApiKey.fromJSON(jwt);
189
137
  }
190
138
  /**
191
- * It regenerates the NvmApiKey from a string
192
- * @param str the string represeting the NvmApiKey
193
- * @returns the @see {@link NvmApiKey}
194
- */
195
- static deserialize(str) {
139
+ * It regenerates the NvmApiKey from a string
140
+ * @param str the string represeting the NvmApiKey
141
+ * @returns the @see {@link NvmApiKey}
142
+ */ static deserialize(str) {
196
143
  return NvmApiKey.fromJSON(JSON.parse(str));
197
144
  }
198
145
  /**
199
- * It serializes the NVM Api Key into a string
200
- * @returns a string representing the NVM API Key
201
- */
202
- serialize() {
146
+ * It serializes the NVM Api Key into a string
147
+ * @returns a string representing the NVM API Key
148
+ */ serialize() {
203
149
  return this.toString();
204
150
  }
205
151
  /**
206
- * It serializes the NVM Api Key into a string
207
- * @returns a string representing the NVM API Key
208
- */
209
- toString() {
152
+ * It serializes the NVM Api Key into a string
153
+ * @returns a string representing the NVM API Key
154
+ */ toString() {
210
155
  return JSON.stringify(this);
211
156
  }
212
157
  /**
213
- * It decodes a string JWT into a JWTPayload
214
- * @param str jwt string
215
- * @returns the JWTPayload
216
- */
217
- static decodeJWT(str) {
158
+ * It decodes a string JWT into a JWTPayload
159
+ * @param str jwt string
160
+ * @returns the JWTPayload
161
+ */ static decodeJWT(str) {
218
162
  return decodeJwt(str);
219
163
  }
220
164
  /**
221
- * It generates the hash of the NvmApiKey
222
- * @returns a string representing the hash of the NvmApiKey
223
- */
224
- hash() {
165
+ * It generates the hash of the NvmApiKey
166
+ * @returns a string representing the hash of the NvmApiKey
167
+ */ hash() {
225
168
  return SignatureUtils.hash(this.serialize());
226
169
  }
227
170
  /**
228
- * Given a serialized string, it generates the hash
229
- * @param serialized the serialized string
230
- * @returns the hash
231
- */
232
- static hash(serialized) {
171
+ * Given a serialized string, it generates the hash
172
+ * @param serialized the serialized string
173
+ * @returns the hash
174
+ */ static hash(serialized) {
233
175
  return SignatureUtils.hash(serialized);
234
176
  }
177
+ constructor(){
178
+ /**
179
+ * The version of the key
180
+ */ this.ver = 'v1';
181
+ }
235
182
  }
183
+
184
+ //# sourceMappingURL=NvmApiKey.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/NvmApiKey.ts"],"sourcesContent":["import { JWTPayload, decodeJwt } from 'jose'\nimport { Account } from 'viem'\nimport { SmartAccount } from 'viem/account-abstraction'\nimport { bytesToHex } from 'viem/utils'\nimport { getChecksumAddress } from '../nevermined/utils/BlockchainViemUtils.js'\nimport { EthSignJWT } from '../nevermined/utils/JwtUtils.js'\nimport { SignatureUtils } from '../nevermined/utils/SignatureUtils.js'\nimport { decryptMessage, encryptMessage, urlSafeBase64Decode } from '../utils/helpers.js'\n\nexport class NvmApiKey implements JWTPayload {\n /**\n * The public address of the account issuing the key.\n */\n iss?: string\n\n /**\n * The chain id of the network the key is valid for. If zero the key is not having any network limitation\n */\n aud?: string\n\n /**\n * The public address of the account the key is issued for.\n */\n sub?: string\n\n /**\n * The version of the key\n */\n ver = 'v1'\n\n /**\n * The ZeroDev session key\n */\n zsk?: string\n\n /**\n * The Marketplace auth token\n */\n // nvt?: string\n\n /**\n * JWT Expiration Time\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}\n */\n exp?: number\n\n /**\n * JWT Issued At\n *\n * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}\n */\n iat?: number;\n\n /**\n * Additional attributes\n */\n [propName: string]: any\n\n /**\n * It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.\n * The string representing this key can be used to authenticate against the Nevermined API.\n * @param signatureUtils The SignatureUtils instance\n * @param issuerAccount The account issuing the key\n * @param zeroDevSessionKey The ZeroDev session key\n * @param receiverAddress The address of the account the key is issued for\n * @param receiverPublicKey The public key of the account the key is issued for\n * @param chainId The chain id of the network the key is valid for\n * @param additionalParams Addintional params to be added to the Key generated\n * @returns The encrypted string representing the @see {@link NvmApiKey}\n */\n public static async generate(\n signatureUtils: SignatureUtils,\n issuerAccount: Account | SmartAccount,\n zeroDevSessionKey: string | undefined,\n receiverAddress: string,\n receiverPublicKey: string,\n expirationTime: number | string = '1y',\n additionalParams = {},\n nvmApiKeyVersion = 'v1',\n ): Promise<string> {\n const issuerAddress = getChecksumAddress(issuerAccount.address)\n const chainId = signatureUtils.client.chain?.id || 0\n const sub = getChecksumAddress(receiverAddress)\n\n const eip712Data = {\n message: 'Sign this message to generate the Encrypted Nevermined API Key',\n ...(chainId > 0 && { chainId }),\n }\n const params = {\n iss: issuerAddress,\n aud: chainId.toString(),\n sub,\n ver: nvmApiKeyVersion,\n zsk: zeroDevSessionKey,\n eip712Data,\n ...additionalParams,\n }\n\n const signedJWT = await new EthSignJWT(params)\n .setProtectedHeader({ alg: 'ES256K' })\n .setIssuedAt()\n .setExpirationTime(expirationTime)\n .ethSign(signatureUtils, issuerAccount)\n\n return encryptMessage(signedJWT, receiverPublicKey)\n }\n\n /**\n * Given an encrypted JWT and a private key, it decrypts and decodes the JWT into a NvmApiKey\n * @param encryptedJwt The encrypted JWT\n * @param privateKey The private key representing the account\n * @returns The @see {@link NvmApiKey}\n */\n public static async decryptAndDecode(encryptedJwt: string, privateKey: string) {\n const decrypted = await decryptMessage(encryptedJwt, privateKey)\n return NvmApiKey.fromJWT(decrypted)\n }\n\n /**\n * Given a signed JWT, it recovers the signer address\n * @param jwtString The signed JWT\n * @returns The signer address\n */\n public static async getSignerAddress(jwtString: string): Promise<string> {\n try {\n const tokens = jwtString.split('.')\n const signature = bytesToHex(urlSafeBase64Decode(tokens[2]))\n return SignatureUtils.recoverSignerAddress(`${tokens[0]}.${tokens[1]}`, signature)\n } catch (e) {\n if (e instanceof Error) {\n throw new Error(`Error recovering signer address: ${e.message}`)\n } else {\n throw new Error(`Error recovering signer address`)\n }\n }\n }\n\n /**\n * It checks if the NVM API Key attributes are valid\n * @param chainId The chain id of the network the key is valid for\n * @returns true if the key is valid, false otherwise\n */\n public isValid(chainId = 0): boolean {\n if (this.exp) {\n const now = new Date()\n if (now.getTime() > Number(this.exp) * 1000) return false\n }\n if (chainId !== 0) {\n if (Number(this.aud) !== chainId) return false\n }\n return true\n }\n\n /**\n * It generates a signed JWT from the NvmApiKey\n * @param signatureUtils The SignatureUtils instance\n * @param issuerAccount The account issuing the key\n * @returns the string in JWT format represeting the NvmApiKey\n */\n public async toJWT(\n signatureUtils: SignatureUtils,\n issuerAccount: Account | SmartAccount,\n ): Promise<string> {\n const params: Record<string, any> = {}\n Object.keys(this)\n .filter((val) => val !== undefined)\n .forEach((key) => {\n if (!key.startsWith('_')) params[key] = this[key]\n })\n\n const jwt = new EthSignJWT(params).setProtectedHeader({ alg: 'ES256K' }).setIssuedAt(this.iat)\n if (this.exp) jwt.setExpirationTime(this.exp)\n return jwt.ethSign(signatureUtils, issuerAccount)\n }\n\n /**\n * It generates the hash in JWT format of the NvmApiKey\n * @param signatureUtils the SignatureUtils instance\n * @param issuerAccount the account issuing the key\n * @returns a JWT string representing the hash of the NvmApiKey\n */\n public async hashJWT(\n signatureUtils: SignatureUtils,\n issuerAccount: Account | SmartAccount,\n heliconeApiKey?: string,\n ): Promise<string> {\n const issuerAddress = getChecksumAddress(issuerAccount.address)\n\n return (\n new EthSignJWT({\n iss: issuerAddress, // the account generating the hash (node/provider, etc) is the issuer of the hash\n sub: this.iss, // the issuer of the NVMApiKey (the user) is the subject of the hash\n jti: this.hash(),\n exp: this.exp,\n o11y: heliconeApiKey,\n })\n .setProtectedHeader({ alg: 'ES256K' })\n // .setIssuedAt() // WARNING: If enabled, the hash will change for the same NvmApiKey\n .ethSign(signatureUtils, issuerAccount)\n )\n }\n\n /**\n * It regenerates the NvmApiKey from a JSON object\n * @param jwt JWTPayload in JSON format\n * @returns the @see {@link NvmApiKey}\n */\n public static fromJSON(jwt: JWTPayload): NvmApiKey {\n const nvmKey = new NvmApiKey()\n const str = JSON.stringify(jwt)\n const _obj = JSON.parse(str)\n Object.keys(_obj)\n .filter((val) => val !== undefined)\n .forEach((key) => {\n nvmKey[key] = _obj[key]\n })\n return nvmKey\n }\n\n /**\n * It regenerates the NvmApiKey from a JWT\n * @param jwtString the string in JWT format represeting the NvmApiKey\n * @returns the @see {@link NvmApiKey}\n */\n public static fromJWT(jwtString: string): NvmApiKey {\n const jwt = NvmApiKey.decodeJWT(jwtString)\n return NvmApiKey.fromJSON(jwt)\n }\n\n /**\n * It regenerates the NvmApiKey from a string\n * @param str the string represeting the NvmApiKey\n * @returns the @see {@link NvmApiKey}\n */\n public static deserialize(str: string): NvmApiKey {\n return NvmApiKey.fromJSON(JSON.parse(str))\n }\n\n /**\n * It serializes the NVM Api Key into a string\n * @returns a string representing the NVM API Key\n */\n public serialize(): string {\n return this.toString()\n }\n\n /**\n * It serializes the NVM Api Key into a string\n * @returns a string representing the NVM API Key\n */\n public toString(): string {\n return JSON.stringify(this)\n }\n\n /**\n * It decodes a string JWT into a JWTPayload\n * @param str jwt string\n * @returns the JWTPayload\n */\n public static decodeJWT(str: string) {\n return decodeJwt(str)\n }\n\n /**\n * It generates the hash of the NvmApiKey\n * @returns a string representing the hash of the NvmApiKey\n */\n public hash() {\n return SignatureUtils.hash(this.serialize())\n }\n\n /**\n * Given a serialized string, it generates the hash\n * @param serialized the serialized string\n * @returns the hash\n */\n static hash(serialized: string) {\n return SignatureUtils.hash(serialized)\n }\n}\n"],"names":["decodeJwt","bytesToHex","getChecksumAddress","EthSignJWT","SignatureUtils","decryptMessage","encryptMessage","urlSafeBase64Decode","NvmApiKey","generate","signatureUtils","issuerAccount","zeroDevSessionKey","receiverAddress","receiverPublicKey","expirationTime","additionalParams","nvmApiKeyVersion","issuerAddress","address","chainId","client","chain","id","sub","eip712Data","message","params","iss","aud","toString","ver","zsk","signedJWT","setProtectedHeader","alg","setIssuedAt","setExpirationTime","ethSign","decryptAndDecode","encryptedJwt","privateKey","decrypted","fromJWT","getSignerAddress","jwtString","tokens","split","signature","recoverSignerAddress","e","Error","isValid","exp","now","Date","getTime","Number","toJWT","Object","keys","filter","val","undefined","forEach","key","startsWith","jwt","iat","hashJWT","heliconeApiKey","jti","hash","o11y","fromJSON","nvmKey","str","JSON","stringify","_obj","parse","decodeJWT","deserialize","serialize","serialized"],"mappings":"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"}
@@ -1 +1,3 @@
1
- export {};
1
+ export { };
2
+
3
+ //# sourceMappingURL=Transactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/Transactions.ts"],"sourcesContent":["export interface TxParameters {\n value?: bigint\n gasLimit?: bigint\n gasMultiplier?: number\n gasPrice?: string\n maxPriorityFeePerGas?: string\n maxFeePerGas?: string\n nonce?: number\n progress?: (data: any) => void\n}\n"],"names":[],"mappings":"AAAA,WASC"}
@@ -3,3 +3,5 @@ export * from './NeverminedOptions.js';
3
3
  export * from './NvmApiKey.js';
4
4
  export * from './Transactions.js';
5
5
  export * from './AgentX402AccessToken.js';
6
+
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/index.ts"],"sourcesContent":["export * from './Logger.js'\nexport * from './NeverminedOptions.js'\nexport * from './NvmApiKey.js'\nexport * from './Transactions.js'\nexport * from './AgentX402AccessToken.js'\n"],"names":[],"mappings":"AAAA,cAAc,cAAa;AAC3B,cAAc,yBAAwB;AACtC,cAAc,iBAAgB;AAC9B,cAAc,oBAAmB;AACjC,cAAc,4BAA2B"}
@@ -5,29 +5,27 @@ import { ContractsApi } from '../contracts/ContractsApi.js';
5
5
  import { PaymentsApi } from './api/PaymentsApi.js';
6
6
  /**
7
7
  * Main interface for Nevermined Protocol.
8
- */
9
- export class Nevermined extends Instantiable {
8
+ */ export class Nevermined extends Instantiable {
10
9
  /**
11
- * Returns the instance of Nevermined.
12
- *
13
- * @example
14
- * ```ts
15
- * import { Nevermined, Config } from '@nevermined-io/sdk'
16
- *
17
- * const config: Config = {...}
18
- * const nevermined = await Nevermined.getInstance(config)
19
- * ```
20
- *
21
- * @param config - Nevermined instance configuration.
22
- * @returns A {@link Nevermined} instance
23
- */
24
- static async getInstance(config) {
10
+ * Returns the instance of Nevermined.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { Nevermined, Config } from '@nevermined-io/sdk'
15
+ *
16
+ * const config: Config = {...}
17
+ * const nevermined = await Nevermined.getInstance(config)
18
+ * ```
19
+ *
20
+ * @param config - Nevermined instance configuration.
21
+ * @returns A {@link Nevermined} instance
22
+ */ static async getInstance(config) {
25
23
  const instance = new Nevermined();
26
24
  // Nevermined main API
27
25
  try {
28
26
  const instanceConfig = {
29
- ...(await generateInstantiableConfigFromConfig(config, true)),
30
- nevermined: instance,
27
+ ...await generateInstantiableConfigFromConfig(config, true),
28
+ nevermined: instance
31
29
  };
32
30
  instance.setInstanceConfig(instanceConfig);
33
31
  // instance.search = new SearchApi(instanceConfig)
@@ -37,36 +35,16 @@ export class Nevermined extends Instantiable {
37
35
  await instance.contracts.init();
38
36
  instance.payments = new PaymentsApi(instanceConfig);
39
37
  instance.contractsInitialized = true;
40
- }
41
- catch (error) {
38
+ } catch (error) {
42
39
  instance.contractsInitialized = false;
43
40
  instance.logger.error(error);
44
41
  instance.logger.error("Contracts didn't initialize because for the above mentioned reason. Loading SDK in offchain mode...");
45
42
  }
46
43
  return instance;
47
44
  }
48
- /**
49
- * ContractsApi instance.
50
- */
51
- contracts;
52
- /**
53
- * SearchApi API
54
- */
55
- services;
56
- /**
57
- * Utils submodule
58
- */
59
- utils;
60
- payments;
61
- /**
62
- * Web3 Clients
63
- */
64
- // public web3: Web3Clients
65
- /**
66
- * If contracts are initialized
67
- */
68
- contractsInitialized;
69
- constructor() {
45
+ constructor(){
70
46
  super();
71
47
  }
72
48
  }
49
+
50
+ //# sourceMappingURL=Nevermined.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/nevermined/Nevermined.ts"],"sourcesContent":["import { Instantiable, generateInstantiableConfigFromConfig } from '../Instantiable.abstract.js'\nimport { NeverminedOptions } from '../models/NeverminedOptions.js'\nimport { UtilsApi } from '../nevermined/api/UtilsApi.js'\nimport { ServicesApi } from './api/ServicesApi.js'\nimport { ContractsApi } from '../contracts/ContractsApi.js'\nimport { PaymentsApi } from './api/PaymentsApi.js'\n\n/**\n * Main interface for Nevermined Protocol.\n */\nexport class Nevermined extends Instantiable {\n /**\n * Returns the instance of Nevermined.\n *\n * @example\n * ```ts\n * import { Nevermined, Config } from '@nevermined-io/sdk'\n *\n * const config: Config = {...}\n * const nevermined = await Nevermined.getInstance(config)\n * ```\n *\n * @param config - Nevermined instance configuration.\n * @returns A {@link Nevermined} instance\n */\n public static override async getInstance(config: NeverminedOptions): Promise<Nevermined> {\n const instance = new Nevermined()\n\n // Nevermined main API\n\n try {\n const instanceConfig = {\n ...(await generateInstantiableConfigFromConfig(config, true)),\n nevermined: instance,\n }\n instance.setInstanceConfig(instanceConfig)\n\n // instance.search = new SearchApi(instanceConfig)\n instance.services = new ServicesApi(instanceConfig)\n instance.utils = new UtilsApi(instanceConfig)\n instance.contracts = await ContractsApi.getInstance(instanceConfig)\n await instance.contracts.init()\n instance.payments = new PaymentsApi(instanceConfig)\n\n instance.contractsInitialized = true\n } catch (error) {\n instance.contractsInitialized = false\n\n instance.logger.error(error)\n instance.logger.error(\n \"Contracts didn't initialize because for the above mentioned reason. Loading SDK in offchain mode...\",\n )\n }\n\n return instance\n }\n\n /**\n * ContractsApi instance.\n */\n public contracts!: ContractsApi\n\n /**\n * SearchApi API\n */\n public services!: ServicesApi\n\n /**\n * Utils submodule\n */\n public utils!: UtilsApi\n\n public payments!: PaymentsApi\n\n /**\n * Web3 Clients\n */\n // public web3: Web3Clients\n\n /**\n * If contracts are initialized\n */\n public contractsInitialized: boolean | undefined\n\n private constructor() {\n super()\n }\n}\n"],"names":["Instantiable","generateInstantiableConfigFromConfig","UtilsApi","ServicesApi","ContractsApi","PaymentsApi","Nevermined","getInstance","config","instance","instanceConfig","nevermined","setInstanceConfig","services","utils","contracts","init","payments","contractsInitialized","error","logger"],"mappings":"AAAA,SAASA,YAAY,EAAEC,oCAAoC,QAAQ,8BAA6B;AAEhG,SAASC,QAAQ,QAAQ,gCAA+B;AACxD,SAASC,WAAW,QAAQ,uBAAsB;AAClD,SAASC,YAAY,QAAQ,+BAA8B;AAC3D,SAASC,WAAW,QAAQ,uBAAsB;AAElD;;CAEC,GACD,OAAO,MAAMC,mBAAmBN;IAC9B;;;;;;;;;;;;;GAaC,GACD,aAA6BO,YAAYC,MAAyB,EAAuB;QACvF,MAAMC,WAAW,IAAIH;QAErB,sBAAsB;QAEtB,IAAI;YACF,MAAMI,iBAAiB;gBACrB,GAAI,MAAMT,qCAAqCO,QAAQ,KAAK;gBAC5DG,YAAYF;YACd;YACAA,SAASG,iBAAiB,CAACF;YAE3B,kDAAkD;YAClDD,SAASI,QAAQ,GAAG,IAAIV,YAAYO;YACpCD,SAASK,KAAK,GAAG,IAAIZ,SAASQ;YAC9BD,SAASM,SAAS,GAAG,MAAMX,aAAaG,WAAW,CAACG;YACpD,MAAMD,SAASM,SAAS,CAACC,IAAI;YAC7BP,SAASQ,QAAQ,GAAG,IAAIZ,YAAYK;YAEpCD,SAASS,oBAAoB,GAAG;QAClC,EAAE,OAAOC,OAAO;YACdV,SAASS,oBAAoB,GAAG;YAEhCT,SAASW,MAAM,CAACD,KAAK,CAACA;YACtBV,SAASW,MAAM,CAACD,KAAK,CACnB;QAEJ;QAEA,OAAOV;IACT;IA6BA,aAAsB;QACpB,KAAK;IACP;AACF"}