@chaoschain/sdk 0.1.0 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +286 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +286 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -679,7 +679,12 @@ var ChaosAgent = class {
|
|
|
679
679
|
*/
|
|
680
680
|
async registerIdentity(metadata) {
|
|
681
681
|
const uri = metadata ? `data:application/json,${JSON.stringify(metadata)}` : "";
|
|
682
|
-
|
|
682
|
+
let tx;
|
|
683
|
+
if (uri) {
|
|
684
|
+
tx = await this.identityContract["register(string)"](uri);
|
|
685
|
+
} else {
|
|
686
|
+
tx = await this.identityContract["register()"]();
|
|
687
|
+
}
|
|
683
688
|
const receipt = await tx.wait();
|
|
684
689
|
const event = receipt.logs.map((log) => {
|
|
685
690
|
try {
|
|
@@ -690,9 +695,9 @@ var ChaosAgent = class {
|
|
|
690
695
|
} catch {
|
|
691
696
|
return null;
|
|
692
697
|
}
|
|
693
|
-
}).find((e) => e?.name === "
|
|
698
|
+
}).find((e) => e?.name === "Registered");
|
|
694
699
|
if (!event) {
|
|
695
|
-
throw new Error("
|
|
700
|
+
throw new Error("Registered event not found");
|
|
696
701
|
}
|
|
697
702
|
return {
|
|
698
703
|
agentId: event.args.agentId,
|
|
@@ -705,7 +710,7 @@ var ChaosAgent = class {
|
|
|
705
710
|
*/
|
|
706
711
|
async getAgentMetadata(agentId) {
|
|
707
712
|
try {
|
|
708
|
-
const uri = await this.identityContract.
|
|
713
|
+
const uri = await this.identityContract.tokenURI(agentId);
|
|
709
714
|
if (!uri) {
|
|
710
715
|
return null;
|
|
711
716
|
}
|
|
@@ -732,7 +737,7 @@ var ChaosAgent = class {
|
|
|
732
737
|
* Set agent URI
|
|
733
738
|
*/
|
|
734
739
|
async setAgentUri(agentId, uri) {
|
|
735
|
-
const tx = await this.identityContract.
|
|
740
|
+
const tx = await this.identityContract.setAgentUri(agentId, uri);
|
|
736
741
|
const receipt = await tx.wait();
|
|
737
742
|
return receipt.hash;
|
|
738
743
|
}
|
|
@@ -815,71 +820,152 @@ var ChaosAgent = class {
|
|
|
815
820
|
}
|
|
816
821
|
}
|
|
817
822
|
/**
|
|
818
|
-
* Give feedback to an agent
|
|
823
|
+
* Give feedback to an agent (ERC-8004 v1.0)
|
|
824
|
+
*
|
|
825
|
+
* @param params Feedback parameters including agentId, rating, feedbackUri, and optional auth
|
|
826
|
+
* @returns Transaction hash
|
|
819
827
|
*/
|
|
820
828
|
async giveFeedback(params) {
|
|
821
|
-
const { agentId, rating, feedbackUri } = params;
|
|
829
|
+
const { agentId, rating, feedbackUri, feedbackData } = params;
|
|
822
830
|
if (rating < 0 || rating > 100) {
|
|
823
831
|
throw new Error("Rating must be between 0 and 100");
|
|
824
832
|
}
|
|
825
|
-
const
|
|
833
|
+
const score = rating;
|
|
834
|
+
const tag1 = feedbackData?.tag1 || ethers.ZeroHash;
|
|
835
|
+
const tag2 = feedbackData?.tag2 || ethers.ZeroHash;
|
|
836
|
+
const feedbackContent = feedbackData?.content || feedbackUri;
|
|
837
|
+
const feedbackHash = ethers.keccak256(ethers.toUtf8Bytes(feedbackContent));
|
|
838
|
+
const feedbackAuth = feedbackData?.feedbackAuth || "0x";
|
|
839
|
+
const tx = await this.reputationContract.giveFeedback(
|
|
840
|
+
agentId,
|
|
841
|
+
score,
|
|
842
|
+
tag1,
|
|
843
|
+
tag2,
|
|
844
|
+
feedbackUri,
|
|
845
|
+
feedbackHash,
|
|
846
|
+
feedbackAuth
|
|
847
|
+
);
|
|
826
848
|
const receipt = await tx.wait();
|
|
827
849
|
return receipt.hash;
|
|
828
850
|
}
|
|
829
851
|
/**
|
|
830
|
-
* Revoke feedback
|
|
852
|
+
* Revoke feedback (ERC-8004 v1.0)
|
|
853
|
+
* @param agentId Agent ID that received the feedback
|
|
854
|
+
* @param feedbackIndex Index of the feedback to revoke (uint64)
|
|
831
855
|
*/
|
|
832
|
-
async revokeFeedback(
|
|
833
|
-
const tx = await this.reputationContract.revokeFeedback(
|
|
856
|
+
async revokeFeedback(agentId, feedbackIndex) {
|
|
857
|
+
const tx = await this.reputationContract.revokeFeedback(agentId, feedbackIndex);
|
|
834
858
|
const receipt = await tx.wait();
|
|
835
859
|
return receipt.hash;
|
|
836
860
|
}
|
|
837
861
|
/**
|
|
838
|
-
* Append response to feedback
|
|
862
|
+
* Append response to feedback (ERC-8004 v1.0)
|
|
863
|
+
* @param agentId Agent ID that received the feedback
|
|
864
|
+
* @param clientAddress Address of the client who gave feedback
|
|
865
|
+
* @param feedbackIndex Index of the feedback
|
|
866
|
+
* @param responseUri URI containing the response data
|
|
867
|
+
* @param responseHash Hash of the response content
|
|
839
868
|
*/
|
|
840
|
-
async appendResponse(
|
|
841
|
-
const tx = await this.reputationContract.appendResponse(
|
|
869
|
+
async appendResponse(agentId, clientAddress, feedbackIndex, responseUri, responseHash) {
|
|
870
|
+
const tx = await this.reputationContract.appendResponse(
|
|
871
|
+
agentId,
|
|
872
|
+
clientAddress,
|
|
873
|
+
feedbackIndex,
|
|
874
|
+
responseUri,
|
|
875
|
+
responseHash
|
|
876
|
+
);
|
|
842
877
|
const receipt = await tx.wait();
|
|
843
878
|
return receipt.hash;
|
|
844
879
|
}
|
|
845
880
|
/**
|
|
846
|
-
*
|
|
881
|
+
* Read specific feedback (ERC-8004 v1.0)
|
|
882
|
+
* @param agentId Agent ID that received the feedback
|
|
883
|
+
* @param clientAddress Address of the client who gave feedback
|
|
884
|
+
* @param index Index of the feedback
|
|
885
|
+
*/
|
|
886
|
+
async readFeedback(agentId, clientAddress, index) {
|
|
887
|
+
const feedback = await this.reputationContract.readFeedback(agentId, clientAddress, index);
|
|
888
|
+
return {
|
|
889
|
+
score: Number(feedback.score),
|
|
890
|
+
tag1: feedback.tag1,
|
|
891
|
+
tag2: feedback.tag2,
|
|
892
|
+
isRevoked: feedback.isRevoked
|
|
893
|
+
};
|
|
894
|
+
}
|
|
895
|
+
/**
|
|
896
|
+
* Read all feedback for an agent (ERC-8004 v1.0)
|
|
897
|
+
* @param agentId Agent ID
|
|
898
|
+
* @param clientAddresses Array of client addresses (empty array for all clients)
|
|
899
|
+
* @param tag1 First tag filter (ZeroHash for no filter)
|
|
900
|
+
* @param tag2 Second tag filter (ZeroHash for no filter)
|
|
901
|
+
* @param includeRevoked Whether to include revoked feedback
|
|
902
|
+
*/
|
|
903
|
+
async readAllFeedback(agentId, clientAddresses = [], tag1 = ethers.ZeroHash, tag2 = ethers.ZeroHash, includeRevoked = false) {
|
|
904
|
+
const result = await this.reputationContract.readAllFeedback(
|
|
905
|
+
agentId,
|
|
906
|
+
clientAddresses,
|
|
907
|
+
tag1,
|
|
908
|
+
tag2,
|
|
909
|
+
includeRevoked
|
|
910
|
+
);
|
|
911
|
+
return {
|
|
912
|
+
clients: result.clients,
|
|
913
|
+
scores: result.scores.map((s) => Number(s)),
|
|
914
|
+
tag1s: result.tag1s,
|
|
915
|
+
tag2s: result.tag2s,
|
|
916
|
+
revokedStatuses: result.revokedStatuses
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* Get summary statistics (ERC-8004 v1.0)
|
|
921
|
+
* @param agentId Agent ID
|
|
922
|
+
* @param clientAddresses Array of client addresses (empty array for all clients)
|
|
923
|
+
* @param tag1 First tag filter (ZeroHash for no filter)
|
|
924
|
+
* @param tag2 Second tag filter (ZeroHash for no filter)
|
|
847
925
|
*/
|
|
848
|
-
async
|
|
849
|
-
const
|
|
926
|
+
async getSummary(agentId, clientAddresses = [], tag1 = ethers.ZeroHash, tag2 = ethers.ZeroHash) {
|
|
927
|
+
const result = await this.reputationContract.getSummary(agentId, clientAddresses, tag1, tag2);
|
|
850
928
|
return {
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
toAgent: feedback.toAgent,
|
|
854
|
-
rating: feedback.rating,
|
|
855
|
-
feedbackUri: feedback.feedbackURI,
|
|
856
|
-
timestamp: Number(feedback.timestamp),
|
|
857
|
-
revoked: feedback.revoked
|
|
929
|
+
count: result.count,
|
|
930
|
+
averageScore: Number(result.averageScore)
|
|
858
931
|
};
|
|
859
932
|
}
|
|
860
933
|
/**
|
|
861
|
-
* Get
|
|
934
|
+
* Get list of clients who gave feedback
|
|
935
|
+
* @param agentId Agent ID
|
|
936
|
+
*/
|
|
937
|
+
async getClients(agentId) {
|
|
938
|
+
return this.reputationContract.getClients(agentId);
|
|
939
|
+
}
|
|
940
|
+
/**
|
|
941
|
+
* Get last feedback index for a client
|
|
942
|
+
* @param agentId Agent ID
|
|
943
|
+
* @param clientAddress Client address
|
|
862
944
|
*/
|
|
863
|
-
async
|
|
864
|
-
return this.reputationContract.
|
|
945
|
+
async getLastIndex(agentId, clientAddress) {
|
|
946
|
+
return this.reputationContract.getLastIndex(agentId, clientAddress);
|
|
865
947
|
}
|
|
866
948
|
/**
|
|
867
|
-
* Get
|
|
949
|
+
* Get identity registry address from reputation contract
|
|
868
950
|
*/
|
|
869
|
-
async
|
|
870
|
-
return this.reputationContract.
|
|
951
|
+
async getIdentityRegistry() {
|
|
952
|
+
return this.reputationContract.getIdentityRegistry();
|
|
871
953
|
}
|
|
872
954
|
// ============================================================================
|
|
873
955
|
// Validation Registry Methods
|
|
874
956
|
// ============================================================================
|
|
875
957
|
/**
|
|
876
|
-
* Request validation from
|
|
958
|
+
* Request validation from a validator (ERC-8004 v1.0)
|
|
959
|
+
* @param validatorAddress Address of the validator
|
|
960
|
+
* @param agentId Agent ID requesting validation
|
|
961
|
+
* @param requestUri URI containing validation request data
|
|
962
|
+
* @param requestHash Hash of the request content (bytes32)
|
|
877
963
|
*/
|
|
878
|
-
async requestValidation(
|
|
879
|
-
const
|
|
880
|
-
const
|
|
881
|
-
|
|
882
|
-
|
|
964
|
+
async requestValidation(validatorAddress, agentId, requestUri, requestHash) {
|
|
965
|
+
const hashBytes = requestHash.startsWith("0x") ? requestHash : ethers.id(requestHash);
|
|
966
|
+
const tx = await this.validationContract.validationRequest(
|
|
967
|
+
validatorAddress,
|
|
968
|
+
agentId,
|
|
883
969
|
requestUri,
|
|
884
970
|
hashBytes
|
|
885
971
|
);
|
|
@@ -887,76 +973,112 @@ var ChaosAgent = class {
|
|
|
887
973
|
return receipt.hash;
|
|
888
974
|
}
|
|
889
975
|
/**
|
|
890
|
-
* Respond to validation request
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
976
|
+
* Respond to validation request (ERC-8004 v1.0)
|
|
977
|
+
* @param requestHash Hash of the original validation request (bytes32)
|
|
978
|
+
* @param response Response score (0-100, where 100 = approved)
|
|
979
|
+
* @param responseUri URI containing response data
|
|
980
|
+
* @param responseHash Hash of the response content (bytes32)
|
|
981
|
+
* @param tag Optional tag for categorization (bytes32)
|
|
982
|
+
*/
|
|
983
|
+
async respondToValidation(requestHash, response, responseUri, responseHash, tag = ethers.ZeroHash) {
|
|
984
|
+
if (response < 0 || response > 100) {
|
|
985
|
+
throw new Error("Response must be between 0 and 100");
|
|
986
|
+
}
|
|
987
|
+
const reqHashBytes = requestHash.startsWith("0x") ? requestHash : ethers.id(requestHash);
|
|
988
|
+
const resHashBytes = responseHash.startsWith("0x") ? responseHash : ethers.id(responseHash);
|
|
989
|
+
const tagBytes = tag.startsWith("0x") ? tag : ethers.ZeroHash;
|
|
990
|
+
const tx = await this.validationContract.validationResponse(
|
|
991
|
+
reqHashBytes,
|
|
992
|
+
response,
|
|
993
|
+
responseUri,
|
|
994
|
+
resHashBytes,
|
|
995
|
+
tagBytes
|
|
897
996
|
);
|
|
898
997
|
const receipt = await tx.wait();
|
|
899
998
|
return receipt.hash;
|
|
900
999
|
}
|
|
901
1000
|
/**
|
|
902
|
-
* Get validation
|
|
1001
|
+
* Get validation status (ERC-8004 v1.0)
|
|
1002
|
+
* @param requestHash Hash of the validation request (bytes32)
|
|
903
1003
|
*/
|
|
904
|
-
async
|
|
905
|
-
const
|
|
1004
|
+
async getValidationStatus(requestHash) {
|
|
1005
|
+
const hashBytes = requestHash.startsWith("0x") ? requestHash : ethers.id(requestHash);
|
|
1006
|
+
const result = await this.validationContract.getValidationStatus(hashBytes);
|
|
906
1007
|
return {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
responseUri: request.responseURI,
|
|
914
|
-
timestamp: Number(request.timestamp)
|
|
1008
|
+
validatorAddress: result.validatorAddress,
|
|
1009
|
+
agentId: result.agentId,
|
|
1010
|
+
response: Number(result.response),
|
|
1011
|
+
responseHash: result.responseHash,
|
|
1012
|
+
tag: result.tag,
|
|
1013
|
+
lastUpdate: result.lastUpdate
|
|
915
1014
|
};
|
|
916
1015
|
}
|
|
917
1016
|
/**
|
|
918
|
-
* Get
|
|
1017
|
+
* Get validation summary statistics (ERC-8004 v1.0)
|
|
1018
|
+
* @param agentId Agent ID
|
|
1019
|
+
* @param validatorAddresses Array of validator addresses (empty for all)
|
|
1020
|
+
* @param tag Tag filter (ZeroHash for no filter)
|
|
919
1021
|
*/
|
|
920
|
-
async
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
1022
|
+
async getValidationSummary(agentId, validatorAddresses = [], tag = ethers.ZeroHash) {
|
|
1023
|
+
const tagBytes = tag.startsWith("0x") ? tag : ethers.ZeroHash;
|
|
1024
|
+
const result = await this.validationContract.getSummary(agentId, validatorAddresses, tagBytes);
|
|
1025
|
+
return {
|
|
1026
|
+
count: result.count,
|
|
1027
|
+
avgResponse: Number(result.avgResponse)
|
|
1028
|
+
};
|
|
927
1029
|
}
|
|
928
1030
|
/**
|
|
929
|
-
* Get validation
|
|
1031
|
+
* Get all validation request hashes for an agent
|
|
1032
|
+
* @param agentId Agent ID
|
|
930
1033
|
*/
|
|
931
|
-
async
|
|
932
|
-
return this.validationContract.
|
|
1034
|
+
async getAgentValidations(agentId) {
|
|
1035
|
+
return this.validationContract.getAgentValidations(agentId);
|
|
1036
|
+
}
|
|
1037
|
+
/**
|
|
1038
|
+
* Get all validation requests for a validator
|
|
1039
|
+
* @param validatorAddress Validator address
|
|
1040
|
+
*/
|
|
1041
|
+
async getValidatorRequests(validatorAddress) {
|
|
1042
|
+
return this.validationContract.getValidatorRequests(validatorAddress);
|
|
1043
|
+
}
|
|
1044
|
+
/**
|
|
1045
|
+
* Get identity registry address from validation contract
|
|
1046
|
+
*/
|
|
1047
|
+
async getValidationIdentityRegistry() {
|
|
1048
|
+
return this.validationContract.getIdentityRegistry();
|
|
933
1049
|
}
|
|
934
1050
|
// ============================================================================
|
|
935
1051
|
// Event Listening
|
|
936
1052
|
// ============================================================================
|
|
937
1053
|
/**
|
|
938
|
-
* Listen for
|
|
1054
|
+
* Listen for Registered events
|
|
939
1055
|
*/
|
|
940
1056
|
onAgentRegistered(callback) {
|
|
941
|
-
this.identityContract.on("
|
|
1057
|
+
this.identityContract.on("Registered", callback);
|
|
942
1058
|
}
|
|
943
1059
|
/**
|
|
944
|
-
* Listen for
|
|
1060
|
+
* Listen for NewFeedback events (ERC-8004 v1.0)
|
|
945
1061
|
*/
|
|
946
|
-
|
|
947
|
-
this.reputationContract.on("
|
|
1062
|
+
onNewFeedback(callback) {
|
|
1063
|
+
this.reputationContract.on("NewFeedback", callback);
|
|
948
1064
|
}
|
|
949
1065
|
/**
|
|
950
|
-
* Listen for
|
|
1066
|
+
* Listen for ResponseAppended events (ERC-8004 v1.0)
|
|
951
1067
|
*/
|
|
952
|
-
|
|
953
|
-
this.
|
|
1068
|
+
onResponseAppended(callback) {
|
|
1069
|
+
this.reputationContract.on("ResponseAppended", callback);
|
|
954
1070
|
}
|
|
955
1071
|
/**
|
|
956
|
-
* Listen for
|
|
1072
|
+
* Listen for ValidationRequest events (ERC-8004 v1.0)
|
|
957
1073
|
*/
|
|
958
|
-
|
|
959
|
-
this.validationContract.on("
|
|
1074
|
+
onValidationRequest(callback) {
|
|
1075
|
+
this.validationContract.on("ValidationRequest", callback);
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Listen for ValidationResponse events (ERC-8004 v1.0)
|
|
1079
|
+
*/
|
|
1080
|
+
onValidationResponse(callback) {
|
|
1081
|
+
this.validationContract.on("ValidationResponse", callback);
|
|
960
1082
|
}
|
|
961
1083
|
/**
|
|
962
1084
|
* Remove all event listeners
|
|
@@ -3102,25 +3224,62 @@ var ChaosChainSDK = class {
|
|
|
3102
3224
|
return { feedbackTxHash: txHash, feedbackUri };
|
|
3103
3225
|
}
|
|
3104
3226
|
/**
|
|
3105
|
-
* Get agent reputation score
|
|
3227
|
+
* Get agent reputation score (ERC-8004 v1.0)
|
|
3228
|
+
*/
|
|
3229
|
+
async getReputationScore(agentId) {
|
|
3230
|
+
const summary = await this.chaosAgent.getSummary(agentId, [], ethers.ZeroHash, ethers.ZeroHash);
|
|
3231
|
+
return summary.averageScore;
|
|
3232
|
+
}
|
|
3233
|
+
/**
|
|
3234
|
+
* Read all feedback for an agent
|
|
3235
|
+
*/
|
|
3236
|
+
async readAllFeedback(agentId, clientAddresses = [], tag1 = ethers.ZeroHash, tag2 = ethers.ZeroHash, includeRevoked = false) {
|
|
3237
|
+
return this.chaosAgent.readAllFeedback(agentId, clientAddresses, tag1, tag2, includeRevoked);
|
|
3238
|
+
}
|
|
3239
|
+
/**
|
|
3240
|
+
* Get feedback summary statistics
|
|
3106
3241
|
*/
|
|
3107
|
-
async
|
|
3108
|
-
return
|
|
3242
|
+
async getFeedbackSummary(agentId, clientAddresses = [], tag1 = ethers.ZeroHash, tag2 = ethers.ZeroHash) {
|
|
3243
|
+
return this.chaosAgent.getSummary(agentId, clientAddresses, tag1, tag2);
|
|
3244
|
+
}
|
|
3245
|
+
/**
|
|
3246
|
+
* Get clients who gave feedback
|
|
3247
|
+
*/
|
|
3248
|
+
async getClients(agentId) {
|
|
3249
|
+
return this.chaosAgent.getClients(agentId);
|
|
3109
3250
|
}
|
|
3110
3251
|
// ============================================================================
|
|
3111
3252
|
// ERC-8004 Validation Methods
|
|
3112
3253
|
// ============================================================================
|
|
3113
3254
|
/**
|
|
3114
|
-
* Request validation from validator
|
|
3255
|
+
* Request validation from validator (ERC-8004 v1.0)
|
|
3256
|
+
*/
|
|
3257
|
+
async requestValidation(validatorAddress, agentId, requestUri, requestHash) {
|
|
3258
|
+
return this.chaosAgent.requestValidation(validatorAddress, agentId, requestUri, requestHash);
|
|
3259
|
+
}
|
|
3260
|
+
/**
|
|
3261
|
+
* Respond to validation request (ERC-8004 v1.0)
|
|
3262
|
+
*/
|
|
3263
|
+
async respondToValidation(requestHash, response, responseUri, responseHash, tag) {
|
|
3264
|
+
return this.chaosAgent.respondToValidation(requestHash, response, responseUri, responseHash, tag);
|
|
3265
|
+
}
|
|
3266
|
+
/**
|
|
3267
|
+
* Get validation status
|
|
3115
3268
|
*/
|
|
3116
|
-
async
|
|
3117
|
-
return this.chaosAgent.
|
|
3269
|
+
async getValidationStatus(requestHash) {
|
|
3270
|
+
return this.chaosAgent.getValidationStatus(requestHash);
|
|
3118
3271
|
}
|
|
3119
3272
|
/**
|
|
3120
|
-
*
|
|
3273
|
+
* Get validation summary for an agent
|
|
3121
3274
|
*/
|
|
3122
|
-
async
|
|
3123
|
-
return this.chaosAgent.
|
|
3275
|
+
async getValidationSummary(agentId, validatorAddresses = [], tag = ethers.ZeroHash) {
|
|
3276
|
+
return this.chaosAgent.getValidationSummary(agentId, validatorAddresses, tag);
|
|
3277
|
+
}
|
|
3278
|
+
/**
|
|
3279
|
+
* Get validation stats (alias for getValidationSummary)
|
|
3280
|
+
*/
|
|
3281
|
+
async getValidationStats(agentId) {
|
|
3282
|
+
return this.getValidationSummary(agentId);
|
|
3124
3283
|
}
|
|
3125
3284
|
// ============================================================================
|
|
3126
3285
|
// x402 Crypto Payment Methods
|
|
@@ -3170,6 +3329,36 @@ var ChaosChainSDK = class {
|
|
|
3170
3329
|
}
|
|
3171
3330
|
return this.x402PaymentManager.getPaymentHistory(limit);
|
|
3172
3331
|
}
|
|
3332
|
+
/**
|
|
3333
|
+
* Calculate total cost including protocol fee (2.5%)
|
|
3334
|
+
*/
|
|
3335
|
+
calculateTotalCost(amount, currency = "USDC") {
|
|
3336
|
+
const amountNum = parseFloat(amount);
|
|
3337
|
+
const fee = amountNum * 0.025;
|
|
3338
|
+
const total = amountNum + fee;
|
|
3339
|
+
return {
|
|
3340
|
+
amount: amountNum.toFixed(6),
|
|
3341
|
+
fee: fee.toFixed(6),
|
|
3342
|
+
total: total.toFixed(6),
|
|
3343
|
+
currency
|
|
3344
|
+
};
|
|
3345
|
+
}
|
|
3346
|
+
/**
|
|
3347
|
+
* Get ETH balance
|
|
3348
|
+
*/
|
|
3349
|
+
async getETHBalance() {
|
|
3350
|
+
const balance = await this.provider.getBalance(this.getAddress());
|
|
3351
|
+
return ethers.formatEther(balance);
|
|
3352
|
+
}
|
|
3353
|
+
/**
|
|
3354
|
+
* Get USDC balance (if USDC contract exists on network)
|
|
3355
|
+
*/
|
|
3356
|
+
async getUSDCBalance() {
|
|
3357
|
+
if (!this.x402PaymentManager) {
|
|
3358
|
+
throw new Error("x402 payments not enabled - cannot get USDC balance");
|
|
3359
|
+
}
|
|
3360
|
+
return "0.0";
|
|
3361
|
+
}
|
|
3173
3362
|
// ============================================================================
|
|
3174
3363
|
// Traditional Payment Methods (Cards, Google Pay, Apple Pay, PayPal)
|
|
3175
3364
|
// ============================================================================
|
|
@@ -3448,6 +3637,16 @@ var IPFSLocalStorage = class {
|
|
|
3448
3637
|
};
|
|
3449
3638
|
|
|
3450
3639
|
// src/types.ts
|
|
3640
|
+
var NetworkConfig = /* @__PURE__ */ ((NetworkConfig2) => {
|
|
3641
|
+
NetworkConfig2["ETHEREUM_SEPOLIA"] = "ethereum-sepolia";
|
|
3642
|
+
NetworkConfig2["BASE_SEPOLIA"] = "base-sepolia";
|
|
3643
|
+
NetworkConfig2["LINEA_SEPOLIA"] = "linea-sepolia";
|
|
3644
|
+
NetworkConfig2["HEDERA_TESTNET"] = "hedera-testnet";
|
|
3645
|
+
NetworkConfig2["MODE_TESTNET"] = "mode-testnet";
|
|
3646
|
+
NetworkConfig2["ZEROG_TESTNET"] = "0g-testnet";
|
|
3647
|
+
NetworkConfig2["LOCAL"] = "local";
|
|
3648
|
+
return NetworkConfig2;
|
|
3649
|
+
})(NetworkConfig || {});
|
|
3451
3650
|
var AgentRole = /* @__PURE__ */ ((AgentRole2) => {
|
|
3452
3651
|
AgentRole2["SERVER"] = "server";
|
|
3453
3652
|
AgentRole2["CLIENT"] = "client";
|
|
@@ -3471,7 +3670,7 @@ var PaymentMethod = /* @__PURE__ */ ((PaymentMethod2) => {
|
|
|
3471
3670
|
PaymentMethod2["A2A_X402"] = "https://a2a.org/x402";
|
|
3472
3671
|
return PaymentMethod2;
|
|
3473
3672
|
})(PaymentMethod || {});
|
|
3474
|
-
var SDK_VERSION = "0.1.
|
|
3673
|
+
var SDK_VERSION = "0.1.2";
|
|
3475
3674
|
var ERC8004_VERSION = "1.0";
|
|
3476
3675
|
var X402_VERSION = "1.0";
|
|
3477
3676
|
var src_default = ChaosChainSDK;
|
|
@@ -3479,6 +3678,6 @@ function initChaosChainSDK(config) {
|
|
|
3479
3678
|
return new ChaosChainSDK(config);
|
|
3480
3679
|
}
|
|
3481
3680
|
|
|
3482
|
-
export { A2AX402Extension, AgentRegistrationError, AgentRole, AutoStorageManager, ChaosAgent, ChaosChainSDK, ChaosChainSDKError, ConfigurationError, ContractError, ERC8004_VERSION, GoogleAP2Integration, IDENTITY_REGISTRY_ABI, IPFSLocalStorage, PinataStorage as IPFSPinataStorage, IntegrityVerificationError, IrysStorage, IrysStorage as IrysStorageProvider, LocalIPFSStorage, PaymentError2 as PaymentError, PaymentManager, PaymentMethod, PinataStorage, REPUTATION_REGISTRY_ABI, SDK_VERSION, StorageError, VALIDATION_REGISTRY_ABI, ValidationStatus, WalletManager, X402PaymentManager, X402Server, X402_VERSION, ZeroGStorage, src_default as default, getContractAddresses, getNetworkInfo, initChaosChainSDK };
|
|
3681
|
+
export { A2AX402Extension, AgentRegistrationError, AgentRole, AutoStorageManager, ChaosAgent, ChaosChainSDK, ChaosChainSDKError, ConfigurationError, ContractError, ERC8004_VERSION, GoogleAP2Integration, IDENTITY_REGISTRY_ABI, IPFSLocalStorage, PinataStorage as IPFSPinataStorage, IntegrityVerificationError, IrysStorage, IrysStorage as IrysStorageProvider, LocalIPFSStorage, NetworkConfig, PaymentError2 as PaymentError, PaymentManager, PaymentMethod, PinataStorage, REPUTATION_REGISTRY_ABI, SDK_VERSION, StorageError, VALIDATION_REGISTRY_ABI, ValidationStatus, WalletManager, X402PaymentManager, X402Server, X402_VERSION, ZeroGStorage, src_default as default, getContractAddresses, getNetworkInfo, initChaosChainSDK };
|
|
3483
3682
|
//# sourceMappingURL=index.mjs.map
|
|
3484
3683
|
//# sourceMappingURL=index.mjs.map
|