@thru/thru-sdk 0.0.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.
Files changed (63) hide show
  1. package/README.md +7 -0
  2. package/buf.gen.yaml +12 -0
  3. package/buf.lock +9 -0
  4. package/buf.yaml +15 -0
  5. package/dist/sdk.d.ts +1354 -0
  6. package/dist/sdk.js +1130 -0
  7. package/dist/sdk.js.map +1 -0
  8. package/package.json +39 -0
  9. package/proto/thru/common/v1/consensus.proto +75 -0
  10. package/proto/thru/common/v1/errors.proto +67 -0
  11. package/proto/thru/common/v1/filters.proto +50 -0
  12. package/proto/thru/common/v1/pagination.proto +47 -0
  13. package/proto/thru/core/v1/account.proto +138 -0
  14. package/proto/thru/core/v1/block.proto +82 -0
  15. package/proto/thru/core/v1/state.proto +37 -0
  16. package/proto/thru/core/v1/transaction.proto +95 -0
  17. package/proto/thru/core/v1/types.proto +52 -0
  18. package/proto/thru/services/v1/command_service.proto +45 -0
  19. package/proto/thru/services/v1/query_service.proto +344 -0
  20. package/proto/thru/services/v1/streaming_service.proto +128 -0
  21. package/thru-ts-client-sdk/core/bound-client.ts +129 -0
  22. package/thru-ts-client-sdk/core/client.ts +38 -0
  23. package/thru-ts-client-sdk/counter.ts +216 -0
  24. package/thru-ts-client-sdk/create-account.ts +78 -0
  25. package/thru-ts-client-sdk/defaults.ts +17 -0
  26. package/thru-ts-client-sdk/get-height.ts +52 -0
  27. package/thru-ts-client-sdk/modules/accounts.ts +137 -0
  28. package/thru-ts-client-sdk/modules/blocks.ts +75 -0
  29. package/thru-ts-client-sdk/modules/events.ts +20 -0
  30. package/thru-ts-client-sdk/modules/height.ts +9 -0
  31. package/thru-ts-client-sdk/modules/helpers.ts +340 -0
  32. package/thru-ts-client-sdk/modules/proofs.ts +20 -0
  33. package/thru-ts-client-sdk/modules/streaming.ts +34 -0
  34. package/thru-ts-client-sdk/modules/transactions.ts +274 -0
  35. package/thru-ts-client-sdk/proto/buf/validate/validate_pb.ts +4761 -0
  36. package/thru-ts-client-sdk/proto/google/api/annotations_pb.ts +39 -0
  37. package/thru-ts-client-sdk/proto/google/api/client_pb.ts +953 -0
  38. package/thru-ts-client-sdk/proto/google/api/field_behavior_pb.ts +157 -0
  39. package/thru-ts-client-sdk/proto/google/api/http_pb.ts +474 -0
  40. package/thru-ts-client-sdk/proto/google/api/launch_stage_pb.ts +118 -0
  41. package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +163 -0
  42. package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +130 -0
  43. package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +81 -0
  44. package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +80 -0
  45. package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +358 -0
  46. package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +260 -0
  47. package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +104 -0
  48. package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +327 -0
  49. package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +101 -0
  50. package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +81 -0
  51. package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +813 -0
  52. package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +391 -0
  53. package/thru-ts-client-sdk/sdk.ts +58 -0
  54. package/thru-ts-client-sdk/transactions/Transaction.ts +240 -0
  55. package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +48 -0
  56. package/thru-ts-client-sdk/transactions/__tests__/transaction.test.ts +95 -0
  57. package/thru-ts-client-sdk/transactions/index.ts +3 -0
  58. package/thru-ts-client-sdk/transactions/types.ts +64 -0
  59. package/thru-ts-client-sdk/transactions/utils.ts +134 -0
  60. package/thru-ts-client-sdk/types/types.ts +8 -0
  61. package/thru-ts-client-sdk/utils/utils.ts +70 -0
  62. package/tsconfig.json +9 -0
  63. package/tsup.config.ts +10 -0
