blue-js-sdk 2.0.0
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/CHANGELOG.md +446 -0
- package/LICENSE +21 -0
- package/README.md +75 -0
- package/ai-path/ADMIN-ELEVATION.md +116 -0
- package/ai-path/AI-MANIFESTO.md +185 -0
- package/ai-path/BREAKING.md +74 -0
- package/ai-path/CHECKLIST.md +619 -0
- package/ai-path/CONNECTION-STEPS.md +724 -0
- package/ai-path/DECISION-TREE.md +378 -0
- package/ai-path/DEPENDENCIES.md +459 -0
- package/ai-path/E2E-FLOW.md +1555 -0
- package/ai-path/FAILURES.md +403 -0
- package/ai-path/GUIDE.md +1217 -0
- package/ai-path/README.md +558 -0
- package/ai-path/SPLIT-TUNNEL.md +266 -0
- package/ai-path/cli.js +535 -0
- package/ai-path/connect.js +884 -0
- package/ai-path/discover.js +178 -0
- package/ai-path/environment.js +266 -0
- package/ai-path/errors.js +86 -0
- package/ai-path/examples/autonomous-agent.mjs +220 -0
- package/ai-path/examples/multi-region.mjs +174 -0
- package/ai-path/examples/one-shot.mjs +31 -0
- package/ai-path/index.js +60 -0
- package/ai-path/pricing.js +136 -0
- package/ai-path/recommend.js +413 -0
- package/ai-path/run-admin.vbs +25 -0
- package/ai-path/setup.js +291 -0
- package/ai-path/wallet.js +137 -0
- package/app-helpers.js +363 -0
- package/app-settings.js +95 -0
- package/app-types.js +267 -0
- package/audit.js +847 -0
- package/batch.js +293 -0
- package/bin/setup.js +376 -0
- package/chain/authz.js +109 -0
- package/chain/broadcast.js +472 -0
- package/chain/client.js +160 -0
- package/chain/fee-grants.js +305 -0
- package/chain/index.js +891 -0
- package/chain/lcd.js +313 -0
- package/chain/queries.js +547 -0
- package/chain/rpc.js +408 -0
- package/chain/wallet.js +141 -0
- package/cli/config.js +143 -0
- package/cli/index.js +463 -0
- package/cli/output.js +182 -0
- package/cli.js +491 -0
- package/client/index.js +251 -0
- package/client.js +271 -0
- package/config/index.js +255 -0
- package/connection/connect.js +849 -0
- package/connection/disconnect.js +180 -0
- package/connection/discovery.js +321 -0
- package/connection/index.js +76 -0
- package/connection/proxy.js +148 -0
- package/connection/resilience.js +428 -0
- package/connection/security.js +232 -0
- package/connection/state.js +369 -0
- package/connection/tunnel.js +691 -0
- package/consumer.js +132 -0
- package/cosmjs-setup.js +1884 -0
- package/defaults.js +366 -0
- package/disk-cache.js +107 -0
- package/dist/client.d.ts +108 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +400 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/errors/index.js +112 -0
- package/errors.js +218 -0
- package/examples/README.md +64 -0
- package/examples/connect-direct.mjs +106 -0
- package/examples/connect-plan.mjs +125 -0
- package/examples/error-handling.mjs +109 -0
- package/examples/query-nodes.mjs +94 -0
- package/examples/wallet-basics.mjs +61 -0
- package/generated/amino/amino.ts +9 -0
- package/generated/cosmos/base/v1beta1/coin.ts +365 -0
- package/generated/cosmos_proto/cosmos.ts +323 -0
- package/generated/gogoproto/gogo.ts +9 -0
- package/generated/google/protobuf/descriptor.ts +7601 -0
- package/generated/google/protobuf/duration.ts +208 -0
- package/generated/google/protobuf/timestamp.ts +238 -0
- package/generated/sentinel/lease/v1/events.ts +924 -0
- package/generated/sentinel/lease/v1/lease.ts +292 -0
- package/generated/sentinel/lease/v1/msg.ts +949 -0
- package/generated/sentinel/lease/v1/params.ts +164 -0
- package/generated/sentinel/node/v3/events.ts +881 -0
- package/generated/sentinel/node/v3/msg.ts +1002 -0
- package/generated/sentinel/node/v3/node.ts +263 -0
- package/generated/sentinel/node/v3/params.ts +183 -0
- package/generated/sentinel/plan/v3/events.ts +675 -0
- package/generated/sentinel/plan/v3/msg.ts +1191 -0
- package/generated/sentinel/plan/v3/plan.ts +283 -0
- package/generated/sentinel/provider/v2/events.ts +171 -0
- package/generated/sentinel/provider/v2/msg.ts +480 -0
- package/generated/sentinel/provider/v2/params.ts +131 -0
- package/generated/sentinel/provider/v2/provider.ts +246 -0
- package/generated/sentinel/session/v3/events.ts +480 -0
- package/generated/sentinel/session/v3/msg.ts +616 -0
- package/generated/sentinel/session/v3/params.ts +260 -0
- package/generated/sentinel/session/v3/proof.ts +180 -0
- package/generated/sentinel/session/v3/session.ts +384 -0
- package/generated/sentinel/subscription/v3/events.ts +1181 -0
- package/generated/sentinel/subscription/v3/msg.ts +1305 -0
- package/generated/sentinel/subscription/v3/params.ts +167 -0
- package/generated/sentinel/subscription/v3/subscription.ts +315 -0
- package/generated/sentinel/types/v1/bandwidth.ts +124 -0
- package/generated/sentinel/types/v1/price.ts +149 -0
- package/generated/sentinel/types/v1/renewal.ts +87 -0
- package/generated/sentinel/types/v1/status.ts +54 -0
- package/generated/typeRegistry.ts +27 -0
- package/index.js +486 -0
- package/node-connect.js +3015 -0
- package/operator.js +134 -0
- package/package.json +113 -0
- package/plan-operations.js +199 -0
- package/preflight.js +352 -0
- package/pricing/index.js +262 -0
- package/proto/amino/amino.proto +84 -0
- package/proto/cosmos/base/v1beta1/coin.proto +61 -0
- package/proto/cosmos_proto/cosmos.proto +112 -0
- package/proto/gogoproto/gogo.proto +145 -0
- package/proto/google/api/annotations.proto +31 -0
- package/proto/google/api/http.proto +370 -0
- package/proto/google/protobuf/any.proto +106 -0
- package/proto/google/protobuf/duration.proto +115 -0
- package/proto/google/protobuf/timestamp.proto +145 -0
- package/proto/sentinel/lease/v1/events.proto +52 -0
- package/proto/sentinel/lease/v1/genesis.proto +15 -0
- package/proto/sentinel/lease/v1/lease.proto +25 -0
- package/proto/sentinel/lease/v1/msg.proto +62 -0
- package/proto/sentinel/lease/v1/params.proto +17 -0
- package/proto/sentinel/node/v3/events.proto +50 -0
- package/proto/sentinel/node/v3/genesis.proto +15 -0
- package/proto/sentinel/node/v3/msg.proto +63 -0
- package/proto/sentinel/node/v3/node.proto +27 -0
- package/proto/sentinel/node/v3/params.proto +21 -0
- package/proto/sentinel/node/v3/querier.proto +63 -0
- package/proto/sentinel/plan/v3/events.proto +41 -0
- package/proto/sentinel/plan/v3/genesis.proto +21 -0
- package/proto/sentinel/plan/v3/msg.proto +83 -0
- package/proto/sentinel/plan/v3/plan.proto +32 -0
- package/proto/sentinel/plan/v3/querier.proto +53 -0
- package/proto/sentinel/provider/v2/events.proto +16 -0
- package/proto/sentinel/provider/v2/genesis.proto +15 -0
- package/proto/sentinel/provider/v2/msg.proto +35 -0
- package/proto/sentinel/provider/v2/params.proto +17 -0
- package/proto/sentinel/provider/v2/provider.proto +24 -0
- package/proto/sentinel/provider/v3/genesis.proto +15 -0
- package/proto/sentinel/provider/v3/params.proto +13 -0
- package/proto/sentinel/session/v3/events.proto +30 -0
- package/proto/sentinel/session/v3/genesis.proto +15 -0
- package/proto/sentinel/session/v3/msg.proto +50 -0
- package/proto/sentinel/session/v3/params.proto +25 -0
- package/proto/sentinel/session/v3/proof.proto +25 -0
- package/proto/sentinel/session/v3/querier.proto +100 -0
- package/proto/sentinel/session/v3/session.proto +50 -0
- package/proto/sentinel/subscription/v2/allocation.proto +21 -0
- package/proto/sentinel/subscription/v2/payout.proto +22 -0
- package/proto/sentinel/subscription/v3/events.proto +65 -0
- package/proto/sentinel/subscription/v3/genesis.proto +17 -0
- package/proto/sentinel/subscription/v3/msg.proto +83 -0
- package/proto/sentinel/subscription/v3/params.proto +21 -0
- package/proto/sentinel/subscription/v3/subscription.proto +33 -0
- package/proto/sentinel/types/v1/bandwidth.proto +19 -0
- package/proto/sentinel/types/v1/price.proto +21 -0
- package/proto/sentinel/types/v1/renewal.proto +21 -0
- package/proto/sentinel/types/v1/status.proto +16 -0
- package/protocol/encoding.js +341 -0
- package/protocol/events.js +361 -0
- package/protocol/handshake.js +297 -0
- package/protocol/index.js +15 -0
- package/protocol/messages.js +346 -0
- package/protocol/plans.js +199 -0
- package/protocol/v2ray.js +268 -0
- package/protocol/v3.js +723 -0
- package/protocol/wireguard.js +125 -0
- package/security/index.js +132 -0
- package/session-manager.js +329 -0
- package/session-tracker.js +80 -0
- package/setup.js +376 -0
- package/speedtest/index.js +528 -0
- package/speedtest.js +567 -0
- package/src/client.ts +502 -0
- package/src/index.ts +20 -0
- package/state/index.js +347 -0
- package/state.js +516 -0
- package/test-all-chain-ops.js +493 -0
- package/test-all-logic.js +199 -0
- package/test-all-msg-types.js +292 -0
- package/test-every-connection.js +208 -0
- package/test-feegrant-connect.js +98 -0
- package/test-logic.js +148 -0
- package/test-mainnet.js +176 -0
- package/test-plan-lifecycle.js +335 -0
- package/tls-trust.js +132 -0
- package/tsconfig.build.json +20 -0
- package/tsconfig.json +34 -0
- package/types/chain.d.ts +746 -0
- package/types/connection.d.ts +425 -0
- package/types/errors.d.ts +174 -0
- package/types/index.d.ts +1380 -0
- package/types/nodes.d.ts +187 -0
- package/types/pricing.d.ts +156 -0
- package/types/protocol.d.ts +332 -0
- package/types/session.d.ts +236 -0
- package/types/settings.d.ts +192 -0
- package/v3protocol.js +1053 -0
- package/wallet/index.js +153 -0
- package/wireguard.js +307 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.subscription.v3;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
|
|
6
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/x/subscription/types/v3";
|
|
7
|
+
option (gogoproto.equal_all) = false;
|
|
8
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
9
|
+
|
|
10
|
+
message EventAllocate {
|
|
11
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
12
|
+
string acc_address = 2;
|
|
13
|
+
string granted_bytes = 3;
|
|
14
|
+
string utilised_bytes = 4;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
message EventCreate {
|
|
18
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
19
|
+
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
|
|
20
|
+
string acc_address = 3;
|
|
21
|
+
string price = 4;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
message EventCreateSession {
|
|
25
|
+
uint64 session_id = 1 [(gogoproto.customname) = "SessionID"];
|
|
26
|
+
uint64 subscription_id = 4 [(gogoproto.customname) = "SubscriptionID"];
|
|
27
|
+
string acc_address = 2;
|
|
28
|
+
string node_address = 3;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
message EventEnd {
|
|
32
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
33
|
+
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
|
|
34
|
+
string acc_address = 3;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
message EventPay {
|
|
38
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
39
|
+
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
|
|
40
|
+
string acc_address = 3;
|
|
41
|
+
string prov_address = 4;
|
|
42
|
+
string payment = 5;
|
|
43
|
+
string staking_reward = 6;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
message EventRenew {
|
|
47
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
48
|
+
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
|
|
49
|
+
string acc_address = 3;
|
|
50
|
+
string price = 4;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
message EventUpdateDetails {
|
|
54
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
55
|
+
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
|
|
56
|
+
string acc_address = 3;
|
|
57
|
+
string renewal_price_policy = 4;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
message EventUpdateStatus {
|
|
61
|
+
uint64 subscription_id = 1 [(gogoproto.customname) = "SubscriptionID"];
|
|
62
|
+
uint64 plan_id = 2 [(gogoproto.customname) = "PlanID"];
|
|
63
|
+
string acc_address = 3;
|
|
64
|
+
string status = 4;
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.subscription.v3;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
import "sentinel/subscription/v2/allocation.proto";
|
|
6
|
+
import "sentinel/subscription/v3/params.proto";
|
|
7
|
+
import "sentinel/subscription/v3/subscription.proto";
|
|
8
|
+
|
|
9
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/x/subscription/types/v3";
|
|
10
|
+
option (gogoproto.equal_all) = false;
|
|
11
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
12
|
+
|
|
13
|
+
message GenesisState {
|
|
14
|
+
repeated sentinel.subscription.v2.Allocation allocations = 1 [(gogoproto.nullable) = false];
|
|
15
|
+
repeated Subscription subscriptions = 2 [(gogoproto.nullable) = false];
|
|
16
|
+
Params params = 3 [(gogoproto.nullable) = false];
|
|
17
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.subscription.v3;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
import "sentinel/subscription/v3/params.proto";
|
|
6
|
+
import "sentinel/types/v1/renewal.proto";
|
|
7
|
+
|
|
8
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/x/subscription/types/v3";
|
|
9
|
+
option (gogoproto.equal_all) = false;
|
|
10
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
11
|
+
|
|
12
|
+
message MsgCancelSubscriptionRequest {
|
|
13
|
+
string from = 1;
|
|
14
|
+
uint64 id = 2 [(gogoproto.customname) = "ID"];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
message MsgRenewSubscriptionRequest {
|
|
18
|
+
string from = 1;
|
|
19
|
+
uint64 id = 2 [(gogoproto.customname) = "ID"];
|
|
20
|
+
string denom = 3;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
message MsgShareSubscriptionRequest {
|
|
24
|
+
string from = 1;
|
|
25
|
+
uint64 id = 2 [(gogoproto.customname) = "ID"];
|
|
26
|
+
string acc_address = 3;
|
|
27
|
+
string bytes = 4 [
|
|
28
|
+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
|
|
29
|
+
(gogoproto.nullable) = false
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
message MsgStartSubscriptionRequest {
|
|
34
|
+
string from = 1;
|
|
35
|
+
uint64 id = 2 [(gogoproto.customname) = "ID"];
|
|
36
|
+
string denom = 3;
|
|
37
|
+
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 4;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
message MsgUpdateSubscriptionRequest {
|
|
41
|
+
string from = 1;
|
|
42
|
+
uint64 id = 2 [(gogoproto.customname) = "ID"];
|
|
43
|
+
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 3;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
message MsgStartSessionRequest {
|
|
47
|
+
string from = 1;
|
|
48
|
+
uint64 id = 2 [(gogoproto.customname) = "ID"];
|
|
49
|
+
string node_address = 3;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
message MsgUpdateParamsRequest {
|
|
53
|
+
string from = 1;
|
|
54
|
+
Params params = 2 [(gogoproto.nullable) = false];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
message MsgCancelSubscriptionResponse {}
|
|
58
|
+
|
|
59
|
+
message MsgRenewSubscriptionResponse {}
|
|
60
|
+
|
|
61
|
+
message MsgShareSubscriptionResponse {}
|
|
62
|
+
|
|
63
|
+
message MsgStartSubscriptionResponse {
|
|
64
|
+
uint64 id = 1 [(gogoproto.customname) = "ID"];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
message MsgUpdateSubscriptionResponse {}
|
|
68
|
+
|
|
69
|
+
message MsgStartSessionResponse {
|
|
70
|
+
uint64 id = 1 [(gogoproto.customname) = "ID"];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
message MsgUpdateParamsResponse {}
|
|
74
|
+
|
|
75
|
+
service MsgService {
|
|
76
|
+
rpc MsgCancelSubscription(MsgCancelSubscriptionRequest) returns (MsgCancelSubscriptionResponse);
|
|
77
|
+
rpc MsgRenewSubscription(MsgRenewSubscriptionRequest) returns (MsgRenewSubscriptionResponse);
|
|
78
|
+
rpc MsgShareSubscription(MsgShareSubscriptionRequest) returns (MsgShareSubscriptionResponse);
|
|
79
|
+
rpc MsgStartSubscription(MsgStartSubscriptionRequest) returns (MsgStartSubscriptionResponse);
|
|
80
|
+
rpc MsgUpdateSubscription(MsgUpdateSubscriptionRequest) returns (MsgUpdateSubscriptionResponse);
|
|
81
|
+
rpc MsgStartSession(MsgStartSessionRequest) returns (MsgStartSessionResponse);
|
|
82
|
+
rpc MsgUpdateParams(MsgUpdateParamsRequest) returns (MsgUpdateParamsResponse);
|
|
83
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.subscription.v3;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
import "google/protobuf/duration.proto";
|
|
6
|
+
|
|
7
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/x/subscription/types/v3";
|
|
8
|
+
option (gogoproto.equal_all) = false;
|
|
9
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
10
|
+
|
|
11
|
+
message Params {
|
|
12
|
+
int64 max_allocations = 1;
|
|
13
|
+
string staking_share = 2 [
|
|
14
|
+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
|
|
15
|
+
(gogoproto.nullable) = false
|
|
16
|
+
];
|
|
17
|
+
google.protobuf.Duration status_timeout = 3 [
|
|
18
|
+
(gogoproto.nullable) = false,
|
|
19
|
+
(gogoproto.stdduration) = true
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.subscription.v3;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
import "google/protobuf/timestamp.proto";
|
|
6
|
+
import "sentinel/types/v1/price.proto";
|
|
7
|
+
import "sentinel/types/v1/renewal.proto";
|
|
8
|
+
import "sentinel/types/v1/status.proto";
|
|
9
|
+
|
|
10
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/x/subscription/types/v3";
|
|
11
|
+
option (gogoproto.equal_all) = false;
|
|
12
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
13
|
+
|
|
14
|
+
message Subscription {
|
|
15
|
+
uint64 id = 1 [(gogoproto.customname) = "ID"];
|
|
16
|
+
string acc_address = 2;
|
|
17
|
+
uint64 plan_id = 3 [(gogoproto.customname) = "PlanID"];
|
|
18
|
+
sentinel.types.v1.Price price = 4 [(gogoproto.nullable) = false];
|
|
19
|
+
sentinel.types.v1.RenewalPricePolicy renewal_price_policy = 5;
|
|
20
|
+
sentinel.types.v1.Status status = 6;
|
|
21
|
+
google.protobuf.Timestamp inactive_at = 7 [
|
|
22
|
+
(gogoproto.nullable) = false,
|
|
23
|
+
(gogoproto.stdtime) = true
|
|
24
|
+
];
|
|
25
|
+
google.protobuf.Timestamp start_at = 8 [
|
|
26
|
+
(gogoproto.nullable) = false,
|
|
27
|
+
(gogoproto.stdtime) = true
|
|
28
|
+
];
|
|
29
|
+
google.protobuf.Timestamp status_at = 9 [
|
|
30
|
+
(gogoproto.nullable) = false,
|
|
31
|
+
(gogoproto.stdtime) = true
|
|
32
|
+
];
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.types.v1;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
|
|
6
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/types/v1";
|
|
7
|
+
option (gogoproto.equal_all) = false;
|
|
8
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
9
|
+
|
|
10
|
+
message Bandwidth {
|
|
11
|
+
string upload = 1 [
|
|
12
|
+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
|
|
13
|
+
(gogoproto.nullable) = false
|
|
14
|
+
];
|
|
15
|
+
string download = 2 [
|
|
16
|
+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
|
|
17
|
+
(gogoproto.nullable) = false
|
|
18
|
+
];
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.types.v1;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
|
|
6
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/types/v1";
|
|
7
|
+
option (gogoproto.equal_all) = false;
|
|
8
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
9
|
+
option (gogoproto.goproto_stringer_all) = false;
|
|
10
|
+
|
|
11
|
+
message Price {
|
|
12
|
+
string denom = 1;
|
|
13
|
+
string base_value = 2 [
|
|
14
|
+
(gogoproto.customtype) = "cosmossdk.io/math.LegacyDec",
|
|
15
|
+
(gogoproto.nullable) = false
|
|
16
|
+
];
|
|
17
|
+
string quote_value = 3 [
|
|
18
|
+
(gogoproto.customtype) = "cosmossdk.io/math.Int",
|
|
19
|
+
(gogoproto.nullable) = false
|
|
20
|
+
];
|
|
21
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.types.v1;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
|
|
6
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/types/v1";
|
|
7
|
+
option (gogoproto.goproto_enum_prefix_all) = false;
|
|
8
|
+
option (gogoproto.goproto_enum_stringer_all) = false;
|
|
9
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
10
|
+
|
|
11
|
+
// Enum for renewal price policies
|
|
12
|
+
enum RenewalPricePolicy {
|
|
13
|
+
RENEWAL_PRICE_POLICY_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyUnspecified"]; // Default value, do not renew
|
|
14
|
+
RENEWAL_PRICE_POLICY_IF_LESSER = 1 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyIfLesser"]; // Renew if the current price is lesser than the previous price
|
|
15
|
+
RENEWAL_PRICE_POLICY_IF_LESSER_OR_EQUAL = 2 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyIfLesserOrEqual"]; // Renew if the current price is lesser than or equal to the previous price
|
|
16
|
+
RENEWAL_PRICE_POLICY_IF_EQUAL = 3 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyIfEqual"]; // Renew if the current price is equal to the previous price
|
|
17
|
+
RENEWAL_PRICE_POLICY_IF_NOT_EQUAL = 4 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyIfNotEqual"]; // Renew if the current price is not equal to the previous price
|
|
18
|
+
RENEWAL_PRICE_POLICY_IF_GREATER = 5 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyIfGreater"]; // Renew if the current price is greater than the previous price
|
|
19
|
+
RENEWAL_PRICE_POLICY_IF_GREATER_OR_EQUAL = 6 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyIfGreaterOrEqual"]; // Renew if the current price is greater than or equal to the previous price
|
|
20
|
+
RENEWAL_PRICE_POLICY_ALWAYS = 7 [(gogoproto.enumvalue_customname) = "RenewalPricePolicyAlways"]; // Always renew
|
|
21
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
syntax = "proto3";
|
|
2
|
+
package sentinel.types.v1;
|
|
3
|
+
|
|
4
|
+
import "gogoproto/gogo.proto";
|
|
5
|
+
|
|
6
|
+
option go_package = "github.com/sentinel-official/sentinelhub/v13/types/v1";
|
|
7
|
+
option (gogoproto.goproto_enum_prefix_all) = false;
|
|
8
|
+
option (gogoproto.goproto_enum_stringer_all) = false;
|
|
9
|
+
option (gogoproto.goproto_getters_all) = false;
|
|
10
|
+
|
|
11
|
+
enum Status {
|
|
12
|
+
STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "StatusUnspecified"];
|
|
13
|
+
STATUS_ACTIVE = 1 [(gogoproto.enumvalue_customname) = "StatusActive"];
|
|
14
|
+
STATUS_INACTIVE_PENDING = 2 [(gogoproto.enumvalue_customname) = "StatusInactivePending"];
|
|
15
|
+
STATUS_INACTIVE = 3 [(gogoproto.enumvalue_customname) = "StatusInactive"];
|
|
16
|
+
}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sentinel v3 Protobuf Encoding & Message Encoders
|
|
3
|
+
*
|
|
4
|
+
* Manual protobuf encoding — avoids needing proto-generated code for v3 types.
|
|
5
|
+
* Field tag = (field_number << 3) | wire_type (0=varint, 2=length-delimited)
|
|
6
|
+
*
|
|
7
|
+
* Contains:
|
|
8
|
+
* - Encoding primitives (encodeVarint, protoString, protoInt64, protoEmbedded)
|
|
9
|
+
* - Value converters (decToScaledInt, encodePrice, encodeDuration)
|
|
10
|
+
* - ALL message encoders (MsgStartSession, MsgEndSession, subscriptions, node ops, plan details)
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// ─── Encoding Primitives ────────────────────────────────────────────────────
|
|
14
|
+
|
|
15
|
+
export function encodeVarint(value) {
|
|
16
|
+
let n = BigInt(value);
|
|
17
|
+
if (n < 0n) throw new RangeError(`encodeVarint: negative values not supported (got ${n})`);
|
|
18
|
+
const bytes = [];
|
|
19
|
+
do {
|
|
20
|
+
let b = Number(n & 0x7fn);
|
|
21
|
+
n >>= 7n;
|
|
22
|
+
if (n > 0n) b |= 0x80;
|
|
23
|
+
bytes.push(b);
|
|
24
|
+
} while (n > 0n);
|
|
25
|
+
return Buffer.from(bytes);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function protoString(fieldNum, str) {
|
|
29
|
+
if (!str) return Buffer.alloc(0);
|
|
30
|
+
const b = Buffer.from(str, 'utf8');
|
|
31
|
+
return Buffer.concat([encodeVarint((BigInt(fieldNum) << 3n) | 2n), encodeVarint(b.length), b]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function protoInt64(fieldNum, n) {
|
|
35
|
+
if (n === null || n === undefined) return Buffer.alloc(0);
|
|
36
|
+
return Buffer.concat([encodeVarint((BigInt(fieldNum) << 3n) | 0n), encodeVarint(n)]);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function protoEmbedded(fieldNum, msgBytes) {
|
|
40
|
+
if (!msgBytes || msgBytes.length === 0) return Buffer.alloc(0);
|
|
41
|
+
return Buffer.concat([encodeVarint((BigInt(fieldNum) << 3n) | 2n), encodeVarint(msgBytes.length), msgBytes]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// ─── Value Converters ───────────────────────────────────────────────────────
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Convert sdk.Dec string to scaled big.Int string (multiply by 10^18).
|
|
48
|
+
* "0.003000000000000000" → "3000000000000000"
|
|
49
|
+
* "40152030" → "40152030000000000000000000" (only for sdk.Dec fields)
|
|
50
|
+
*/
|
|
51
|
+
export function decToScaledInt(decStr) {
|
|
52
|
+
if (decStr == null || decStr === '') return '0';
|
|
53
|
+
const s = String(decStr).trim();
|
|
54
|
+
if (!s || s === 'undefined' || s === 'null') return '0';
|
|
55
|
+
const dotIdx = s.indexOf('.');
|
|
56
|
+
if (dotIdx === -1) {
|
|
57
|
+
// Integer — multiply by 10^18
|
|
58
|
+
return s + '0'.repeat(18);
|
|
59
|
+
}
|
|
60
|
+
const intPart = s.slice(0, dotIdx);
|
|
61
|
+
const fracPart = s.slice(dotIdx + 1);
|
|
62
|
+
// Pad or trim fractional part to exactly 18 digits
|
|
63
|
+
const frac18 = (fracPart + '0'.repeat(18)).slice(0, 18);
|
|
64
|
+
const combined = (intPart === '' || intPart === '0' ? '' : intPart) + frac18;
|
|
65
|
+
// Remove leading zeros (but keep at least one digit)
|
|
66
|
+
const trimmed = combined.replace(/^0+/, '') || '0';
|
|
67
|
+
return trimmed;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Encode sentinel.types.v1.Price { denom, base_value, quote_value }
|
|
72
|
+
* base_value is sdk.Dec → encode as scaled big.Int string
|
|
73
|
+
* quote_value is sdk.Int → encode as integer string
|
|
74
|
+
*/
|
|
75
|
+
export function encodePrice({ denom, base_value, quote_value }) {
|
|
76
|
+
const baseValEncoded = decToScaledInt(String(base_value));
|
|
77
|
+
return Buffer.concat([
|
|
78
|
+
protoString(1, denom),
|
|
79
|
+
protoString(2, baseValEncoded),
|
|
80
|
+
protoString(3, String(quote_value)),
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Encode google.protobuf.Duration { seconds, nanos }
|
|
86
|
+
* Used by MsgCreatePlanRequest and MsgUpdatePlanDetails for plan duration.
|
|
87
|
+
*/
|
|
88
|
+
export function encodeDuration({ seconds, nanos = 0 }) {
|
|
89
|
+
return Buffer.concat([
|
|
90
|
+
protoInt64(1, seconds),
|
|
91
|
+
nanos ? protoInt64(2, nanos) : Buffer.alloc(0),
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// ─── Session Message Encoders ───────────────────────────────────────────────
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Encode sentinel.node.v3.MsgStartSessionRequest
|
|
99
|
+
* Replaces old nodeSubscribe + sessionStart (now one tx).
|
|
100
|
+
*
|
|
101
|
+
* Fields:
|
|
102
|
+
* 1: from (string) — account address
|
|
103
|
+
* 2: node_address (string) — node's sentnode1... address
|
|
104
|
+
* 3: gigabytes (int64)
|
|
105
|
+
* 4: hours (int64, 0 if using gigabytes)
|
|
106
|
+
* 5: max_price (Price, optional) — max price user will pay per GB
|
|
107
|
+
*/
|
|
108
|
+
export function encodeMsgStartSession({ from, node_address, gigabytes = 1, hours = 0, max_price }) {
|
|
109
|
+
return Uint8Array.from(Buffer.concat([
|
|
110
|
+
protoString(1, from),
|
|
111
|
+
protoString(2, node_address),
|
|
112
|
+
protoInt64(3, gigabytes),
|
|
113
|
+
hours ? protoInt64(4, hours) : Buffer.alloc(0),
|
|
114
|
+
max_price ? protoEmbedded(5, encodePrice(max_price)) : Buffer.alloc(0),
|
|
115
|
+
]));
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* MsgStartSubscriptionRequest (sentinel.subscription.v3):
|
|
120
|
+
* 1: from (string)
|
|
121
|
+
* 2: id (uint64, plan ID)
|
|
122
|
+
* 3: denom (string, e.g. "udvpn")
|
|
123
|
+
* 4: renewal_price_policy (enum/int64, optional)
|
|
124
|
+
*/
|
|
125
|
+
export function encodeMsgStartSubscription({ from, id, denom = 'udvpn', renewalPricePolicy = 0 }) {
|
|
126
|
+
const parts = [
|
|
127
|
+
protoString(1, from),
|
|
128
|
+
protoInt64(2, id),
|
|
129
|
+
protoString(3, denom),
|
|
130
|
+
];
|
|
131
|
+
if (renewalPricePolicy) parts.push(protoInt64(4, renewalPricePolicy));
|
|
132
|
+
return Uint8Array.from(Buffer.concat(parts));
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* MsgStartSessionRequest (sentinel.subscription.v3) — start session via subscription:
|
|
137
|
+
* 1: from (string)
|
|
138
|
+
* 2: id (uint64, subscription ID)
|
|
139
|
+
* 3: node_address (string)
|
|
140
|
+
*/
|
|
141
|
+
export function encodeMsgSubStartSession({ from, id, nodeAddress }) {
|
|
142
|
+
return Uint8Array.from(Buffer.concat([
|
|
143
|
+
protoString(1, from),
|
|
144
|
+
protoInt64(2, id),
|
|
145
|
+
protoString(3, nodeAddress),
|
|
146
|
+
]));
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// ─── Subscription Management (v3 — from sentinel-go-sdk) ────────────────────
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* MsgCancelSubscriptionRequest (sentinel.subscription.v3) — cancel a subscription:
|
|
153
|
+
* 1: from (string)
|
|
154
|
+
* 2: id (uint64, subscription ID)
|
|
155
|
+
*/
|
|
156
|
+
export function encodeMsgCancelSubscription({ from, id }) {
|
|
157
|
+
return Uint8Array.from(Buffer.concat([
|
|
158
|
+
protoString(1, from),
|
|
159
|
+
protoInt64(2, id),
|
|
160
|
+
]));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* MsgRenewSubscriptionRequest (sentinel.subscription.v3) — renew an expiring subscription:
|
|
165
|
+
* 1: from (string)
|
|
166
|
+
* 2: id (uint64, subscription ID)
|
|
167
|
+
* 3: denom (string, default 'udvpn')
|
|
168
|
+
*/
|
|
169
|
+
export function encodeMsgRenewSubscription({ from, id, denom = 'udvpn' }) {
|
|
170
|
+
return Uint8Array.from(Buffer.concat([
|
|
171
|
+
protoString(1, from),
|
|
172
|
+
protoInt64(2, id),
|
|
173
|
+
protoString(3, denom),
|
|
174
|
+
]));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* MsgShareSubscriptionRequest (sentinel.subscription.v3) — share bandwidth with another address:
|
|
179
|
+
* 1: from (string)
|
|
180
|
+
* 2: id (uint64, subscription ID)
|
|
181
|
+
* 3: acc_address (string, recipient sent1... address)
|
|
182
|
+
* 4: bytes (int64, bytes to share)
|
|
183
|
+
*/
|
|
184
|
+
export function encodeMsgShareSubscription({ from, id, accAddress, bytes }) {
|
|
185
|
+
return Uint8Array.from(Buffer.concat([
|
|
186
|
+
protoString(1, from),
|
|
187
|
+
protoInt64(2, id),
|
|
188
|
+
protoString(3, accAddress),
|
|
189
|
+
protoInt64(4, bytes),
|
|
190
|
+
]));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* MsgUpdateSubscriptionRequest (sentinel.subscription.v3) — update renewal policy:
|
|
195
|
+
* 1: from (string)
|
|
196
|
+
* 2: id (uint64, subscription ID)
|
|
197
|
+
* 3: renewal_price_policy (int64)
|
|
198
|
+
*/
|
|
199
|
+
export function encodeMsgUpdateSubscription({ from, id, renewalPricePolicy }) {
|
|
200
|
+
return Uint8Array.from(Buffer.concat([
|
|
201
|
+
protoString(1, from),
|
|
202
|
+
protoInt64(2, id),
|
|
203
|
+
protoInt64(3, renewalPricePolicy),
|
|
204
|
+
]));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// ─── Session Management (v3) ────────────────────────────────────────────────
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* MsgUpdateSessionRequest (sentinel.session.v3) — report bandwidth usage:
|
|
211
|
+
* 1: from (string)
|
|
212
|
+
* 2: id (uint64, session ID)
|
|
213
|
+
* 3: download_bytes (int64)
|
|
214
|
+
* 4: upload_bytes (int64)
|
|
215
|
+
* 5: duration (bytes, protobuf Duration)
|
|
216
|
+
* 6: signature (bytes)
|
|
217
|
+
*/
|
|
218
|
+
export function encodeMsgUpdateSession({ from, id, downloadBytes, uploadBytes }) {
|
|
219
|
+
return Uint8Array.from(Buffer.concat([
|
|
220
|
+
protoString(1, from),
|
|
221
|
+
protoInt64(2, id),
|
|
222
|
+
protoInt64(3, downloadBytes),
|
|
223
|
+
protoInt64(4, uploadBytes),
|
|
224
|
+
]));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// ─── Node Operator (v3 — for node operators, NOT consumer apps) ─────────────
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* MsgRegisterNodeRequest (sentinel.node.v3) — register a new node:
|
|
231
|
+
* 1: from (string, sentnode1... address)
|
|
232
|
+
* 2: gigabyte_prices (bytes[], Price entries)
|
|
233
|
+
* 3: hourly_prices (bytes[], Price entries)
|
|
234
|
+
* 4: remote_addrs (string[], IP:port addresses)
|
|
235
|
+
*/
|
|
236
|
+
export function encodeMsgRegisterNode({ from, gigabytePrices = [], hourlyPrices = [], remoteAddrs = [] }) {
|
|
237
|
+
const parts = [protoString(1, from)];
|
|
238
|
+
for (const p of gigabytePrices) parts.push(protoEmbedded(2, encodePrice(p)));
|
|
239
|
+
for (const p of hourlyPrices) parts.push(protoEmbedded(3, encodePrice(p)));
|
|
240
|
+
for (const addr of remoteAddrs) parts.push(protoString(4, addr));
|
|
241
|
+
return Uint8Array.from(Buffer.concat(parts));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* MsgUpdateNodeDetailsRequest (sentinel.node.v3) — update node details:
|
|
246
|
+
* 1: from (string, sentnode1... address)
|
|
247
|
+
* 2: gigabyte_prices (bytes[], Price entries)
|
|
248
|
+
* 3: hourly_prices (bytes[], Price entries)
|
|
249
|
+
* 4: remote_addrs (string[], IP:port addresses)
|
|
250
|
+
*/
|
|
251
|
+
export function encodeMsgUpdateNodeDetails({ from, gigabytePrices = [], hourlyPrices = [], remoteAddrs = [] }) {
|
|
252
|
+
const parts = [protoString(1, from)];
|
|
253
|
+
for (const p of gigabytePrices) parts.push(protoEmbedded(2, encodePrice(p)));
|
|
254
|
+
for (const p of hourlyPrices) parts.push(protoEmbedded(3, encodePrice(p)));
|
|
255
|
+
for (const addr of remoteAddrs) parts.push(protoString(4, addr));
|
|
256
|
+
return Uint8Array.from(Buffer.concat(parts));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* MsgUpdateNodeStatusRequest (sentinel.node.v3) — activate/deactivate node:
|
|
261
|
+
* 1: from (string, sentnode1... address)
|
|
262
|
+
* 2: status (int64, 1=active, 3=inactive)
|
|
263
|
+
*/
|
|
264
|
+
export function encodeMsgUpdateNodeStatus({ from, status }) {
|
|
265
|
+
return Uint8Array.from(Buffer.concat([
|
|
266
|
+
protoString(1, from),
|
|
267
|
+
protoInt64(2, status),
|
|
268
|
+
]));
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ─── Plan Management (v3 addition) ──────────────────────────────────────────
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* MsgUpdatePlanDetailsRequest (sentinel.plan.v3) — update plan details (NEW in v3):
|
|
275
|
+
* 1: from (string, sentprov1... address)
|
|
276
|
+
* 2: id (uint64, plan ID)
|
|
277
|
+
* 3: bytes (string, total bandwidth)
|
|
278
|
+
* 4: duration (bytes, Duration)
|
|
279
|
+
* 5: prices (bytes[], Price entries)
|
|
280
|
+
*/
|
|
281
|
+
export function encodeMsgUpdatePlanDetails({ from, id, bytes, duration, prices = [] }) {
|
|
282
|
+
const parts = [protoString(1, from), protoInt64(2, id)];
|
|
283
|
+
if (bytes) parts.push(protoString(3, String(bytes)));
|
|
284
|
+
if (duration) parts.push(protoEmbedded(4, encodeDuration(
|
|
285
|
+
typeof duration === 'number' ? { seconds: duration } : duration
|
|
286
|
+
)));
|
|
287
|
+
for (const p of prices) parts.push(protoEmbedded(5, encodePrice(p)));
|
|
288
|
+
return Uint8Array.from(Buffer.concat(parts));
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* MsgCancelSessionRequest (sentinel.session.v3) — cancel/end a session:
|
|
293
|
+
* 1: from (string) — signer address
|
|
294
|
+
* 2: id (uint64) — session ID
|
|
295
|
+
*
|
|
296
|
+
* NOTE: v3 renamed MsgEndSession to MsgCancelSession and removed the rating field.
|
|
297
|
+
* The v2 MsgEndRequest had a rating field — v3 does not.
|
|
298
|
+
*/
|
|
299
|
+
export function encodeMsgEndSession({ from, id }) {
|
|
300
|
+
return Uint8Array.from(Buffer.concat([
|
|
301
|
+
protoString(1, from),
|
|
302
|
+
protoInt64(2, id),
|
|
303
|
+
]));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Extract session ID from MsgStartSession tx result.
|
|
308
|
+
* Checks ABCI events for sentinel.node.v3.EventCreateSession.session_id
|
|
309
|
+
*/
|
|
310
|
+
export function extractSessionId(txResult) {
|
|
311
|
+
// Try ABCI events first
|
|
312
|
+
for (const event of (txResult.events || [])) {
|
|
313
|
+
if (/session/i.test(event.type)) {
|
|
314
|
+
for (const attr of (event.attributes || [])) {
|
|
315
|
+
const k = typeof attr.key === 'string' ? attr.key
|
|
316
|
+
: Buffer.from(attr.key, 'base64').toString('utf8');
|
|
317
|
+
const v = typeof attr.value === 'string' ? attr.value
|
|
318
|
+
: Buffer.from(attr.value, 'base64').toString('utf8');
|
|
319
|
+
if (k === 'session_id' || k === 'SessionID' || k === 'id') {
|
|
320
|
+
const id = BigInt(v.replace(/"/g, ''));
|
|
321
|
+
if (id > 0n) return id;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
// Try rawLog
|
|
327
|
+
try {
|
|
328
|
+
const logs = JSON.parse(txResult.rawLog || '[]');
|
|
329
|
+
for (const log of (Array.isArray(logs) ? logs : [])) {
|
|
330
|
+
for (const ev of (log.events || [])) {
|
|
331
|
+
for (const attr of (ev.attributes || [])) {
|
|
332
|
+
if (attr.key === 'session_id' || attr.key === 'id') {
|
|
333
|
+
const id = BigInt(String(attr.value).replace(/"/g, ''));
|
|
334
|
+
if (id > 0n) return id;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
} catch { }
|
|
340
|
+
return null;
|
|
341
|
+
}
|