@thru/thru-sdk 0.1.19 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. package/README.md +19 -0
  2. package/dist/{chunk-PH7P5EEU.js → chunk-SHMREHP5.js} +13 -9
  3. package/dist/chunk-SHMREHP5.js.map +1 -0
  4. package/dist/client.d.ts +2 -1
  5. package/dist/client.js +3 -2
  6. package/dist/client.js.map +1 -1
  7. package/dist/metafile-esm.json +1 -1
  8. package/dist/sdk.d.ts +3 -3
  9. package/dist/sdk.js +1 -1
  10. package/dist/{transactions-BzD9hYlc.d.ts → transactions-CLezIeXO.d.ts} +20 -18
  11. package/package.json +7 -3
  12. package/buf.gen.yaml +0 -12
  13. package/buf.lock +0 -9
  14. package/buf.yaml +0 -15
  15. package/dist/chunk-PH7P5EEU.js.map +0 -1
  16. package/proto/thru/common/v1/consensus.proto +0 -73
  17. package/proto/thru/common/v1/errors.proto +0 -65
  18. package/proto/thru/common/v1/filters.proto +0 -60
  19. package/proto/thru/common/v1/pagination.proto +0 -45
  20. package/proto/thru/core/v1/account.proto +0 -137
  21. package/proto/thru/core/v1/block.proto +0 -80
  22. package/proto/thru/core/v1/state.proto +0 -35
  23. package/proto/thru/core/v1/transaction.proto +0 -136
  24. package/proto/thru/core/v1/types.proto +0 -50
  25. package/proto/thru/services/v1/command_service.proto +0 -70
  26. package/proto/thru/services/v1/query_service.proto +0 -344
  27. package/proto/thru/services/v1/streaming_service.proto +0 -126
  28. package/thru-ts-client-sdk/__tests__/helpers/test-utils.ts +0 -228
  29. package/thru-ts-client-sdk/client.ts +0 -10
  30. package/thru-ts-client-sdk/core/__tests__/bound-client.test.ts +0 -354
  31. package/thru-ts-client-sdk/core/__tests__/client.test.ts +0 -53
  32. package/thru-ts-client-sdk/core/bound-client.ts +0 -156
  33. package/thru-ts-client-sdk/core/client.ts +0 -38
  34. package/thru-ts-client-sdk/defaults.ts +0 -26
  35. package/thru-ts-client-sdk/modules/__tests__/accounts.test.ts +0 -406
  36. package/thru-ts-client-sdk/modules/__tests__/blocks.test.ts +0 -199
  37. package/thru-ts-client-sdk/modules/__tests__/events.test.ts +0 -74
  38. package/thru-ts-client-sdk/modules/__tests__/height.test.ts +0 -39
  39. package/thru-ts-client-sdk/modules/__tests__/helpers.test.ts +0 -288
  40. package/thru-ts-client-sdk/modules/__tests__/keys.test.ts +0 -55
  41. package/thru-ts-client-sdk/modules/__tests__/proofs.test.ts +0 -119
  42. package/thru-ts-client-sdk/modules/__tests__/streaming.test.ts +0 -152
  43. package/thru-ts-client-sdk/modules/__tests__/transactions.test.ts +0 -730
  44. package/thru-ts-client-sdk/modules/__tests__/version.test.ts +0 -40
  45. package/thru-ts-client-sdk/modules/accounts.ts +0 -141
  46. package/thru-ts-client-sdk/modules/blocks.ts +0 -75
  47. package/thru-ts-client-sdk/modules/events.ts +0 -20
  48. package/thru-ts-client-sdk/modules/height.ts +0 -9
  49. package/thru-ts-client-sdk/modules/helpers.ts +0 -131
  50. package/thru-ts-client-sdk/modules/keys.ts +0 -29
  51. package/thru-ts-client-sdk/modules/proofs.ts +0 -20
  52. package/thru-ts-client-sdk/modules/streaming.ts +0 -133
  53. package/thru-ts-client-sdk/modules/transactions.ts +0 -374
  54. package/thru-ts-client-sdk/modules/version.ts +0 -10
  55. package/thru-ts-client-sdk/proto/buf/validate/validate_pb.ts +0 -4761
  56. package/thru-ts-client-sdk/proto/google/api/annotations_pb.ts +0 -39
  57. package/thru-ts-client-sdk/proto/google/api/client_pb.ts +0 -953
  58. package/thru-ts-client-sdk/proto/google/api/field_behavior_pb.ts +0 -157
  59. package/thru-ts-client-sdk/proto/google/api/http_pb.ts +0 -474
  60. package/thru-ts-client-sdk/proto/google/api/launch_stage_pb.ts +0 -118
  61. package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +0 -162
  62. package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +0 -129
  63. package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +0 -129
  64. package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +0 -79
  65. package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +0 -359
  66. package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +0 -259
  67. package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +0 -103
  68. package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +0 -528
  69. package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +0 -100
  70. package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +0 -146
  71. package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +0 -819
  72. package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +0 -390
  73. package/thru-ts-client-sdk/sdk.ts +0 -42
  74. package/thru-ts-client-sdk/test-scripts/counter.ts +0 -469
  75. package/thru-ts-client-sdk/test-scripts/create-account.ts +0 -74
  76. package/thru-ts-client-sdk/test-scripts/get-height.ts +0 -52
  77. package/thru-ts-client-sdk/transactions/Transaction.ts +0 -240
  78. package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +0 -53
  79. package/thru-ts-client-sdk/transactions/__tests__/TransactionBuilder.test.ts +0 -411
  80. package/thru-ts-client-sdk/transactions/__tests__/utils.test.ts +0 -214
  81. package/thru-ts-client-sdk/transactions/index.ts +0 -3
  82. package/thru-ts-client-sdk/transactions/types.ts +0 -74
  83. package/thru-ts-client-sdk/transactions/utils.ts +0 -132
  84. package/thru-ts-client-sdk/types/types.ts +0 -8
  85. package/thru-ts-client-sdk/utils/utils.ts +0 -27
  86. package/tsconfig.json +0 -9
  87. package/tsup.config.ts +0 -14
  88. package/vitest.config.ts +0 -31
