@nevermined-io/core-kit 0.0.2-rc19

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 (137) hide show
  1. package/README.md +15 -0
  2. package/dist/Instantiable.abstract.d.ts +35 -0
  3. package/dist/Instantiable.abstract.d.ts.map +1 -0
  4. package/dist/Instantiable.abstract.js +102 -0
  5. package/dist/artifacts/generated.d.ts +29912 -0
  6. package/dist/artifacts/generated.d.ts.map +1 -0
  7. package/dist/artifacts/generated.js +16797 -0
  8. package/dist/contracts/AccessManager.d.ts +17 -0
  9. package/dist/contracts/AccessManager.d.ts.map +1 -0
  10. package/dist/contracts/AccessManager.js +15 -0
  11. package/dist/contracts/AssetRegistry.d.ts +65 -0
  12. package/dist/contracts/AssetRegistry.d.ts.map +1 -0
  13. package/dist/contracts/AssetRegistry.js +103 -0
  14. package/dist/contracts/ContractBase.d.ts +21 -0
  15. package/dist/contracts/ContractBase.d.ts.map +1 -0
  16. package/dist/contracts/ContractBase.js +270 -0
  17. package/dist/contracts/ContractsApi.d.ts +62 -0
  18. package/dist/contracts/ContractsApi.d.ts.map +1 -0
  19. package/dist/contracts/ContractsApi.js +66 -0
  20. package/dist/contracts/FiatPaymentTemplate.d.ts +10 -0
  21. package/dist/contracts/FiatPaymentTemplate.d.ts.map +1 -0
  22. package/dist/contracts/FiatPaymentTemplate.js +14 -0
  23. package/dist/contracts/FiatSettlementCondition.d.ts +11 -0
  24. package/dist/contracts/FiatSettlementCondition.d.ts.map +1 -0
  25. package/dist/contracts/FiatSettlementCondition.js +18 -0
  26. package/dist/contracts/FixedPaymentTemplate.d.ts +10 -0
  27. package/dist/contracts/FixedPaymentTemplate.d.ts.map +1 -0
  28. package/dist/contracts/FixedPaymentTemplate.js +14 -0
  29. package/dist/contracts/NFT1155Base.d.ts +41 -0
  30. package/dist/contracts/NFT1155Base.d.ts.map +1 -0
  31. package/dist/contracts/NFT1155Base.js +21 -0
  32. package/dist/contracts/NFT1155Credits.d.ts +6 -0
  33. package/dist/contracts/NFT1155Credits.d.ts.map +1 -0
  34. package/dist/contracts/NFT1155Credits.js +9 -0
  35. package/dist/contracts/NFT1155ExpirableCredits.d.ts +34 -0
  36. package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +1 -0
  37. package/dist/contracts/NFT1155ExpirableCredits.js +18 -0
  38. package/dist/contracts/NVMConfig.d.ts +10 -0
  39. package/dist/contracts/NVMConfig.d.ts.map +1 -0
  40. package/dist/contracts/NVMConfig.js +18 -0
  41. package/dist/contracts/ProtocolStandardFees.d.ts +9 -0
  42. package/dist/contracts/ProtocolStandardFees.d.ts.map +1 -0
  43. package/dist/contracts/ProtocolStandardFees.js +15 -0
  44. package/dist/contracts/Roles.d.ts +13 -0
  45. package/dist/contracts/Roles.d.ts.map +1 -0
  46. package/dist/contracts/Roles.js +12 -0
  47. package/dist/contracts/index.d.ts +3 -0
  48. package/dist/contracts/index.d.ts.map +1 -0
  49. package/dist/contracts/index.js +2 -0
  50. package/dist/errors/NeverminedErrors.d.ts +71 -0
  51. package/dist/errors/NeverminedErrors.d.ts.map +1 -0
  52. package/dist/errors/NeverminedErrors.js +123 -0
  53. package/dist/errors/index.d.ts +2 -0
  54. package/dist/errors/index.d.ts.map +1 -0
  55. package/dist/errors/index.js +1 -0
  56. package/dist/index.d.ts +8 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +11 -0
  59. package/dist/models/Logger.d.ts +9 -0
  60. package/dist/models/Logger.d.ts.map +1 -0
  61. package/dist/models/Logger.js +27 -0
  62. package/dist/models/NeverminedOptions.d.ts +55 -0
  63. package/dist/models/NeverminedOptions.d.ts.map +1 -0
  64. package/dist/models/NeverminedOptions.js +58 -0
  65. package/dist/models/NvmApiKey.d.ts +137 -0
  66. package/dist/models/NvmApiKey.d.ts.map +1 -0
  67. package/dist/models/NvmApiKey.js +234 -0
  68. package/dist/models/Transactions.d.ts +11 -0
  69. package/dist/models/Transactions.d.ts.map +1 -0
  70. package/dist/models/Transactions.js +1 -0
  71. package/dist/models/index.d.ts +5 -0
  72. package/dist/models/index.d.ts.map +1 -0
  73. package/dist/models/index.js +4 -0
  74. package/dist/nevermined/DID.d.ts +45 -0
  75. package/dist/nevermined/DID.d.ts.map +1 -0
  76. package/dist/nevermined/DID.js +90 -0
  77. package/dist/nevermined/Nevermined.d.ts +48 -0
  78. package/dist/nevermined/Nevermined.d.ts.map +1 -0
  79. package/dist/nevermined/Nevermined.js +72 -0
  80. package/dist/nevermined/api/PaymentsApi.d.ts +17 -0
  81. package/dist/nevermined/api/PaymentsApi.d.ts.map +1 -0
  82. package/dist/nevermined/api/PaymentsApi.js +125 -0
  83. package/dist/nevermined/api/ServicesApi.d.ts +28 -0
  84. package/dist/nevermined/api/ServicesApi.d.ts.map +1 -0
  85. package/dist/nevermined/api/ServicesApi.js +33 -0
  86. package/dist/nevermined/api/UtilsApi.d.ts +28 -0
  87. package/dist/nevermined/api/UtilsApi.d.ts.map +1 -0
  88. package/dist/nevermined/api/UtilsApi.js +33 -0
  89. package/dist/nevermined/index.d.ts +4 -0
  90. package/dist/nevermined/index.d.ts.map +1 -0
  91. package/dist/nevermined/index.js +3 -0
  92. package/dist/nevermined/utils/BlockchainViemUtils.d.ts +276 -0
  93. package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +1 -0
  94. package/dist/nevermined/utils/BlockchainViemUtils.js +376 -0
  95. package/dist/nevermined/utils/JwtUtils.d.ts +27 -0
  96. package/dist/nevermined/utils/JwtUtils.d.ts.map +1 -0
  97. package/dist/nevermined/utils/JwtUtils.js +154 -0
  98. package/dist/nevermined/utils/SignatureUtils.d.ts +14 -0
  99. package/dist/nevermined/utils/SignatureUtils.d.ts.map +1 -0
  100. package/dist/nevermined/utils/SignatureUtils.js +99 -0
  101. package/dist/nevermined/utils/WebServiceConnector.d.ts +32 -0
  102. package/dist/nevermined/utils/WebServiceConnector.d.ts.map +1 -0
  103. package/dist/nevermined/utils/WebServiceConnector.js +191 -0
  104. package/dist/nevermined/utils/ZeroDevPolicies.d.ts +19 -0
  105. package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +1 -0
  106. package/dist/nevermined/utils/ZeroDevPolicies.js +78 -0
  107. package/dist/nevermined/utils/index.d.ts +6 -0
  108. package/dist/nevermined/utils/index.d.ts.map +1 -0
  109. package/dist/nevermined/utils/index.js +5 -0
  110. package/dist/services/Api.d.ts +7 -0
  111. package/dist/services/Api.d.ts.map +1 -0
  112. package/dist/services/Api.js +25 -0
  113. package/dist/services/MarketplaceAPI.d.ts +7 -0
  114. package/dist/services/MarketplaceAPI.d.ts.map +1 -0
  115. package/dist/services/MarketplaceAPI.js +25 -0
  116. package/dist/services/MetadataService.d.ts +90 -0
  117. package/dist/services/MetadataService.d.ts.map +1 -0
  118. package/dist/services/MetadataService.js +277 -0
  119. package/dist/services/Profiles.d.ts +16 -0
  120. package/dist/services/Profiles.d.ts.map +1 -0
  121. package/dist/services/Profiles.js +84 -0
  122. package/dist/services/index.d.ts +4 -0
  123. package/dist/services/index.d.ts.map +1 -0
  124. package/dist/services/index.js +3 -0
  125. package/dist/utils/ConversionTypeHelpers.d.ts +8 -0
  126. package/dist/utils/ConversionTypeHelpers.d.ts.map +1 -0
  127. package/dist/utils/ConversionTypeHelpers.js +31 -0
  128. package/dist/utils/Network.d.ts +5 -0
  129. package/dist/utils/Network.d.ts.map +1 -0
  130. package/dist/utils/Network.js +224 -0
  131. package/dist/utils/helpers.d.ts +21 -0
  132. package/dist/utils/helpers.d.ts.map +1 -0
  133. package/dist/utils/helpers.js +109 -0
  134. package/dist/utils/index.d.ts +4 -0
  135. package/dist/utils/index.d.ts.map +1 -0
  136. package/dist/utils/index.js +3 -0
  137. package/package.json +27 -0
