@nevermined-io/core-kit 0.1.1 → 0.1.4
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/package.json +1 -1
- package/dist/Instantiable.abstract.d.ts +0 -33
- package/dist/Instantiable.abstract.d.ts.map +0 -1
- package/dist/Instantiable.abstract.js +0 -98
- package/dist/artifacts/generated.d.ts +0 -39371
- package/dist/artifacts/generated.d.ts.map +0 -1
- package/dist/artifacts/generated.js +0 -21448
- package/dist/contracts/AccessManager.d.ts +0 -17
- package/dist/contracts/AccessManager.d.ts.map +0 -1
- package/dist/contracts/AccessManager.js +0 -15
- package/dist/contracts/AssetRegistry.d.ts +0 -105
- package/dist/contracts/AssetRegistry.d.ts.map +0 -1
- package/dist/contracts/AssetRegistry.js +0 -155
- package/dist/contracts/ContractBase.d.ts +0 -33
- package/dist/contracts/ContractBase.d.ts.map +0 -1
- package/dist/contracts/ContractBase.js +0 -413
- package/dist/contracts/ContractsApi.d.ts +0 -69
- package/dist/contracts/ContractsApi.d.ts.map +0 -1
- package/dist/contracts/ContractsApi.js +0 -73
- package/dist/contracts/FiatPaymentTemplate.d.ts +0 -10
- package/dist/contracts/FiatPaymentTemplate.d.ts.map +0 -1
- package/dist/contracts/FiatPaymentTemplate.js +0 -14
- package/dist/contracts/FiatSettlementCondition.d.ts +0 -11
- package/dist/contracts/FiatSettlementCondition.d.ts.map +0 -1
- package/dist/contracts/FiatSettlementCondition.js +0 -18
- package/dist/contracts/FixedPaymentTemplate.d.ts +0 -14
- package/dist/contracts/FixedPaymentTemplate.d.ts.map +0 -1
- package/dist/contracts/FixedPaymentTemplate.js +0 -63
- package/dist/contracts/NFT1155Base.d.ts +0 -50
- package/dist/contracts/NFT1155Base.d.ts.map +0 -1
- package/dist/contracts/NFT1155Base.js +0 -24
- package/dist/contracts/NFT1155Credits.d.ts +0 -6
- package/dist/contracts/NFT1155Credits.d.ts.map +0 -1
- package/dist/contracts/NFT1155Credits.js +0 -9
- package/dist/contracts/NFT1155ExpirableCredits.d.ts +0 -34
- package/dist/contracts/NFT1155ExpirableCredits.d.ts.map +0 -1
- package/dist/contracts/NFT1155ExpirableCredits.js +0 -18
- package/dist/contracts/NVMConfig.d.ts +0 -10
- package/dist/contracts/NVMConfig.d.ts.map +0 -1
- package/dist/contracts/NVMConfig.js +0 -18
- package/dist/contracts/PayAsYouGoTemplate.d.ts +0 -13
- package/dist/contracts/PayAsYouGoTemplate.d.ts.map +0 -1
- package/dist/contracts/PayAsYouGoTemplate.js +0 -59
- package/dist/contracts/ProtocolStandardFees.d.ts +0 -9
- package/dist/contracts/ProtocolStandardFees.d.ts.map +0 -1
- package/dist/contracts/ProtocolStandardFees.js +0 -15
- package/dist/contracts/Roles.d.ts +0 -13
- package/dist/contracts/Roles.d.ts.map +0 -1
- package/dist/contracts/Roles.js +0 -12
- package/dist/contracts/index.d.ts +0 -3
- package/dist/contracts/index.d.ts.map +0 -1
- package/dist/contracts/index.js +0 -2
- package/dist/errors/NeverminedErrors.d.ts +0 -74
- package/dist/errors/NeverminedErrors.d.ts.map +0 -1
- package/dist/errors/NeverminedErrors.js +0 -128
- package/dist/errors/index.d.ts +0 -2
- package/dist/errors/index.d.ts.map +0 -1
- package/dist/errors/index.js +0 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -8
- package/dist/models/AgentAccessToken.d.ts +0 -123
- package/dist/models/AgentAccessToken.d.ts.map +0 -1
- package/dist/models/AgentAccessToken.js +0 -164
- package/dist/models/AgentX402AccessToken.d.ts +0 -59
- package/dist/models/AgentX402AccessToken.d.ts.map +0 -1
- package/dist/models/AgentX402AccessToken.js +0 -78
- package/dist/models/Logger.d.ts +0 -9
- package/dist/models/Logger.d.ts.map +0 -1
- package/dist/models/Logger.js +0 -27
- package/dist/models/NeverminedOptions.d.ts +0 -30
- package/dist/models/NeverminedOptions.d.ts.map +0 -1
- package/dist/models/NeverminedOptions.js +0 -28
- package/dist/models/NvmApiKey.d.ts +0 -137
- package/dist/models/NvmApiKey.d.ts.map +0 -1
- package/dist/models/NvmApiKey.js +0 -235
- package/dist/models/Transactions.d.ts +0 -11
- package/dist/models/Transactions.d.ts.map +0 -1
- package/dist/models/Transactions.js +0 -1
- package/dist/models/index.d.ts +0 -7
- package/dist/models/index.d.ts.map +0 -1
- package/dist/models/index.js +0 -6
- package/dist/nevermined/Nevermined.d.ts +0 -48
- package/dist/nevermined/Nevermined.d.ts.map +0 -1
- package/dist/nevermined/Nevermined.js +0 -72
- package/dist/nevermined/api/PaymentsApi.d.ts +0 -25
- package/dist/nevermined/api/PaymentsApi.d.ts.map +0 -1
- package/dist/nevermined/api/PaymentsApi.js +0 -177
- package/dist/nevermined/api/ServicesApi.d.ts +0 -23
- package/dist/nevermined/api/ServicesApi.d.ts.map +0 -1
- package/dist/nevermined/api/ServicesApi.js +0 -27
- package/dist/nevermined/api/UtilsApi.d.ts +0 -28
- package/dist/nevermined/api/UtilsApi.d.ts.map +0 -1
- package/dist/nevermined/api/UtilsApi.js +0 -33
- package/dist/nevermined/index.d.ts +0 -3
- package/dist/nevermined/index.d.ts.map +0 -1
- package/dist/nevermined/index.js +0 -2
- package/dist/nevermined/utils/AgentUtils.d.ts +0 -8
- package/dist/nevermined/utils/AgentUtils.d.ts.map +0 -1
- package/dist/nevermined/utils/AgentUtils.js +0 -56
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts +0 -280
- package/dist/nevermined/utils/BlockchainViemUtils.d.ts.map +0 -1
- package/dist/nevermined/utils/BlockchainViemUtils.js +0 -408
- package/dist/nevermined/utils/JwtUtils.d.ts +0 -27
- package/dist/nevermined/utils/JwtUtils.d.ts.map +0 -1
- package/dist/nevermined/utils/JwtUtils.js +0 -161
- package/dist/nevermined/utils/SignatureUtils.d.ts +0 -14
- package/dist/nevermined/utils/SignatureUtils.d.ts.map +0 -1
- package/dist/nevermined/utils/SignatureUtils.js +0 -99
- package/dist/nevermined/utils/WebServiceConnector.d.ts +0 -30
- package/dist/nevermined/utils/WebServiceConnector.d.ts.map +0 -1
- package/dist/nevermined/utils/WebServiceConnector.js +0 -170
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts +0 -36
- package/dist/nevermined/utils/ZeroDevPolicies.d.ts.map +0 -1
- package/dist/nevermined/utils/ZeroDevPolicies.js +0 -152
- package/dist/nevermined/utils/index.d.ts +0 -7
- package/dist/nevermined/utils/index.d.ts.map +0 -1
- package/dist/nevermined/utils/index.js +0 -6
- package/dist/services/Api.d.ts +0 -7
- package/dist/services/Api.d.ts.map +0 -1
- package/dist/services/Api.js +0 -25
- package/dist/services/Profiles.d.ts +0 -16
- package/dist/services/Profiles.d.ts.map +0 -1
- package/dist/services/Profiles.js +0 -84
- package/dist/services/index.d.ts +0 -3
- package/dist/services/index.d.ts.map +0 -1
- package/dist/services/index.js +0 -2
- package/dist/utils/ConversionTypeHelpers.d.ts +0 -5
- package/dist/utils/ConversionTypeHelpers.d.ts.map +0 -1
- package/dist/utils/ConversionTypeHelpers.js +0 -30
- package/dist/utils/Network.d.ts +0 -5
- package/dist/utils/Network.d.ts.map +0 -1
- package/dist/utils/Network.js +0 -224
- package/dist/utils/helpers.d.ts +0 -23
- package/dist/utils/helpers.d.ts.map +0 -1
- package/dist/utils/helpers.js +0 -161
- package/dist/utils/index.d.ts +0 -4
- package/dist/utils/index.d.ts.map +0 -1
- package/dist/utils/index.js +0 -3
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA;AACpC,cAAc,mBAAmB,CAAA;AACjC,cAAc,uBAAuB,CAAA;AACrC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,mBAAmB,CAAA;AAEjC,cAAc,4BAA4B,CAAA;AAG1C,cAAc,kBAAkB,CAAA"}
|
package/dist/index.js
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './contracts/index.js';
|
|
2
|
-
export * from './models/index.js';
|
|
3
|
-
export * from './nevermined/index.js';
|
|
4
|
-
export * from './nevermined/Nevermined.js';
|
|
5
|
-
export * from './errors/index.js';
|
|
6
|
-
export * from './Instantiable.abstract.js';
|
|
7
|
-
// Utils
|
|
8
|
-
export * from './utils/index.js';
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { JWTPayload } from 'jose';
|
|
2
|
-
import { Account } from 'viem';
|
|
3
|
-
import { SmartAccount } from 'viem/account-abstraction';
|
|
4
|
-
import { SignatureUtils } from '../nevermined/utils/SignatureUtils.js';
|
|
5
|
-
/**
|
|
6
|
-
* The access to remote agents is granted through an authorization token.
|
|
7
|
-
* This token is generated using the AgentAccessToken JWT structure.
|
|
8
|
-
* AgentAccessToken:
|
|
9
|
-
* authToken: JWTAuthTokenParams
|
|
10
|
-
* proof: JWTRedemptionProofParams
|
|
11
|
-
*/
|
|
12
|
-
export interface JWTAuthTokenParams {
|
|
13
|
-
/**
|
|
14
|
-
* The agent identifier related with the authorization token.
|
|
15
|
-
*/
|
|
16
|
-
agentId: string;
|
|
17
|
-
/**
|
|
18
|
-
* The plan identifier related with the authorization token.
|
|
19
|
-
*/
|
|
20
|
-
planId: string;
|
|
21
|
-
/**
|
|
22
|
-
* The public address of the account the key is issued for.
|
|
23
|
-
*/
|
|
24
|
-
sub: `0x${string}`;
|
|
25
|
-
/**
|
|
26
|
-
* The public address of the account issuing the key.
|
|
27
|
-
*/
|
|
28
|
-
iss?: `0x${string}`;
|
|
29
|
-
/**
|
|
30
|
-
* The chain id of the network the token is valid for. If zero the key is not having any network limitation
|
|
31
|
-
*/
|
|
32
|
-
aud?: string;
|
|
33
|
-
/**
|
|
34
|
-
* JWT Expiration Time
|
|
35
|
-
*
|
|
36
|
-
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.4 RFC7519#section-4.1.4}
|
|
37
|
-
*/
|
|
38
|
-
exp?: number;
|
|
39
|
-
/**
|
|
40
|
-
* JWT Issued At
|
|
41
|
-
*
|
|
42
|
-
* @see {@link https://www.rfc-editor.org/rfc/rfc7519#section-4.1.6 RFC7519#section-4.1.6}
|
|
43
|
-
*/
|
|
44
|
-
iat?: number;
|
|
45
|
-
[key: string]: unknown;
|
|
46
|
-
}
|
|
47
|
-
export interface JWTRedemptionProofParams {
|
|
48
|
-
keyspace: string;
|
|
49
|
-
nonce: string;
|
|
50
|
-
planIds: string[];
|
|
51
|
-
}
|
|
52
|
-
export declare class AgentAccessToken implements JWTPayload {
|
|
53
|
-
/**
|
|
54
|
-
* The version of the access token
|
|
55
|
-
*/
|
|
56
|
-
ver?: string;
|
|
57
|
-
/**
|
|
58
|
-
* The authorization token used to query the agent.
|
|
59
|
-
* This token is validated by the agent or proxy to ensure the request is authorized
|
|
60
|
-
* {@see {@link AgentAuthTokenParams}}
|
|
61
|
-
*/
|
|
62
|
-
authToken?: string;
|
|
63
|
-
/**
|
|
64
|
-
* The proof generated by the subscriber (sub) to prove the request to query the agent
|
|
65
|
-
* {@see {@link JWTRedemptionProofParams}
|
|
66
|
-
*/
|
|
67
|
-
proof?: string;
|
|
68
|
-
iss?: string | undefined;
|
|
69
|
-
sub?: string | undefined;
|
|
70
|
-
aud?: string | string[] | undefined;
|
|
71
|
-
exp?: number;
|
|
72
|
-
iat?: number;
|
|
73
|
-
[propName: string]: unknown;
|
|
74
|
-
_signatureUtils: SignatureUtils;
|
|
75
|
-
_issuerAccount: Account | SmartAccount;
|
|
76
|
-
private constructor();
|
|
77
|
-
/**
|
|
78
|
-
* It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
|
|
79
|
-
* The string representing this key can be used to authenticate against the Nevermined API.
|
|
80
|
-
* @param signatureUtils The SignatureUtils instance
|
|
81
|
-
* @param issuerAccount The account issuing the key
|
|
82
|
-
|
|
83
|
-
*/
|
|
84
|
-
static generate(signatureUtils: SignatureUtils, issuerAccount: Account | SmartAccount, agentId: string | bigint, planId: string | bigint, subscriberAddress: `0x${string}`, expirationTime?: number | string, version?: string): Promise<AgentAccessToken>;
|
|
85
|
-
setRedemptionProof(keyspace: string, nonce: string): Promise<this>;
|
|
86
|
-
decodeAuthToken(): JWTAuthTokenParams;
|
|
87
|
-
/**
|
|
88
|
-
* It serializes the NVM Api Key into a string
|
|
89
|
-
* @returns a string representing the NVM API Key
|
|
90
|
-
*/
|
|
91
|
-
serialize(): string;
|
|
92
|
-
/**
|
|
93
|
-
* It serializes the NVM Api Key into a string
|
|
94
|
-
* @returns a string representing the NVM API Key
|
|
95
|
-
*/
|
|
96
|
-
toString(): string;
|
|
97
|
-
/**
|
|
98
|
-
* It generates a signed JWT from the NvmApiKey
|
|
99
|
-
* @param signatureUtils The SignatureUtils instance
|
|
100
|
-
* @param issuerAccount The account issuing the key
|
|
101
|
-
* @returns the string in JWT format represeting the NvmApiKey
|
|
102
|
-
*/
|
|
103
|
-
toJWT(): Promise<string>;
|
|
104
|
-
static fromJWT(jwtString: string, signatureUtils: SignatureUtils, issuerAddress: Account | SmartAccount): AgentAccessToken;
|
|
105
|
-
/**
|
|
106
|
-
* It decodes a string JWT into a JWTPayload
|
|
107
|
-
* @param str jwt string
|
|
108
|
-
* @returns the JWTPayload
|
|
109
|
-
*/
|
|
110
|
-
static decodeJWT(str: string): JWTPayload;
|
|
111
|
-
/**
|
|
112
|
-
* It generates the hash of the NvmApiKey
|
|
113
|
-
* @returns a string representing the hash of the NvmApiKey
|
|
114
|
-
*/
|
|
115
|
-
hash(): string;
|
|
116
|
-
/**
|
|
117
|
-
* Given a serialized string, it generates the hash
|
|
118
|
-
* @param serialized the serialized string
|
|
119
|
-
* @returns the hash
|
|
120
|
-
*/
|
|
121
|
-
static hash(serialized: string): string;
|
|
122
|
-
}
|
|
123
|
-
//# sourceMappingURL=AgentAccessToken.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentAccessToken.d.ts","sourceRoot":"","sources":["../../src/models/Ag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,EAAE,MAAM,GAAG,OAAO,CAAA;IAE3B,eAAe,EAAE,cAAc,CAAA;IAC/B,cAAc,EAAE,OAAO,GAAG,YAAY,CAAA;IAEtC,OAAO;IAMP;;;;;;OAMG;WACiB,QAAQ,CAC1B,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,OAAO,GAAG,YAAY,EACrC,OAAO,EAAE,MAAM,GAAG,MAAM,EACxB,MAAM,EAAE,MAAM,GAAG,MAAM,EACvB,iBAAiB,EAAE,KAAK,MAAM,EAAE,EAChC,cAAc,GAAE,MAAM,GAAG,MAAa,EACtC,OAAO,SAAM,GACZ,OAAO,CAAC,gBAAgB,CAAC;IA8Bf,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAWxD,eAAe,IAAI,kBAAkB;IAiB5C;;;OAGG;IACI,SAAS,IAAI,MAAM;IAI1B;;;OAGG;IACI,QAAQ,IAAI,MAAM;IAUzB;;;;;OAKG;IACU,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;WAYvB,OAAO,CACnB,SAAS,EAAE,MAAM,EACjB,cAAc,EAAE,cAAc,EAC9B,aAAa,EAAE,OAAO,GAAG,YAAY,GACpC,gBAAgB;IAWnB;;;;OAIG;WACW,SAAS,CAAC,GAAG,EAAE,MAAM;IAInC;;;OAGG;IACI,IAAI;IAIX;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM;CAG/B"}
|
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import { decodeJwt } from 'jose';
|
|
2
|
-
import { getChecksumAddress } from '../nevermined/utils/BlockchainViemUtils.js';
|
|
3
|
-
import { EthSignJWT } from '../nevermined/utils/JwtUtils.js';
|
|
4
|
-
import { SignatureUtils } from '../nevermined/utils/SignatureUtils.js';
|
|
5
|
-
export class AgentAccessToken {
|
|
6
|
-
/**
|
|
7
|
-
* The version of the access token
|
|
8
|
-
*/
|
|
9
|
-
ver;
|
|
10
|
-
/**
|
|
11
|
-
* The authorization token used to query the agent.
|
|
12
|
-
* This token is validated by the agent or proxy to ensure the request is authorized
|
|
13
|
-
* {@see {@link AgentAuthTokenParams}}
|
|
14
|
-
*/
|
|
15
|
-
authToken;
|
|
16
|
-
/**
|
|
17
|
-
* The proof generated by the subscriber (sub) to prove the request to query the agent
|
|
18
|
-
* {@see {@link JWTRedemptionProofParams}
|
|
19
|
-
*/
|
|
20
|
-
proof;
|
|
21
|
-
iss;
|
|
22
|
-
sub;
|
|
23
|
-
aud;
|
|
24
|
-
exp;
|
|
25
|
-
iat;
|
|
26
|
-
_signatureUtils;
|
|
27
|
-
_issuerAccount;
|
|
28
|
-
constructor(signatureUtils, issuerAccount) {
|
|
29
|
-
this.ver = '1';
|
|
30
|
-
this._signatureUtils = signatureUtils;
|
|
31
|
-
this._issuerAccount = issuerAccount;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* It generates a new serialized and encrypted NvmApiKey including the ZeroDev session key and the Marketplace auth token.
|
|
35
|
-
* The string representing this key can be used to authenticate against the Nevermined API.
|
|
36
|
-
* @param signatureUtils The SignatureUtils instance
|
|
37
|
-
* @param issuerAccount The account issuing the key
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
static async generate(signatureUtils, issuerAccount, agentId, planId, subscriberAddress, expirationTime = '1y', version = '1') {
|
|
41
|
-
const issuerAddress = getChecksumAddress(issuerAccount.address);
|
|
42
|
-
const chainId = signatureUtils.client.chain?.id || 0;
|
|
43
|
-
const sub = getChecksumAddress(subscriberAddress);
|
|
44
|
-
const jwtAuth = {
|
|
45
|
-
iss: issuerAddress,
|
|
46
|
-
aud: chainId.toString(),
|
|
47
|
-
sub,
|
|
48
|
-
agentId: typeof agentId === 'bigint' ? agentId.toString() : agentId,
|
|
49
|
-
planId: typeof planId === 'bigint' ? planId.toString() : planId,
|
|
50
|
-
};
|
|
51
|
-
const signedJWTAuth = await new EthSignJWT(jwtAuth)
|
|
52
|
-
.setProtectedHeader({ alg: 'ES256K' })
|
|
53
|
-
.setIssuedAt()
|
|
54
|
-
.setExpirationTime(expirationTime)
|
|
55
|
-
.ethSign(signatureUtils, issuerAccount);
|
|
56
|
-
// const jwtAccessToken: JWTAgentAccessToken = {
|
|
57
|
-
// ver: version,
|
|
58
|
-
// authToken: signedJWTAuth,
|
|
59
|
-
// proof: undefined, // This can be set later when the proof is generated
|
|
60
|
-
// }
|
|
61
|
-
const agentAccessToken = new AgentAccessToken(signatureUtils, issuerAccount);
|
|
62
|
-
agentAccessToken.ver = version;
|
|
63
|
-
agentAccessToken.authToken = signedJWTAuth;
|
|
64
|
-
agentAccessToken.proof = undefined; // This can be set later when the proof is generated
|
|
65
|
-
return agentAccessToken;
|
|
66
|
-
}
|
|
67
|
-
async setRedemptionProof(keyspace, nonce) {
|
|
68
|
-
const jwtPayload = decodeJwt(this.authToken);
|
|
69
|
-
const proofParams = {
|
|
70
|
-
keyspace,
|
|
71
|
-
nonce,
|
|
72
|
-
planIds: [String(jwtPayload.planId)],
|
|
73
|
-
};
|
|
74
|
-
this.proof = JSON.stringify(proofParams);
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
decodeAuthToken() {
|
|
78
|
-
if (!this.authToken) {
|
|
79
|
-
throw new Error('Auth token is not set');
|
|
80
|
-
}
|
|
81
|
-
const jwt = decodeJwt(this.authToken);
|
|
82
|
-
return {
|
|
83
|
-
agentId: jwt.agentId,
|
|
84
|
-
planId: jwt.planId,
|
|
85
|
-
sub: jwt.sub,
|
|
86
|
-
iss: jwt.iss,
|
|
87
|
-
aud: jwt.aud,
|
|
88
|
-
exp: jwt.exp,
|
|
89
|
-
iat: jwt.iat,
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* It serializes the NVM Api Key into a string
|
|
94
|
-
* @returns a string representing the NVM API Key
|
|
95
|
-
*/
|
|
96
|
-
serialize() {
|
|
97
|
-
return this.toString();
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* It serializes the NVM Api Key into a string
|
|
101
|
-
* @returns a string representing the NVM API Key
|
|
102
|
-
*/
|
|
103
|
-
toString() {
|
|
104
|
-
const params = {};
|
|
105
|
-
Object.keys(this)
|
|
106
|
-
.filter((val) => val !== undefined)
|
|
107
|
-
.forEach((key) => {
|
|
108
|
-
if (!key.startsWith('_'))
|
|
109
|
-
params[key] = this[key];
|
|
110
|
-
});
|
|
111
|
-
return JSON.stringify(params);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* It generates a signed JWT from the NvmApiKey
|
|
115
|
-
* @param signatureUtils The SignatureUtils instance
|
|
116
|
-
* @param issuerAccount The account issuing the key
|
|
117
|
-
* @returns the string in JWT format represeting the NvmApiKey
|
|
118
|
-
*/
|
|
119
|
-
async toJWT() {
|
|
120
|
-
const params = {};
|
|
121
|
-
Object.keys(this)
|
|
122
|
-
.filter((val) => val !== undefined)
|
|
123
|
-
.forEach((key) => {
|
|
124
|
-
if (!key.startsWith('_'))
|
|
125
|
-
params[key] = this[key];
|
|
126
|
-
});
|
|
127
|
-
const jwt = new EthSignJWT(params).setProtectedHeader({ alg: 'ES256K' });
|
|
128
|
-
return jwt.ethSign(this._signatureUtils, this._issuerAccount);
|
|
129
|
-
}
|
|
130
|
-
static fromJWT(jwtString, signatureUtils, issuerAddress) {
|
|
131
|
-
const jwt = AgentAccessToken.decodeJWT(jwtString);
|
|
132
|
-
const agentAccessToken = new AgentAccessToken(signatureUtils, issuerAddress);
|
|
133
|
-
Object.keys(jwt)
|
|
134
|
-
.filter((val) => val !== undefined)
|
|
135
|
-
.forEach((key) => {
|
|
136
|
-
if (!key.startsWith('_'))
|
|
137
|
-
agentAccessToken[key] = jwt[key];
|
|
138
|
-
});
|
|
139
|
-
return agentAccessToken;
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* It decodes a string JWT into a JWTPayload
|
|
143
|
-
* @param str jwt string
|
|
144
|
-
* @returns the JWTPayload
|
|
145
|
-
*/
|
|
146
|
-
static decodeJWT(str) {
|
|
147
|
-
return decodeJwt(str);
|
|
148
|
-
}
|
|
149
|
-
/**
|
|
150
|
-
* It generates the hash of the NvmApiKey
|
|
151
|
-
* @returns a string representing the hash of the NvmApiKey
|
|
152
|
-
*/
|
|
153
|
-
hash() {
|
|
154
|
-
return SignatureUtils.hash(this.serialize());
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Given a serialized string, it generates the hash
|
|
158
|
-
* @param serialized the serialized string
|
|
159
|
-
* @returns the hash
|
|
160
|
-
*/
|
|
161
|
-
static hash(serialized) {
|
|
162
|
-
return SignatureUtils.hash(serialized);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"AgentX402AccessToken.d.ts","sourceRoot":"","sources":["../../src/models/AgentX402AccessToken.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,YAAY,EAAgC,MAAM,MAAM,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAEvD,MAAM,MAAM,oBAAoB,GAAG;IACjC,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,OAAO,EAAE;QACP,SAAS,EAAE,KAAK,MAAM,EAAE,CAAA;QACxB,aAAa,EAAE;YACb,mBAAmB,EAAE,MAAM,CAAA;YAC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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"}
|
|
@@ -1,78 +0,0 @@
|
|
|
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/Logger.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Logger as PinoLogger } from 'pino';
|
|
2
|
-
export type LogLevel = 'fatal' | 'error' | 'warn' | 'info' | 'debug' | 'trace' | 'silent';
|
|
3
|
-
export interface LoggerConfig {
|
|
4
|
-
level?: LogLevel;
|
|
5
|
-
pretty?: boolean;
|
|
6
|
-
}
|
|
7
|
-
export declare const createLogger: (config?: LoggerConfig) => PinoLogger<never, boolean>;
|
|
8
|
-
export declare const LoggerInstance: () => PinoLogger;
|
|
9
|
-
//# sourceMappingURL=Logger.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Logger.d.ts","sourceRoot":"","sources":["../../src/models/Logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM,CAAA;AAEjD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;AAEzF,MAAM,WAAW,YAAY;IAC3B,KAAK,CAAC,EAAE,QAAQ,CAAA;IAChB,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAID,eAAO,MAAM,YAAY,GAAI,SAAQ,YAAiB,+BAgBrD,CAAA;AAED,eAAO,MAAM,cAAc,kBAQ1B,CAAA"}
|
package/dist/models/Logger.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { pino } from 'pino';
|
|
2
|
-
let loggerInstance;
|
|
3
|
-
export const createLogger = (config = {}) => {
|
|
4
|
-
const { level = 'info', pretty = false } = config;
|
|
5
|
-
return pino({
|
|
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
|
-
},
|
|
15
|
-
}
|
|
16
|
-
: undefined,
|
|
17
|
-
});
|
|
18
|
-
};
|
|
19
|
-
export const LoggerInstance = () => {
|
|
20
|
-
if (!loggerInstance) {
|
|
21
|
-
loggerInstance = createLogger({
|
|
22
|
-
level: 'debug',
|
|
23
|
-
pretty: true,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return loggerInstance;
|
|
27
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
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
|
-
agentsProxy?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Log level.
|
|
18
|
-
*/
|
|
19
|
-
logLevel: string;
|
|
20
|
-
accounts?: Account[];
|
|
21
|
-
/**
|
|
22
|
-
* ZeroDev project id
|
|
23
|
-
*/
|
|
24
|
-
zeroDevProjectId?: string;
|
|
25
|
-
/**
|
|
26
|
-
* Contracts version
|
|
27
|
-
*/
|
|
28
|
-
contractsVersion?: string;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=NeverminedOptions.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,28 +0,0 @@
|
|
|
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
|
-
}
|