@@ -1,119 +0,0 @@
1
- import { create } from "@bufbuild/protobuf";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { createMockContext, generateTestAddress, generateTestPubkey } from "../../__tests__/helpers/test-utils";
4
- import { StateProofType } from "../../proto/thru/core/v1/state_pb";
5
- import { GenerateStateProofResponseSchema } from "../../proto/thru/services/v1/query_service_pb";
6
- import { generateStateProof } from "../proofs";
7
-
8
- describe("proofs", () => {
9
- describe("generateStateProof", () => {
10
- it("should generate state proof with address and proof type", async () => {
11
- const ctx = createMockContext();
12
- const mockResponse = create(GenerateStateProofResponseSchema, {
13
- proof: {
14
- proof: new Uint8Array([1, 2, 3, 4]),
15
- },
16
- });
17
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue(mockResponse);
18
-
19
- const address = generateTestPubkey(0x01);
20
- const result = await generateStateProof(ctx, {
21
- address,
22
- proofType: StateProofType.CREATING,
23
- targetSlot: 1000n,
24
- });
25
-
26
- expect(result).toBe(mockResponse);
27
- expect(ctx.query.generateStateProof).toHaveBeenCalledTimes(1);
28
- });
29
-
30
- it("should accept address as Uint8Array", async () => {
31
- const ctx = createMockContext();
32
- const mockResponse = create(GenerateStateProofResponseSchema, {
33
- proof: { proof: new Uint8Array([1, 2, 3]) },
34
- });
35
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue(mockResponse);
36
-
37
- const address = generateTestPubkey(0x01);
38
- await generateStateProof(ctx, {
39
- address,
40
- proofType: StateProofType.CREATING,
41
- targetSlot: 1000n,
42
- });
43
-
44
- const callArgs = (ctx.query.generateStateProof as any).mock.calls[0][0];
45
- expect(callArgs.request.address?.value).toEqual(address);
46
- });
47
-
48
- it("should accept address as string", async () => {
49
- const ctx = createMockContext();
50
- const mockResponse = create(GenerateStateProofResponseSchema, {
51
- proof: { proof: new Uint8Array([1, 2, 3]) },
52
- });
53
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue(mockResponse);
54
-
55
- const address = generateTestAddress(0x01);
56
- await generateStateProof(ctx, {
57
- address,
58
- proofType: StateProofType.CREATING,
59
- targetSlot: 1000n,
60
- });
61
-
62
- const callArgs = (ctx.query.generateStateProof as any).mock.calls[0][0];
63
- expect(callArgs.request.address).toBeDefined();
64
- });
65
-
66
- it("should include proof type in request", async () => {
67
- const ctx = createMockContext();
68
- const mockResponse = create(GenerateStateProofResponseSchema, {
69
- proof: { proof: new Uint8Array([1, 2, 3]) },
70
- });
71
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue(mockResponse);
72
-
73
- await generateStateProof(ctx, {
74
- address: generateTestPubkey(0x01),
75
- proofType: StateProofType.READING,
76
- targetSlot: 1000n,
77
- });
78
-
79
- const callArgs = (ctx.query.generateStateProof as any).mock.calls[0][0];
80
- expect(callArgs.request.request?.proofType).toBe(StateProofType.READING);
81
- });
82
-
83
- it("should include target slot in request", async () => {
84
- const ctx = createMockContext();
85
- const mockResponse = create(GenerateStateProofResponseSchema, {
86
- proof: { proof: new Uint8Array([1, 2, 3]) },
87
- });
88
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue(mockResponse);
89
-
90
- await generateStateProof(ctx, {
91
- address: generateTestPubkey(0x01),
92
- proofType: StateProofType.CREATING,
93
- targetSlot: 2000n,
94
- });
95
-
96
- // Verify generateStateProof was called
97
- expect(ctx.query.generateStateProof).toHaveBeenCalledTimes(1);
98
- const callArgs = (ctx.query.generateStateProof as any).mock.calls[0][0];
99
- expect(callArgs.request).toBeDefined();
100
- });
101
-
102
- it("should allow undefined address", async () => {
103
- const ctx = createMockContext();
104
- const mockResponse = create(GenerateStateProofResponseSchema, {
105
- proof: { proof: new Uint8Array([1, 2, 3]) },
106
- });
107
- vi.spyOn(ctx.query, "generateStateProof").mockResolvedValue(mockResponse);
108
-
109
- await generateStateProof(ctx, {
110
- proofType: StateProofType.CREATING,
111
- targetSlot: 1000n,
112
- });
113
-
114
- const callArgs = (ctx.query.generateStateProof as any).mock.calls[0][0];
115
- expect(callArgs.request.request?.address).toBeUndefined();
116
- });
117
- });
118
- });
119
-
@@ -1,152 +0,0 @@
1
- import { create } from "@bufbuild/protobuf";
2
- import { describe, expect, it, vi } from "vitest";
3
- import { createMockContext, generateTestSignature, generateTestSignatureString } from "../../__tests__/helpers/test-utils";
4
- import { ConsensusStatus } from "../../proto/thru/common/v1/consensus_pb";
5
- import { TrackTransactionResponseSchema } from "../../proto/thru/services/v1/streaming_service_pb";
6
- import { trackTransaction } from "../streaming";
7
-
8
- describe("streaming", () => {
9
- describe("trackTransaction", () => {
10
- it("should return async iterable for transaction tracking", async () => {
11
- const ctx = createMockContext();
12
- const mockResponse1 = create(TrackTransactionResponseSchema, {
13
- consensusStatus: ConsensusStatus.UNSPECIFIED,
14
- });
15
- const mockResponse2 = create(TrackTransactionResponseSchema, {
16
- consensusStatus: ConsensusStatus.FINALIZED,
17
- });
18
-
19
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
20
- (async function* () {
21
- yield mockResponse1;
22
- yield mockResponse2;
23
- })()
24
- );
25
-
26
- const signature = generateTestSignature();
27
- const iterable = trackTransaction(ctx, signature);
28
-
29
- const results = [];
30
- for await (const response of iterable) {
31
- results.push(response);
32
- }
33
-
34
- expect(results).toHaveLength(2);
35
- expect(results[0]).toBe(mockResponse1);
36
- expect(results[1]).toBe(mockResponse2);
37
- expect(ctx.streaming.trackTransaction).toHaveBeenCalledTimes(1);
38
- });
39
-
40
- it("should accept signature as Uint8Array", async () => {
41
- const ctx = createMockContext();
42
- const signature = generateTestSignature();
43
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
44
- (async function* () { yield create(TrackTransactionResponseSchema, {}); })()
45
- );
46
-
47
- trackTransaction(ctx, signature);
48
-
49
- const callArgs = (ctx.streaming.trackTransaction as any).mock.calls[0][0];
50
- expect(callArgs.signature.value).toEqual(signature);
51
- });
52
-
53
- it("should accept signature as string", async () => {
54
- const ctx = createMockContext();
55
- const signatureString = generateTestSignatureString();
56
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
57
- (async function* () { yield create(TrackTransactionResponseSchema, {}); })()
58
- );
59
-
60
- trackTransaction(ctx, signatureString);
61
-
62
- const callArgs = (ctx.streaming.trackTransaction as any).mock.calls[0][0];
63
- expect(callArgs.signature.value.length).toBe(64);
64
- });
65
-
66
- it("should convert timeoutMs to seconds and nanos", async () => {
67
- const ctx = createMockContext();
68
- const signature = generateTestSignature();
69
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
70
- (async function* () { yield create(TrackTransactionResponseSchema, {}); })()
71
- );
72
-
73
- trackTransaction(ctx, signature, { timeoutMs: 2500 });
74
-
75
- const callArgs = (ctx.streaming.trackTransaction as any).mock.calls[0][0];
76
- expect(callArgs.timeout?.seconds).toBe(2n);
77
- expect(callArgs.timeout?.nanos).toBe(500_000_000);
78
- });
79
-
80
- it("should handle timeoutMs less than 1000ms", async () => {
81
- const ctx = createMockContext();
82
- const signature = generateTestSignature();
83
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
84
- (async function* () { yield create(TrackTransactionResponseSchema, {}); })()
85
- );
86
-
87
- trackTransaction(ctx, signature, { timeoutMs: 500 });
88
-
89
- const callArgs = (ctx.streaming.trackTransaction as any).mock.calls[0][0];
90
- expect(callArgs.timeout?.seconds).toBe(0n);
91
- expect(callArgs.timeout?.nanos).toBe(500_000_000);
92
- });
93
-
94
- it("should not include timeout when timeoutMs is undefined", async () => {
95
- const ctx = createMockContext();
96
- const signature = generateTestSignature();
97
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
98
- (async function* () { yield create(TrackTransactionResponseSchema, {}); })()
99
- );
100
-
101
- trackTransaction(ctx, signature);
102
-
103
- const callArgs = (ctx.streaming.trackTransaction as any).mock.calls[0][0];
104
- expect(callArgs.timeout).toBeUndefined();
105
- });
106
-
107
- it("should pass AbortSignal to streaming client", async () => {
108
- const ctx = createMockContext();
109
- const signature = generateTestSignature();
110
- const abortController = new AbortController();
111
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
112
- (async function* () { yield create(TrackTransactionResponseSchema, {}); })()
113
- );
114
-
115
- trackTransaction(ctx, signature, { signal: abortController.signal });
116
-
117
- const callOptions = (ctx.streaming.trackTransaction as any).mock.calls[0][1];
118
- expect(callOptions.signal).toBe(abortController.signal);
119
- });
120
-
121
- it("should handle multiple responses", async () => {
122
- const ctx = createMockContext();
123
- const responses = [
124
- create(TrackTransactionResponseSchema, { consensusStatus: ConsensusStatus.OBSERVED }),
125
- create(TrackTransactionResponseSchema, { consensusStatus: ConsensusStatus.INCLUDED }),
126
- create(TrackTransactionResponseSchema, { consensusStatus: ConsensusStatus.FINALIZED }),
127
- ];
128
-
129
- vi.spyOn(ctx.streaming, "trackTransaction").mockReturnValue(
130
- (async function* () {
131
- for (const response of responses) {
132
- yield response;
133
- }
134
- })()
135
- );
136
-
137
- const signature = generateTestSignature();
138
- const iterable = trackTransaction(ctx, signature);
139
-
140
- const results = [];
141
- for await (const response of iterable) {
142
- results.push(response);
143
- }
144
-
145
- expect(results).toHaveLength(3);
146
- expect(results[0].consensusStatus).toBe(ConsensusStatus.OBSERVED);
147
- expect(results[1].consensusStatus).toBe(ConsensusStatus.INCLUDED);
148
- expect(results[2].consensusStatus).toBe(ConsensusStatus.FINALIZED);
149
- });
150
- });
151
- });
152
-