@@ -0,0 +1,391 @@
1
+ // @generated by protoc-gen-es v2.9.0 with parameter "target=ts"
2
+ // @generated from file thru/services/v1/streaming_service.proto (package thru.services.v1, edition 2023)
3
+ // option features.field_presence = EXPLICIT;
4
+ /* eslint-disable */
5
+
6
+ import type { GenFile, GenMessage, GenService } from "@bufbuild/protobuf/codegenv2";
7
+ import { fileDesc, messageDesc, serviceDesc } from "@bufbuild/protobuf/codegenv2";
8
+ import { file_buf_validate_validate } from "../../../buf/validate/validate_pb";
9
+ import { file_google_api_field_behavior } from "../../../google/api/field_behavior_pb";
10
+ import type { Duration, Timestamp } from "@bufbuild/protobuf/wkt";
11
+ import { file_google_protobuf_duration, file_google_protobuf_timestamp } from "@bufbuild/protobuf/wkt";
12
+ import type { ConsensusStatus } from "../../common/v1/consensus_pb";
13
+ import { file_thru_common_v1_consensus } from "../../common/v1/consensus_pb";
14
+ import type { Filter } from "../../common/v1/filters_pb";
15
+ import { file_thru_common_v1_filters } from "../../common/v1/filters_pb";
16
+ import type { Account, AccountMeta, AccountPage, AccountView } from "../../core/v1/account_pb";
17
+ import { file_thru_core_v1_account } from "../../core/v1/account_pb";
18
+ import type { Block, BlockView } from "../../core/v1/block_pb";
19
+ import { file_thru_core_v1_block } from "../../core/v1/block_pb";
20
+ import type { Transaction, TransactionExecutionResult } from "../../core/v1/transaction_pb";
21
+ import { file_thru_core_v1_transaction } from "../../core/v1/transaction_pb";
22
+ import type { Pubkey, Signature } from "../../core/v1/types_pb";
23
+ import { file_thru_core_v1_types } from "../../core/v1/types_pb";
24
+ import type { Message } from "@bufbuild/protobuf";
25
+
26
+ /**
27
+ * Describes the file thru/services/v1/streaming_service.proto.
28
+ */
29
+ export const file_thru_services_v1_streaming_service: GenFile = /*@__PURE__*/
30
+ fileDesc("Cih0aHJ1L3NlcnZpY2VzL3YxL3N0cmVhbWluZ19zZXJ2aWNlLnByb3RvEhB0aHJ1LnNlcnZpY2VzLnYxIsQB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ration, file_google_protobuf_timestamp, file_thru_common_v1_consensus, file_thru_common_v1_filters, file_thru_core_v1_account, file_thru_core_v1_block, file_thru_core_v1_transaction, file_thru_core_v1_types]);
31
+
32
+ /**
33
+ * StreamBlocksRequest subscribes to real-time block updates.
34
+ *
35
+ * @generated from message thru.services.v1.StreamBlocksRequest
36
+ */
37
+ export type StreamBlocksRequest = Message<"thru.services.v1.StreamBlocksRequest"> & {
38
+ /**
39
+ * @generated from field: uint64 start_slot = 1;
40
+ */
41
+ startSlot: bigint;
42
+
43
+ /**
44
+ * @generated from field: thru.common.v1.Filter filter = 2;
45
+ */
46
+ filter?: Filter;
47
+
48
+ /**
49
+ * @generated from field: thru.core.v1.BlockView view = 3;
50
+ */
51
+ view: BlockView;
52
+
53
+ /**
54
+ * @generated from field: thru.common.v1.ConsensusStatus min_consensus = 4;
55
+ */
56
+ minConsensus: ConsensusStatus;
57
+ };
58
+
59
+ /**
60
+ * Describes the message thru.services.v1.StreamBlocksRequest.
61
+ * Use `create(StreamBlocksRequestSchema)` to create a new message.
62
+ */
63
+ export const StreamBlocksRequestSchema: GenMessage<StreamBlocksRequest> = /*@__PURE__*/
64
+ messageDesc(file_thru_services_v1_streaming_service, 0);
65
+
66
+ /**
67
+ * StreamBlocksResponse delivers block updates.
68
+ *
69
+ * @generated from message thru.services.v1.StreamBlocksResponse
70
+ */
71
+ export type StreamBlocksResponse = Message<"thru.services.v1.StreamBlocksResponse"> & {
72
+ /**
73
+ * @generated from field: thru.core.v1.Block block = 1;
74
+ */
75
+ block?: Block;
76
+ };
77
+
78
+ /**
79
+ * Describes the message thru.services.v1.StreamBlocksResponse.
80
+ * Use `create(StreamBlocksResponseSchema)` to create a new message.
81
+ */
82
+ export const StreamBlocksResponseSchema: GenMessage<StreamBlocksResponse> = /*@__PURE__*/
83
+ messageDesc(file_thru_services_v1_streaming_service, 1);
84
+
85
+ /**
86
+ * StreamAccountUpdatesRequest subscribes to account delta events.
87
+ *
88
+ * @generated from message thru.services.v1.StreamAccountUpdatesRequest
89
+ */
90
+ export type StreamAccountUpdatesRequest = Message<"thru.services.v1.StreamAccountUpdatesRequest"> & {
91
+ /**
92
+ * @generated from field: thru.core.v1.Pubkey address = 1;
93
+ */
94
+ address?: Pubkey;
95
+
96
+ /**
97
+ * @generated from field: thru.core.v1.AccountView view = 2;
98
+ */
99
+ view: AccountView;
100
+
101
+ /**
102
+ * @generated from field: thru.common.v1.Filter filter = 4;
103
+ */
104
+ filter?: Filter;
105
+ };
106
+
107
+ /**
108
+ * Describes the message thru.services.v1.StreamAccountUpdatesRequest.
109
+ * Use `create(StreamAccountUpdatesRequestSchema)` to create a new message.
110
+ */
111
+ export const StreamAccountUpdatesRequestSchema: GenMessage<StreamAccountUpdatesRequest> = /*@__PURE__*/
112
+ messageDesc(file_thru_services_v1_streaming_service, 2);
113
+
114
+ /**
115
+ * AccountUpdate describes a delta for an account.
116
+ *
117
+ * @generated from message thru.services.v1.AccountUpdate
118
+ */
119
+ export type AccountUpdate = Message<"thru.services.v1.AccountUpdate"> & {
120
+ /**
121
+ * @generated from field: uint64 slot = 1;
122
+ */
123
+ slot: bigint;
124
+
125
+ /**
126
+ * @generated from field: thru.core.v1.AccountPage page = 2;
127
+ */
128
+ page?: AccountPage;
129
+
130
+ /**
131
+ * @generated from field: thru.core.v1.AccountMeta meta = 3;
132
+ */
133
+ meta?: AccountMeta;
134
+
135
+ /**
136
+ * @generated from field: bool delete = 4;
137
+ */
138
+ delete: boolean;
139
+ };
140
+
141
+ /**
142
+ * Describes the message thru.services.v1.AccountUpdate.
143
+ * Use `create(AccountUpdateSchema)` to create a new message.
144
+ */
145
+ export const AccountUpdateSchema: GenMessage<AccountUpdate> = /*@__PURE__*/
146
+ messageDesc(file_thru_services_v1_streaming_service, 3);
147
+
148
+ /**
149
+ * StreamAccountUpdatesResponse contains either an initial snapshot or a delta.
150
+ *
151
+ * @generated from message thru.services.v1.StreamAccountUpdatesResponse
152
+ */
153
+ export type StreamAccountUpdatesResponse = Message<"thru.services.v1.StreamAccountUpdatesResponse"> & {
154
+ /**
155
+ * @generated from oneof thru.services.v1.StreamAccountUpdatesResponse.message
156
+ */
157
+ message: {
158
+ /**
159
+ * @generated from field: thru.core.v1.Account snapshot = 1;
160
+ */
161
+ value: Account;
162
+ case: "snapshot";
163
+ } | {
164
+ /**
165
+ * @generated from field: thru.services.v1.AccountUpdate update = 2;
166
+ */
167
+ value: AccountUpdate;
168
+ case: "update";
169
+ } | { case: undefined; value?: undefined };
170
+ };
171
+
172
+ /**
173
+ * Describes the message thru.services.v1.StreamAccountUpdatesResponse.
174
+ * Use `create(StreamAccountUpdatesResponseSchema)` to create a new message.
175
+ */
176
+ export const StreamAccountUpdatesResponseSchema: GenMessage<StreamAccountUpdatesResponse> = /*@__PURE__*/
177
+ messageDesc(file_thru_services_v1_streaming_service, 4);
178
+
179
+ /**
180
+ * StreamTransactionsRequest subscribes to transaction confirmations.
181
+ *
182
+ * @generated from message thru.services.v1.StreamTransactionsRequest
183
+ */
184
+ export type StreamTransactionsRequest = Message<"thru.services.v1.StreamTransactionsRequest"> & {
185
+ /**
186
+ * @generated from field: thru.common.v1.Filter filter = 1;
187
+ */
188
+ filter?: Filter;
189
+
190
+ /**
191
+ * @generated from field: thru.common.v1.ConsensusStatus min_consensus = 2;
192
+ */
193
+ minConsensus: ConsensusStatus;
194
+ };
195
+
196
+ /**
197
+ * Describes the message thru.services.v1.StreamTransactionsRequest.
198
+ * Use `create(StreamTransactionsRequestSchema)` to create a new message.
199
+ */
200
+ export const StreamTransactionsRequestSchema: GenMessage<StreamTransactionsRequest> = /*@__PURE__*/
201
+ messageDesc(file_thru_services_v1_streaming_service, 5);
202
+
203
+ /**
204
+ * StreamTransactionsResponse delivers transaction events.
205
+ *
206
+ * @generated from message thru.services.v1.StreamTransactionsResponse
207
+ */
208
+ export type StreamTransactionsResponse = Message<"thru.services.v1.StreamTransactionsResponse"> & {
209
+ /**
210
+ * @generated from field: thru.core.v1.Transaction transaction = 1;
211
+ */
212
+ transaction?: Transaction;
213
+ };
214
+
215
+ /**
216
+ * Describes the message thru.services.v1.StreamTransactionsResponse.
217
+ * Use `create(StreamTransactionsResponseSchema)` to create a new message.
218
+ */
219
+ export const StreamTransactionsResponseSchema: GenMessage<StreamTransactionsResponse> = /*@__PURE__*/
220
+ messageDesc(file_thru_services_v1_streaming_service, 6);
221
+
222
+ /**
223
+ * StreamEventsRequest subscribes to chain events.
224
+ *
225
+ * @generated from message thru.services.v1.StreamEventsRequest
226
+ */
227
+ export type StreamEventsRequest = Message<"thru.services.v1.StreamEventsRequest"> & {
228
+ /**
229
+ * @generated from field: thru.common.v1.Filter filter = 1;
230
+ */
231
+ filter?: Filter;
232
+ };
233
+
234
+ /**
235
+ * Describes the message thru.services.v1.StreamEventsRequest.
236
+ * Use `create(StreamEventsRequestSchema)` to create a new message.
237
+ */
238
+ export const StreamEventsRequestSchema: GenMessage<StreamEventsRequest> = /*@__PURE__*/
239
+ messageDesc(file_thru_services_v1_streaming_service, 7);
240
+
241
+ /**
242
+ * StreamEventsResponse delivers event payloads.
243
+ *
244
+ * @generated from message thru.services.v1.StreamEventsResponse
245
+ */
246
+ export type StreamEventsResponse = Message<"thru.services.v1.StreamEventsResponse"> & {
247
+ /**
248
+ * @generated from field: string event_id = 1;
249
+ */
250
+ eventId: string;
251
+
252
+ /**
253
+ * @generated from field: bytes payload = 2;
254
+ */
255
+ payload: Uint8Array;
256
+
257
+ /**
258
+ * @generated from field: google.protobuf.Timestamp timestamp = 3;
259
+ */
260
+ timestamp?: Timestamp;
261
+
262
+ /**
263
+ * @generated from field: thru.core.v1.Pubkey program = 4;
264
+ */
265
+ program?: Pubkey;
266
+
267
+ /**
268
+ * @generated from field: uint32 call_idx = 5;
269
+ */
270
+ callIdx: number;
271
+
272
+ /**
273
+ * @generated from field: thru.core.v1.Signature signature = 6;
274
+ */
275
+ signature?: Signature;
276
+
277
+ /**
278
+ * @generated from field: uint64 slot = 7;
279
+ */
280
+ slot: bigint;
281
+ };
282
+
283
+ /**
284
+ * Describes the message thru.services.v1.StreamEventsResponse.
285
+ * Use `create(StreamEventsResponseSchema)` to create a new message.
286
+ */
287
+ export const StreamEventsResponseSchema: GenMessage<StreamEventsResponse> = /*@__PURE__*/
288
+ messageDesc(file_thru_services_v1_streaming_service, 8);
289
+
290
+ /**
291
+ * TrackTransactionRequest subscribes to status updates for a transaction.
292
+ *
293
+ * @generated from message thru.services.v1.TrackTransactionRequest
294
+ */
295
+ export type TrackTransactionRequest = Message<"thru.services.v1.TrackTransactionRequest"> & {
296
+ /**
297
+ * @generated from field: thru.core.v1.Signature signature = 1;
298
+ */
299
+ signature?: Signature;
300
+
301
+ /**
302
+ * @generated from field: google.protobuf.Duration timeout = 2;
303
+ */
304
+ timeout?: Duration;
305
+ };
306
+
307
+ /**
308
+ * Describes the message thru.services.v1.TrackTransactionRequest.
309
+ * Use `create(TrackTransactionRequestSchema)` to create a new message.
310
+ */
311
+ export const TrackTransactionRequestSchema: GenMessage<TrackTransactionRequest> = /*@__PURE__*/
312
+ messageDesc(file_thru_services_v1_streaming_service, 9);
313
+
314
+ /**
315
+ * TrackTransactionResponse reports status transitions for a transaction.
316
+ *
317
+ * @generated from message thru.services.v1.TrackTransactionResponse
318
+ */
319
+ export type TrackTransactionResponse = Message<"thru.services.v1.TrackTransactionResponse"> & {
320
+ /**
321
+ * @generated from field: thru.core.v1.Signature signature = 1;
322
+ */
323
+ signature?: Signature;
324
+
325
+ /**
326
+ * @generated from field: thru.common.v1.ConsensusStatus consensus_status = 2;
327
+ */
328
+ consensusStatus: ConsensusStatus;
329
+
330
+ /**
331
+ * @generated from field: thru.core.v1.TransactionExecutionResult execution_result = 3;
332
+ */
333
+ executionResult?: TransactionExecutionResult;
334
+ };
335
+
336
+ /**
337
+ * Describes the message thru.services.v1.TrackTransactionResponse.
338
+ * Use `create(TrackTransactionResponseSchema)` to create a new message.
339
+ */
340
+ export const TrackTransactionResponseSchema: GenMessage<TrackTransactionResponse> = /*@__PURE__*/
341
+ messageDesc(file_thru_services_v1_streaming_service, 10);
342
+
343
+ /**
344
+ * StreamingService serves server-streaming gRPC APIs for real-time data.
345
+ *
346
+ * @generated from service thru.services.v1.StreamingService
347
+ */
348
+ export const StreamingService: GenService<{
349
+ /**
350
+ * @generated from rpc thru.services.v1.StreamingService.StreamBlocks
351
+ */
352
+ streamBlocks: {
353
+ methodKind: "server_streaming";
354
+ input: typeof StreamBlocksRequestSchema;
355
+ output: typeof StreamBlocksResponseSchema;
356
+ },
357
+ /**
358
+ * @generated from rpc thru.services.v1.StreamingService.StreamAccountUpdates
359
+ */
360
+ streamAccountUpdates: {
361
+ methodKind: "server_streaming";
362
+ input: typeof StreamAccountUpdatesRequestSchema;
363
+ output: typeof StreamAccountUpdatesResponseSchema;
364
+ },
365
+ /**
366
+ * @generated from rpc thru.services.v1.StreamingService.StreamTransactions
367
+ */
368
+ streamTransactions: {
369
+ methodKind: "server_streaming";
370
+ input: typeof StreamTransactionsRequestSchema;
371
+ output: typeof StreamTransactionsResponseSchema;
372
+ },
373
+ /**
374
+ * @generated from rpc thru.services.v1.StreamingService.StreamEvents
375
+ */
376
+ streamEvents: {
377
+ methodKind: "server_streaming";
378
+ input: typeof StreamEventsRequestSchema;
379
+ output: typeof StreamEventsResponseSchema;
380
+ },
381
+ /**
382
+ * @generated from rpc thru.services.v1.StreamingService.TrackTransaction
383
+ */
384
+ trackTransaction: {
385
+ methodKind: "server_streaming";
386
+ input: typeof TrackTransactionRequestSchema;
387
+ output: typeof TrackTransactionResponseSchema;
388
+ },
389
+ }> = /*@__PURE__*/
390
+ serviceDesc(file_thru_services_v1_streaming_service, 0);
391
+
@@ -0,0 +1,58 @@
1
+ import { createBoundThruClient, Thru } from "./core/bound-client";
2
+ import type { ThruClientConfig } from "./core/client";
3
+ import { createThruClientContext } from "./core/client";
4
+ import type { SignedTransactionResult } from "./transactions";
5
+ import { TransactionBuilder } from "./transactions";
6
+
7
+ export { createBoundThruClient } from "./core/bound-client";
8
+ export type { Thru } from "./core/bound-client";
9
+
10
+ export { createThruClientContext } from "./core/client";
11
+ export type { ThruClientConfig, ThruClientContext } from "./core/client";
12
+
13
+ export * as accounts from "./modules/accounts";
14
+ export * as blocks from "./modules/blocks";
15
+ export * as events from "./modules/events";
16
+ export * as height from "./modules/height";
17
+ export * as proofs from "./modules/proofs";
18
+ export * as streaming from "./modules/streaming";
19
+ export * as transactions from "./modules/transactions";
20
+
21
+ export { ConsensusStatus } from "./proto/thru/common/v1/consensus_pb";
22
+
23
+ export type {
24
+ AccountQueryOptions,
25
+ ListOwnedAccountsOptions,
26
+ RawAccountQueryOptions,
27
+ CreateAccountOptions,
28
+ } from "./modules/accounts";
29
+ export type { BlockQueryOptions, ListBlocksOptions, RawBlockQueryOptions } from "./modules/blocks";
30
+ export type { GetEventOptions } from "./modules/events";
31
+ export {
32
+ decodeAddress,
33
+ decodeSignature,
34
+ deriveProgramAddress,
35
+ encodeAddress,
36
+ encodeSignature,
37
+ toPubkey
38
+ } from "./modules/helpers";
39
+ export type {
40
+ BlockSelector,
41
+ BytesLike,
42
+ DeriveProgramAddressOptions,
43
+ DeriveProgramAddressResult
44
+ } from "./modules/helpers";
45
+ export type { TrackTransactionOptions } from "./modules/streaming";
46
+ export type {
47
+ BuildAndSignTransactionOptions, BuildTransactionOptions, RawTransactionQueryOptions, TransactionAccountsConfig,
48
+ TransactionContentConfig, TransactionFeePayerConfig, TransactionHeaderConfig, TransactionQueryOptions
49
+ } from "./modules/transactions";
50
+ export { Transaction as SdkTransaction } from "./transactions";
51
+ export type { GenerateStateProofOptions } from "./types/types";
52
+ export { TransactionBuilder };
53
+ export type { SignedTransactionResult };
54
+
55
+ export function createThruClient(config: ThruClientConfig = {}): Thru {
56
+ const ctx = createThruClientContext(config);
57
+ return createBoundThruClient(ctx);
58
+ }
@@ -0,0 +1,240 @@
1
+ import { signAsync } from "@noble/ed25519";
2
+ import type { AccountAddress, Bytes64, OptionalProofs, TransactionAccountsInput, TransactionHeaderInput } from "./types";
3
+
4
+ const DEFAULT_FLAGS = 0;
5
+ const TRANSACTION_VERSION = 1;
6
+ const SIGNATURE_LENGTH = 64;
7
+ const PUBKEY_LENGTH = 32;
8
+ const HEADER_SIZE = 176;
9
+ const SIGNATURE_PREFIX_SIZE = 64;
10
+
11
+ export class Transaction {
12
+ readonly feePayer: AccountAddress;
13
+ readonly program: AccountAddress;
14
+
15
+ readonly fee: bigint;
16
+ readonly nonce: bigint;
17
+ readonly startSlot: bigint;
18
+ readonly expiryAfter: number;
19
+
20
+ readonly requestedComputeUnits: number;
21
+ readonly requestedStateUnits: number;
22
+ readonly requestedMemoryUnits: number;
23
+ readonly flags: number;
24
+
25
+ readonly readWriteAccounts: AccountAddress[];
26
+ readonly readOnlyAccounts: AccountAddress[];
27
+
28
+ readonly instructions?: Uint8Array;
29
+ readonly feePayerStateProof?: Uint8Array;
30
+ readonly feePayerAccountMetaRaw?: Uint8Array;
31
+
32
+ private signature?: Bytes64;
33
+
34
+ constructor(params: {
35
+ feePayer: AccountAddress;
36
+ program: AccountAddress;
37
+ header: TransactionHeaderInput;
38
+ accounts?: TransactionAccountsInput;
39
+ instructions?: Uint8Array;
40
+ proofs?: OptionalProofs;
41
+ }) {
42
+ this.feePayer = copyKey(params.feePayer);
43
+ this.program = copyKey(params.program);
44
+
45
+ this.fee = params.header.fee;
46
+ this.nonce = params.header.nonce;
47
+ this.startSlot = params.header.startSlot;
48
+ this.expiryAfter = params.header.expiryAfter ?? 0;
49
+
50
+ this.requestedComputeUnits = params.header.computeUnits ?? 0;
51
+ this.requestedStateUnits = params.header.stateUnits ?? 0;
52
+ this.requestedMemoryUnits = params.header.memoryUnits ?? 0;
53
+ this.flags = params.header.flags ?? DEFAULT_FLAGS;
54
+
55
+ this.readWriteAccounts = params.accounts?.readWriteAccounts
56
+ ? params.accounts.readWriteAccounts.map(copyKey)
57
+ : [];
58
+ this.readOnlyAccounts = params.accounts?.readOnlyAccounts
59
+ ? params.accounts.readOnlyAccounts.map(copyKey)
60
+ : [];
61
+
62
+ this.instructions = params.instructions ? new Uint8Array(params.instructions) : undefined;
63
+ this.feePayerStateProof = params.proofs?.feePayerStateProof
64
+ ? new Uint8Array(params.proofs.feePayerStateProof)
65
+ : undefined;
66
+ this.feePayerAccountMetaRaw = params.proofs?.feePayerAccountMetaRaw
67
+ ? new Uint8Array(params.proofs.feePayerAccountMetaRaw)
68
+ : undefined;
69
+ }
70
+
71
+ getSignature(): Bytes64 | undefined {
72
+ return this.signature ? new Uint8Array(this.signature) : undefined;
73
+ }
74
+
75
+ setSignature(signature: Bytes64): void {
76
+ if (signature.length !== SIGNATURE_LENGTH) {
77
+ throw new Error(`Signature must contain ${SIGNATURE_LENGTH} bytes`);
78
+ }
79
+ this.signature = new Uint8Array(signature);
80
+ }
81
+
82
+ async sign(privateKey: Uint8Array): Promise<Bytes64> {
83
+ if (privateKey.length !== 32) {
84
+ throw new Error("Fee payer private key must contain 32 bytes");
85
+ }
86
+ const payload = this.toWireForSigning();
87
+ const signature = await signAsync(payload, privateKey);
88
+ if (signature.length !== SIGNATURE_LENGTH) {
89
+ throw new Error("ed25519 signing produced an invalid signature");
90
+ }
91
+ this.signature = signature;
92
+ return new Uint8Array(signature);
93
+ }
94
+
95
+ toWireForSigning(): Uint8Array {
96
+ const header = this.createHeader(undefined);
97
+ const view = new Uint8Array(header);
98
+ return this.buildWirePayload(view.subarray(SIGNATURE_PREFIX_SIZE));
99
+ }
100
+
101
+ toWire(): Uint8Array {
102
+ const header = this.createHeader(this.signature);
103
+ const payload = this.buildWirePayload(new Uint8Array(header));
104
+ return payload;
105
+ }
106
+
107
+ private createHeader(signature: Uint8Array | undefined): ArrayBufferLike {
108
+ const buffer = new ArrayBuffer(HEADER_SIZE);
109
+ const headerBytes = new Uint8Array(buffer);
110
+ const view = new DataView(buffer);
111
+
112
+ // Fee payer signature (64 bytes)
113
+ if (signature) {
114
+ if (signature.length !== SIGNATURE_LENGTH) {
115
+ throw new Error(`Signature must contain ${SIGNATURE_LENGTH} bytes`);
116
+ }
117
+ headerBytes.set(signature, 0);
118
+ } else {
119
+ headerBytes.fill(0, 0, SIGNATURE_LENGTH);
120
+ }
121
+
122
+ let offset = SIGNATURE_PREFIX_SIZE;
123
+ view.setUint8(offset, TRANSACTION_VERSION);
124
+ offset += 1;
125
+
126
+ view.setUint8(offset, this.flags & 0xff);
127
+ offset += 1;
128
+
129
+ view.setUint16(offset, this.readWriteAccounts.length, true);
130
+ offset += 2;
131
+
132
+ view.setUint16(offset, this.readOnlyAccounts.length, true);
133
+ offset += 2;
134
+
135
+ const instructionLength = this.instructions?.length ?? 0;
136
+ if (instructionLength > 0xffff) {
137
+ throw new Error("Instruction data exceeds maximum length (65535 bytes)");
138
+ }
139
+ view.setUint16(offset, instructionLength, true);
140
+ offset += 2;
141
+
142
+ view.setUint32(offset, ensureUint32(this.requestedComputeUnits), true);
143
+ offset += 4;
144
+
145
+ view.setUint16(offset, ensureUint16(this.requestedStateUnits), true);
146
+ offset += 2;
147
+
148
+ view.setUint16(offset, ensureUint16(this.requestedMemoryUnits), true);
149
+ offset += 2;
150
+
151
+ view.setBigUint64(offset, ensureBigUint64(this.fee), true);
152
+ offset += 8;
153
+
154
+ view.setBigUint64(offset, ensureBigUint64(this.nonce), true);
155
+ offset += 8;
156
+
157
+ view.setBigUint64(offset, ensureBigUint64(this.startSlot), true);
158
+ offset += 8;
159
+
160
+ view.setUint32(offset, ensureUint32(this.expiryAfter), true);
161
+ offset += 4;
162
+
163
+ // padding_0 (4 bytes) zeroed by default
164
+ offset += 4;
165
+
166
+ headerBytes.set(this.feePayer, offset);
167
+ offset += PUBKEY_LENGTH;
168
+
169
+ headerBytes.set(this.program, offset);
170
+
171
+ return buffer;
172
+ }
173
+
174
+ private buildWirePayload(headerWithoutSignature: Uint8Array): Uint8Array {
175
+ const dynamicLength =
176
+ this.readWriteAccounts.length * PUBKEY_LENGTH +
177
+ this.readOnlyAccounts.length * PUBKEY_LENGTH +
178
+ (this.instructions?.length ?? 0) +
179
+ (this.feePayerStateProof?.length ?? 0) +
180
+ (this.feePayerAccountMetaRaw?.length ?? 0);
181
+
182
+ const result = new Uint8Array(headerWithoutSignature.length + dynamicLength);
183
+ result.set(headerWithoutSignature, 0);
184
+
185
+ let offset = headerWithoutSignature.length;
186
+ offset = appendAccountList(result, offset, this.readWriteAccounts);
187
+ offset = appendAccountList(result, offset, this.readOnlyAccounts);
188
+ if (this.instructions) {
189
+ result.set(this.instructions, offset);
190
+ offset += this.instructions.length;
191
+ }
192
+ if (this.feePayerStateProof) {
193
+ result.set(this.feePayerStateProof, offset);
194
+ offset += this.feePayerStateProof.length;
195
+ }
196
+ if (this.feePayerAccountMetaRaw) {
197
+ result.set(this.feePayerAccountMetaRaw, offset);
198
+ offset += this.feePayerAccountMetaRaw.length;
199
+ }
200
+
201
+ return result;
202
+ }
203
+ }
204
+
205
+ function appendAccountList(target: Uint8Array, start: number, accounts: AccountAddress[]): number {
206
+ let offset = start;
207
+ for (const account of accounts) {
208
+ target.set(account, offset);
209
+ offset += PUBKEY_LENGTH;
210
+ }
211
+ return offset;
212
+ }
213
+
214
+ function ensureUint16(value: number): number {
215
+ if (!Number.isInteger(value) || value < 0 || value > 0xffff) {
216
+ throw new Error("Value must fit within uint16 range");
217
+ }
218
+ return value;
219
+ }
220
+
221
+ function ensureUint32(value: number): number {
222
+ if (!Number.isInteger(value) || value < 0 || value > 0xffffffff) {
223
+ throw new Error("Value must fit within uint32 range");
224
+ }
225
+ return value;
226
+ }
227
+
228
+ function ensureBigUint64(value: bigint): bigint {
229
+ if (value < 0n || value > 0xffff_ffff_ffff_ffffn) {
230
+ throw new Error("Value must fit within uint64 range");
231
+ }
232
+ return value;
233
+ }
234
+
235
+ function copyKey(source: AccountAddress): AccountAddress {
236
+ if (source.length !== PUBKEY_LENGTH) {
237
+ throw new Error("Public keys must contain 32 bytes");
238
+ }
239
+ return new Uint8Array(source);
240
+ }