@@ -0,0 +1,55 @@
1
+ import { Account } from 'viem';
2
+ export declare class NeverminedOptions {
3
+ chainId: number;
4
+ /**
5
+ * Ethereum Web3 Provider URL. This Url allows the SDK to connect to a blockchain.
6
+ * This provider depends on the network where you want to connect (Ethereum Mainnet, Rinkeby, Polygon Matic, etc).
7
+ * It's possible to use a public available provider or a private/paid one like Infura, Alchemy, etc.
8
+ */
9
+ web3ProviderUri?: string;
10
+ /**
11
+ * The Nevermined App URL.
12
+ */
13
+ appUrl?: string;
14
+ backendUrl?: string;
15
+ /**
16
+ * Web3 Provider.
17
+ */
18
+ /**
19
+ * Log level.
20
+ */
21
+ 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
+ /**
30
+ * The folder where the nevermined contract artifacts are located.
31
+ */
32
+ artifactsFolder?: string;
33
+ accounts?: Account[];
34
+ /**
35
+ * IPFS variables enable the resolution of DDOs (via `assets.resolve`) from CID urls
36
+ * INFO: For performance purposes, it is recommended to setup a IPFS Infura endpoint to accelerate
37
+ * the asset resolution requests.
38
+ */
39
+ ipfsGateway?: string;
40
+ ipfsProjectId?: string;
41
+ ipfsProjectSecret?: string;
42
+ /**
43
+ * Use a gas station to calculate transaction fees
44
+ */
45
+ gasStationUri?: string;
46
+ /**
47
+ * ZeroDev project id
48
+ */
49
+ zeroDevProjectId?: string;
50
+ /**
51
+ * Contracts version
52
+ */
53
+ contractsVersion?: string;
54
+ }
55
+ //# sourceMappingURL=NeverminedOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NeverminedOptions.d.ts","sourceRoot":"","sources":["../../src/models/NeverminedOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,qBAAa,iBAAiB;IACrB,OAAO,EAAE,MAAM,CAAA;IACtB;;;;OAIG;IACI,eAAe,CAAC,EAAE,MAAM,CAAA;IAE/B;;OAEG;IACI,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf,UAAU,CAAC,EAAE,MAAM,CAAA;IAI1B;;OAEG;IAGH;;OAEG;IACI,QAAQ,SAAS;IAGxB;;;OAGG;IAGH;;OAEG;IAGH;;OAEG;IACI,eAAe,CAAC,EAAE,MAAM,CAAA;IAExB,QAAQ,CAAC,EAAE,OAAO,EAAE,CAAA;IAE3B;;;;OAIG;IACI,WAAW,CAAC,EAAE,MAAM,CAAoB;IAExC,aAAa,CAAC,EAAE,MAAM,CAAA;IAEtB,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAEjC;;OAEG;IACI,aAAa,CAAC,EAAE,MAAM,CAAA;IAE7B;;OAEG;IACI,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAEhC;;OAEG;IACI,gBAAgB,CAAC,EAAE,MAAM,CAAA;CACjC"}
@@ -0,0 +1,58 @@
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
+ // public backendAuthToken?: string
15
+ /**
16
+ * Web3 Provider.
17
+ */
18
+ // public web3Provider?: any
19
+ /**
20
+ * Log level.
21
+ */
22
+ 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
+ /**
34
+ * The folder where the nevermined contract artifacts are located.
35
+ */
36
+ artifactsFolder;
37
+ accounts;
38
+ /**
39
+ * IPFS variables enable the resolution of DDOs (via `assets.resolve`) from CID urls
40
+ * INFO: For performance purposes, it is recommended to setup a IPFS Infura endpoint to accelerate
41
+ * the asset resolution requests.
42
+ */
43
+ ipfsGateway = 'https://ipfs.io';
44
+ ipfsProjectId;
45
+ ipfsProjectSecret;
46
+ /**
47
+ * Use a gas station to calculate transaction fees
48
+ */
49
+ gasStationUri;
50
+ /**
51
+ * ZeroDev project id
52
+ */
53
+ zeroDevProjectId;
54
+ /**
55
+ * Contracts version
56
+ */
57
+ contractsVersion;
58
+ }
@@ -0,0 +1,137 @@
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
+ export declare class NvmApiKey implements JWTPayload {
6
+ /**
7
+ * The public address of the account issuing the key.
8
+ */
9
+ iss?: string;
10
+ /**
11
+ * The chain id of the network the key is valid for. If zero the key is not having any network limitation
12
+ */
13
+ aud?: string;
14
+ /**
15
+ * The public address of the account the key is issued for.
16
+ */
17
+ sub?: string;
18
+ /**
19
+ * The version of the key
20
+ */
21
+ ver: string;
22
+ /**
23
+ * The ZeroDev session key
24
+ */
25
+ zsk?: string;
26
+ /**
27
+ * The Marketplace auth token
28
+ */
29
+ /**
30
+ * JWT Expiration Time
31
+ *
32
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
33
+ */
34
+ exp?: number;
35
+ /**
36
+ * JWT Issued At
37
+ *
38
+ * @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
39
+ */
40
+ iat?: number;
41
+ /**
42
+ * Additional attributes
43
+ */
44
+ [propName: string]: any;
45
+ /**
46
+ * It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
47
+ * The string representing this key can be used to authenticate against the Nevermined API.
48
+ * @param signatureUtils The SignatureUtils instance
49
+ * @param issuerAccount The account issuing the key
50
+ * @param zeroDevSessionKey The ZeroDev session key
51
+ * @param receiverAddress The address of the account the key is issued for
52
+ * @param receiverPublicKey The public key of the account the key is issued for
53
+ * @param chainId The chain id of the network the key is valid for
54
+ * @param additionalParams Addintional params to be added to the Key generated
55
+ * @returns The encrypted string representing the @see {@link NvmApiKey}
56
+ */
57
+ static generate(signatureUtils: SignatureUtils, issuerAccount: Account | SmartAccount, zeroDevSessionKey: string | undefined, receiverAddress: string, receiverPublicKey: string, expirationTime?: number | string, additionalParams?: {}, nvmApiKeyVersion?: string): Promise<string>;
58
+ /**
59
+ * Given an encrypted JWT and a private key, it decrypts and decodes the JWT into a NvmApiKey
60
+ * @param encryptedJwt The encrypted JWT
61
+ * @param privateKey The private key representing the account
62
+ * @returns The @see {@link NvmApiKey}
63
+ */
64
+ static decryptAndDecode(encryptedJwt: string, privateKey: string): Promise<NvmApiKey>;
65
+ /**
66
+ * Given a signed JWT, it recovers the signer address
67
+ * @param jwtString The signed JWT
68
+ * @returns The signer address
69
+ */
70
+ static getSignerAddress(jwtString: string): Promise<string>;
71
+ /**
72
+ * It checks if the NVM API Key attributes are valid
73
+ * @param chainId The chain id of the network the key is valid for
74
+ * @returns true if the key is valid, false otherwise
75
+ */
76
+ isValid(chainId?: number): boolean;
77
+ /**
78
+ * It generates a signed JWT from the NvmApiKey
79
+ * @param signatureUtils The SignatureUtils instance
80
+ * @param issuerAccount The account issuing the key
81
+ * @returns the string in JWT format represeting the NvmApiKey
82
+ */
83
+ toJWT(signatureUtils: SignatureUtils, issuerAccount: Account | SmartAccount): Promise<string>;
84
+ /**
85
+ * It generates the hash in JWT format of the NvmApiKey
86
+ * @param signatureUtils the SignatureUtils instance
87
+ * @param issuerAccount the account issuing the key
88
+ * @returns a JWT string representing the hash of the NvmApiKey
89
+ */
90
+ hashJWT(signatureUtils: SignatureUtils, issuerAccount: Account | SmartAccount): Promise<string>;
91
+ /**
92
+ * It regenerates the NvmApiKey from a JSON object
93
+ * @param jwt JWTPayload in JSON format
94
+ * @returns the @see {@link NvmApiKey}
95
+ */
96
+ static fromJSON(jwt: JWTPayload): NvmApiKey;
97
+ /**
98
+ * It regenerates the NvmApiKey from a JWT
99
+ * @param jwtString the string in JWT format represeting the NvmApiKey
100
+ * @returns the @see {@link NvmApiKey}
101
+ */
102
+ static fromJWT(jwtString: string): NvmApiKey;
103
+ /**
104
+ * It regenerates the NvmApiKey from a string
105
+ * @param str the string represeting the NvmApiKey
106
+ * @returns the @see {@link NvmApiKey}
107
+ */
108
+ static deserialize(str: string): NvmApiKey;
109
+ /**
110
+ * It serializes the NVM Api Key into a string
111
+ * @returns a string representing the NVM API Key
112
+ */
113
+ serialize(): string;
114
+ /**
115
+ * It serializes the NVM Api Key into a string
116
+ * @returns a string representing the NVM API Key
117
+ */
118
+ toString(): string;
119
+ /**
120
+ * It decodes a string JWT into a JWTPayload
121
+ * @param str jwt string
122
+ * @returns the JWTPayload
123
+ */
124
+ static decodeJWT(str: string): JWTPayload;
125
+ /**
126
+ * It generates the hash of the NvmApiKey
127
+ * @returns a string representing the hash of the NvmApiKey
128
+ */
129
+ hash(): string;
130
+ /**
131
+ * Given a serialized string, it generates the hash
132
+ * @param serialized the serialized string
133
+ * @returns the hash
134
+ */
135
+ static hash(serialized: string): string;
136
+ }
137
+ //# sourceMappingURL=NvmApiKey.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NvmApiKey.d.ts","sourceRoot":"","sources":["../../src/models/NvmApiKey.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;AAIvD,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAA;AAGtE,qBAAa,SAAU,YAAW,UAAU;IAC1C;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IACH,GAAG,SAAO;IAEV;;OAEG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;OAEG;IAGH;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;IAEZ;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb;;OAEG;IACH,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,CAAA;IAEvB;;;;;;;;;;;OAWG;WACiB,QAAQ,CAC1B,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,OAAO,GAAG,YAAY,EACrC,iBAAiB,EAAE,MAAM,GAAG,SAAS,EACrC,eAAe,EAAE,MAAM,EACvB,iBAAiB,EAAE,MAAM,EACzB,cAAc,GAAE,MAAM,GAAG,MAAa,EACtC,gBAAgB,KAAK,EACrB,gBAAgB,SAAO,GACtB,OAAO,CAAC,MAAM,CAAC;IA4BlB;;;;;OAKG;WACiB,gBAAgB,CAAC,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM;IAK7E;;;;OAIG;WACiB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAcxE;;;;OAIG;IACI,OAAO,CAAC,OAAO,SAAI,GAAG,OAAO;IAWpC;;;;;OAKG;IACU,KAAK,CAChB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,OAAO,GAAG,YAAY,GACpC,OAAO,CAAC,MAAM,CAAC;IAalB;;;;;OAKG;IACU,OAAO,CAClB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,OAAO,GAAG,YAAY,GACpC,OAAO,CAAC,MAAM,CAAC;IAgBlB;;;;OAIG;WACW,QAAQ,CAAC,GAAG,EAAE,UAAU,GAAG,SAAS;IAYlD;;;;OAIG;WACW,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS;IAKnD;;;;OAIG;WACW,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IAIjD;;;OAGG;IACI,SAAS,IAAI,MAAM;IAI1B;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAIzB;;;;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,234 @@
1
+ import { decodeJwt } from 'jose';
2
+ import { bytesToHex } from 'viem/utils';
3
+ import { getChecksumAddress } from '../nevermined/utils/BlockchainViemUtils.js';
4
+ import { EthSignJWT } from '../nevermined/utils/JwtUtils.js';
5
+ import { SignatureUtils } from '../nevermined/utils/SignatureUtils.js';
6
+ import { decryptMessage, encryptMessage, urlSafeBase64Decode } from '../utils/helpers.js';
7
+ export class NvmApiKey {
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') {
57
+ const issuerAddress = getChecksumAddress(issuerAccount.address);
58
+ const chainId = signatureUtils.client.chain?.id || 0;
59
+ const sub = getChecksumAddress(receiverAddress);
60
+ const eip712Data = {
61
+ message: 'Sign this message to generate the Encrypted Nevermined API Key',
62
+ ...(chainId > 0 && { chainId }),
63
+ };
64
+ const params = {
65
+ iss: issuerAddress,
66
+ aud: chainId.toString(),
67
+ sub,
68
+ ver: nvmApiKeyVersion,
69
+ zsk: zeroDevSessionKey,
70
+ eip712Data,
71
+ ...additionalParams,
72
+ };
73
+ const signedJWT = await new EthSignJWT(params)
74
+ .setProtectedHeader({ alg: 'ES256K' })
75
+ .setIssuedAt()
76
+ .setExpirationTime(expirationTime)
77
+ .ethSign(signatureUtils, issuerAccount);
78
+ return encryptMessage(signedJWT, receiverPublicKey);
79
+ }
80
+ /**
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) {
87
+ const decrypted = await decryptMessage(encryptedJwt, privateKey);
88
+ return NvmApiKey.fromJWT(decrypted);
89
+ }
90
+ /**
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) {
96
+ try {
97
+ const tokens = jwtString.split('.');
98
+ const signature = bytesToHex(urlSafeBase64Decode(tokens[2]));
99
+ return SignatureUtils.recoverSignerAddress(`${tokens[0]}.${tokens[1]}`, signature);
100
+ }
101
+ catch (e) {
102
+ if (e instanceof Error) {
103
+ throw new Error(`Error recovering signer address: ${e.message}`);
104
+ }
105
+ else {
106
+ throw new Error(`Error recovering signer address`);
107
+ }
108
+ }
109
+ }
110
+ /**
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) {
116
+ if (this.exp) {
117
+ const now = new Date();
118
+ if (now.getTime() > Number(this.exp) * 1000)
119
+ return false;
120
+ }
121
+ if (chainId !== 0) {
122
+ if (Number(this.aud) !== chainId)
123
+ return false;
124
+ }
125
+ return true;
126
+ }
127
+ /**
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) {
134
+ const params = {};
135
+ Object.keys(this)
136
+ .filter((val) => val !== undefined)
137
+ .forEach((key) => {
138
+ if (!key.startsWith('_'))
139
+ params[key] = this[key];
140
+ });
141
+ const jwt = new EthSignJWT(params).setProtectedHeader({ alg: 'ES256K' }).setIssuedAt(this.iat);
142
+ if (this.exp)
143
+ jwt.setExpirationTime(this.exp);
144
+ return jwt.ethSign(signatureUtils, issuerAccount);
145
+ }
146
+ /**
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) {
153
+ 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
157
+ jti: this.hash(),
158
+ exp: this.exp,
159
+ })
160
+ .setProtectedHeader({ alg: 'ES256K' })
161
+ // .setIssuedAt() // WARNING: If enabled, the hash will change for the same NvmApiKey
162
+ .ethSign(signatureUtils, issuerAccount));
163
+ }
164
+ /**
165
+ * It regenerates the NvmApiKey from a JSON object
166
+ * @param jwt JWTPayload in JSON format
167
+ * @returns the @see {@link NvmApiKey}
168
+ */
169
+ static fromJSON(jwt) {
170
+ const nvmKey = new NvmApiKey();
171
+ const str = JSON.stringify(jwt);
172
+ const _obj = JSON.parse(str);
173
+ Object.keys(_obj)
174
+ .filter((val) => val !== undefined)
175
+ .forEach((key) => {
176
+ nvmKey[key] = _obj[key];
177
+ });
178
+ return nvmKey;
179
+ }
180
+ /**
181
+ * It regenerates the NvmApiKey from a JWT
182
+ * @param jwtString the string in JWT format represeting the NvmApiKey
183
+ * @returns the @see {@link NvmApiKey}
184
+ */
185
+ static fromJWT(jwtString) {
186
+ const jwt = NvmApiKey.decodeJWT(jwtString);
187
+ return NvmApiKey.fromJSON(jwt);
188
+ }
189
+ /**
190
+ * It regenerates the NvmApiKey from a string
191
+ * @param str the string represeting the NvmApiKey
192
+ * @returns the @see {@link NvmApiKey}
193
+ */
194
+ static deserialize(str) {
195
+ return NvmApiKey.fromJSON(JSON.parse(str));
196
+ }
197
+ /**
198
+ * It serializes the NVM Api Key into a string
199
+ * @returns a string representing the NVM API Key
200
+ */
201
+ serialize() {
202
+ return this.toString();
203
+ }
204
+ /**
205
+ * It serializes the NVM Api Key into a string
206
+ * @returns a string representing the NVM API Key
207
+ */
208
+ toString() {
209
+ return JSON.stringify(this);
210
+ }
211
+ /**
212
+ * It decodes a string JWT into a JWTPayload
213
+ * @param str jwt string
214
+ * @returns the JWTPayload
215
+ */
216
+ static decodeJWT(str) {
217
+ return decodeJwt(str);
218
+ }
219
+ /**
220
+ * It generates the hash of the NvmApiKey
221
+ * @returns a string representing the hash of the NvmApiKey
222
+ */
223
+ hash() {
224
+ return SignatureUtils.hash(this.serialize());
225
+ }
226
+ /**
227
+ * Given a serialized string, it generates the hash
228
+ * @param serialized the serialized string
229
+ * @returns the hash
230
+ */
231
+ static hash(serialized) {
232
+ return SignatureUtils.hash(serialized);
233
+ }
234
+ }
@@ -0,0 +1,11 @@
1
+ export interface TxParameters {
2
+ value?: bigint;
3
+ gasLimit?: bigint;
4
+ gasMultiplier?: number;
5
+ gasPrice?: string;
6
+ maxPriorityFeePerGas?: string;
7
+ maxFeePerGas?: string;
8
+ nonce?: number;
9
+ progress?: (data: any) => void;
10
+ }
11
+ //# sourceMappingURL=Transactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Transactions.d.ts","sourceRoot":"","sources":["../../src/models/Transactions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,IAAI,CAAA;CAC/B"}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from './Logger.js';
2
+ export * from './NeverminedOptions.js';
3
+ export * from './NvmApiKey.js';
4
+ export * from './Transactions.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,4 @@
1
+ export * from './Logger.js';
2
+ export * from './NeverminedOptions.js';
3
+ export * from './NvmApiKey.js';
4
+ export * from './Transactions.js';
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Decentralized ID.
3
+ */
4
+ export declare class DID {
5
+ /**
6
+ * Parses a DID from a string.
7
+ * @param didString - DID in string format or DID instance.
8
+ * The didString can be in did:nv: format or 0x: format.
9
+ * @returns {@link DID}
10
+ */
11
+ static parse(didString: string | DID): DID;
12
+ /**
13
+ * Returns a new DID.
14
+ * @returns {@link DID}
15
+ */
16
+ static generate(): DID;
17
+ static parseBigInt(value: any, radix?: number): any;
18
+ /**
19
+ * Returns a new DID from a base36 encoded string.
20
+ * @param encoded - Base36 encoded string.
21
+ * @returns {@link DID}
22
+ */
23
+ static fromEncoded(encoded: string): DID;
24
+ /**
25
+ * Generates an encoded string in base 36 from a DID.
26
+ * @returns A base36 encoded string.
27
+ */
28
+ getEncoded(): string;
29
+ /**
30
+ * Short ID.
31
+ */
32
+ private id;
33
+ private constructor();
34
+ /**
35
+ * Returns the DID (i.e did:nv:...)
36
+ * @returns A string with the prefixed id.
37
+ */
38
+ getDid(): string;
39
+ /**
40
+ * Returns the Short ID.
41
+ * @returns A string of the _id_ without the prefix.
42
+ */
43
+ getId(): string;
44
+ }
45
+ //# sourceMappingURL=DID.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DID.d.ts","sourceRoot":"","sources":["../../src/nevermined/DID.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,qBAAa,GAAG;IACd;;;;;OAKG;WACW,KAAK,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG;IA0BjD;;;OAGG;WACW,QAAQ,IAAI,GAAG;WAIf,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,KAAK,SAAK;IAYhD;;;;OAIG;WACW,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG;IAM/C;;;OAGG;IACI,UAAU,IAAI,MAAM;IAI3B;;OAEG;IACH,OAAO,CAAC,EAAE,CAAQ;IAElB,OAAO;IAIP;;;OAGG;IACI,MAAM,IAAI,MAAM;IAIvB;;;OAGG;IACI,KAAK,IAAI,MAAM;CAGvB"}
@@ -0,0 +1,90 @@
1
+ import { generateId } from '../utils/index.js';
2
+ const DID_PREFIX = 'did:nv:';
3
+ /**
4
+ * Decentralized ID.
5
+ */
6
+ export class DID {
7
+ /**
8
+ * Parses a DID from a string.
9
+ * @param didString - DID in string format or DID instance.
10
+ * The didString can be in did:nv: format or 0x: format.
11
+ * @returns {@link DID}
12
+ */
13
+ static parse(didString) {
14
+ if (didString instanceof DID) {
15
+ didString = didString.getDid();
16
+ }
17
+ let did = null;
18
+ const did0xMatch = didString.match(/^0x([a-f0-9]{64})$/i);
19
+ if (did0xMatch) {
20
+ did = new DID(did0xMatch[1]);
21
+ }
22
+ else {
23
+ const didMatch = didString.match(/^did:nv:([a-f0-9]{64})$/i);
24
+ if (didMatch) {
25
+ did = new DID(didMatch[1]);
26
+ }
27
+ }
28
+ if (!did) {
29
+ throw new Error(`Parsing DID failed, ${didString}`);
30
+ }
31
+ return did;
32
+ }
33
+ /**
34
+ * Returns a new DID.
35
+ * @returns {@link DID}
36
+ */
37
+ static generate() {
38
+ return new DID(generateId());
39
+ }
40
+ static parseBigInt(value, radix = 36) {
41
+ // value: string
42
+ const size = 10;
43
+ const factor = BigInt(radix ** size);
44
+ let i = value.length % size || size;
45
+ const parts = [value.slice(0, i)];
46
+ while (i < value.length)
47
+ parts.push(value.slice(i, (i += size)));
48
+ return parts.reduce((r, v) => r * factor + BigInt(parseInt(v, radix)), BigInt(0));
49
+ }
50
+ /**
51
+ * Returns a new DID from a base36 encoded string.
52
+ * @param encoded - Base36 encoded string.
53
+ * @returns {@link DID}
54
+ */
55
+ static fromEncoded(encoded) {
56
+ const decoded = this.parseBigInt(encoded).toString(16);
57
+ if (decoded.length !== 64)
58
+ return new DID(`0${decoded}`);
59
+ else
60
+ return new DID(decoded);
61
+ }
62
+ /**
63
+ * Generates an encoded string in base 36 from a DID.
64
+ * @returns A base36 encoded string.
65
+ */
66
+ getEncoded() {
67
+ return BigInt(`0x${this.id}`).toString(36);
68
+ }
69
+ /**
70
+ * Short ID.
71
+ */
72
+ id;
73
+ constructor(id) {
74
+ this.id = id;
75
+ }
76
+ /**
77
+ * Returns the DID (i.e did:nv:...)
78
+ * @returns A string with the prefixed id.
79
+ */
80
+ getDid() {
81
+ return `${DID_PREFIX}${this.id}`;
82
+ }
83
+ /**
84
+ * Returns the Short ID.
85
+ * @returns A string of the _id_ without the prefix.
86
+ */
87
+ getId() {
88
+ return this.id;
89
+ }
90
+ }