@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.
- package/README.md +19 -0
- package/dist/{chunk-PH7P5EEU.js → chunk-SHMREHP5.js} +13 -9
- package/dist/chunk-SHMREHP5.js.map +1 -0
- package/dist/client.d.ts +2 -1
- package/dist/client.js +3 -2
- package/dist/client.js.map +1 -1
- package/dist/metafile-esm.json +1 -1
- package/dist/sdk.d.ts +3 -3
- package/dist/sdk.js +1 -1
- package/dist/{transactions-BzD9hYlc.d.ts → transactions-CLezIeXO.d.ts} +20 -18
- package/package.json +7 -3
- package/buf.gen.yaml +0 -12
- package/buf.lock +0 -9
- package/buf.yaml +0 -15
- package/dist/chunk-PH7P5EEU.js.map +0 -1
- package/proto/thru/common/v1/consensus.proto +0 -73
- package/proto/thru/common/v1/errors.proto +0 -65
- package/proto/thru/common/v1/filters.proto +0 -60
- package/proto/thru/common/v1/pagination.proto +0 -45
- package/proto/thru/core/v1/account.proto +0 -137
- package/proto/thru/core/v1/block.proto +0 -80
- package/proto/thru/core/v1/state.proto +0 -35
- package/proto/thru/core/v1/transaction.proto +0 -136
- package/proto/thru/core/v1/types.proto +0 -50
- package/proto/thru/services/v1/command_service.proto +0 -70
- package/proto/thru/services/v1/query_service.proto +0 -344
- package/proto/thru/services/v1/streaming_service.proto +0 -126
- package/thru-ts-client-sdk/__tests__/helpers/test-utils.ts +0 -228
- package/thru-ts-client-sdk/client.ts +0 -10
- package/thru-ts-client-sdk/core/__tests__/bound-client.test.ts +0 -354
- package/thru-ts-client-sdk/core/__tests__/client.test.ts +0 -53
- package/thru-ts-client-sdk/core/bound-client.ts +0 -156
- package/thru-ts-client-sdk/core/client.ts +0 -38
- package/thru-ts-client-sdk/defaults.ts +0 -26
- package/thru-ts-client-sdk/modules/__tests__/accounts.test.ts +0 -406
- package/thru-ts-client-sdk/modules/__tests__/blocks.test.ts +0 -199
- package/thru-ts-client-sdk/modules/__tests__/events.test.ts +0 -74
- package/thru-ts-client-sdk/modules/__tests__/height.test.ts +0 -39
- package/thru-ts-client-sdk/modules/__tests__/helpers.test.ts +0 -288
- package/thru-ts-client-sdk/modules/__tests__/keys.test.ts +0 -55
- package/thru-ts-client-sdk/modules/__tests__/proofs.test.ts +0 -119
- package/thru-ts-client-sdk/modules/__tests__/streaming.test.ts +0 -152
- package/thru-ts-client-sdk/modules/__tests__/transactions.test.ts +0 -730
- package/thru-ts-client-sdk/modules/__tests__/version.test.ts +0 -40
- package/thru-ts-client-sdk/modules/accounts.ts +0 -141
- package/thru-ts-client-sdk/modules/blocks.ts +0 -75
- package/thru-ts-client-sdk/modules/events.ts +0 -20
- package/thru-ts-client-sdk/modules/height.ts +0 -9
- package/thru-ts-client-sdk/modules/helpers.ts +0 -131
- package/thru-ts-client-sdk/modules/keys.ts +0 -29
- package/thru-ts-client-sdk/modules/proofs.ts +0 -20
- package/thru-ts-client-sdk/modules/streaming.ts +0 -133
- package/thru-ts-client-sdk/modules/transactions.ts +0 -374
- package/thru-ts-client-sdk/modules/version.ts +0 -10
- package/thru-ts-client-sdk/proto/buf/validate/validate_pb.ts +0 -4761
- package/thru-ts-client-sdk/proto/google/api/annotations_pb.ts +0 -39
- package/thru-ts-client-sdk/proto/google/api/client_pb.ts +0 -953
- package/thru-ts-client-sdk/proto/google/api/field_behavior_pb.ts +0 -157
- package/thru-ts-client-sdk/proto/google/api/http_pb.ts +0 -474
- package/thru-ts-client-sdk/proto/google/api/launch_stage_pb.ts +0 -118
- package/thru-ts-client-sdk/proto/thru/common/v1/consensus_pb.ts +0 -162
- package/thru-ts-client-sdk/proto/thru/common/v1/errors_pb.ts +0 -129
- package/thru-ts-client-sdk/proto/thru/common/v1/filters_pb.ts +0 -129
- package/thru-ts-client-sdk/proto/thru/common/v1/pagination_pb.ts +0 -79
- package/thru-ts-client-sdk/proto/thru/core/v1/account_pb.ts +0 -359
- package/thru-ts-client-sdk/proto/thru/core/v1/block_pb.ts +0 -259
- package/thru-ts-client-sdk/proto/thru/core/v1/state_pb.ts +0 -103
- package/thru-ts-client-sdk/proto/thru/core/v1/transaction_pb.ts +0 -528
- package/thru-ts-client-sdk/proto/thru/core/v1/types_pb.ts +0 -100
- package/thru-ts-client-sdk/proto/thru/services/v1/command_service_pb.ts +0 -146
- package/thru-ts-client-sdk/proto/thru/services/v1/query_service_pb.ts +0 -819
- package/thru-ts-client-sdk/proto/thru/services/v1/streaming_service_pb.ts +0 -390
- package/thru-ts-client-sdk/sdk.ts +0 -42
- package/thru-ts-client-sdk/test-scripts/counter.ts +0 -469
- package/thru-ts-client-sdk/test-scripts/create-account.ts +0 -74
- package/thru-ts-client-sdk/test-scripts/get-height.ts +0 -52
- package/thru-ts-client-sdk/transactions/Transaction.ts +0 -240
- package/thru-ts-client-sdk/transactions/TransactionBuilder.ts +0 -53
- package/thru-ts-client-sdk/transactions/__tests__/TransactionBuilder.test.ts +0 -411
- package/thru-ts-client-sdk/transactions/__tests__/utils.test.ts +0 -214
- package/thru-ts-client-sdk/transactions/index.ts +0 -3
- package/thru-ts-client-sdk/transactions/types.ts +0 -74
- package/thru-ts-client-sdk/transactions/utils.ts +0 -132
- package/thru-ts-client-sdk/types/types.ts +0 -8
- package/thru-ts-client-sdk/utils/utils.ts +0 -27
- package/tsconfig.json +0 -9
- package/tsup.config.ts +0 -14
- package/vitest.config.ts +0 -31
package/README.md
CHANGED
|
@@ -8,6 +8,25 @@ Typed TypeScript/JavaScript client for talking to the Thru blockchain. It wraps
|
|
|
8
8
|
npm install @thru/thru-sdk
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
### TypeScript Configuration
|
|
12
|
+
|
|
13
|
+
For optimal import resolution, we recommend using modern TypeScript module resolution in your `tsconfig.json`:
|
|
14
|
+
|
|
15
|
+
```json
|
|
16
|
+
{
|
|
17
|
+
"compilerOptions": {
|
|
18
|
+
"moduleResolution": "bundler",
|
|
19
|
+
"module": "ESNext",
|
|
20
|
+
"target": "ES2020",
|
|
21
|
+
"isolatedModules": true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
**Why?** The SDK uses modern `exports` fields in `package.json` for better tree-shaking and bundler compatibility. The `bundler` resolution strategy fully supports these modern package exports, while the older `node` resolution may require importing from `dist` paths directly.
|
|
27
|
+
|
|
28
|
+
If you're using a bundler (Vite, Webpack, esbuild, etc.) or modern build tools, `moduleResolution: "bundler"` is the recommended setting. For Node.js projects, you can also use `"node16"` or `"nodenext"`.
|
|
29
|
+
|
|
11
30
|
## Basic Usage
|
|
12
31
|
|
|
13
32
|
```ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { signAsync } from '@noble/ed25519';
|
|
1
|
+
import { signAsync, getPublicKeyAsync } from '@noble/ed25519';
|
|
2
2
|
import { decodeSignature, decodeBase64, decodeAddress, ensureBytes, encodeAddress, isHexString, hexToBytes, encodeSignature } from '@thru/helpers';
|
|
3
3
|
import { messageDesc, fileDesc, serviceDesc } from '@bufbuild/protobuf/codegenv2';
|
|
4
4
|
import { file_google_protobuf_timestamp, file_google_protobuf_descriptor, file_google_protobuf_duration } from '@bufbuild/protobuf/wkt';
|
|
@@ -661,6 +661,7 @@ function getEvent(ctx, eventId, options = {}) {
|
|
|
661
661
|
// thru-ts-client-sdk/modules/keys.ts
|
|
662
662
|
var keys_exports = {};
|
|
663
663
|
__export(keys_exports, {
|
|
664
|
+
fromPrivateKey: () => fromPrivateKey,
|
|
664
665
|
generateKeyPair: () => generateKeyPair
|
|
665
666
|
});
|
|
666
667
|
async function generateKeyPair() {
|
|
@@ -673,6 +674,9 @@ async function generateKeyPair() {
|
|
|
673
674
|
privateKey: account.privateKey
|
|
674
675
|
};
|
|
675
676
|
}
|
|
677
|
+
async function fromPrivateKey(privateKey) {
|
|
678
|
+
return new Uint8Array(await getPublicKeyAsync(privateKey));
|
|
679
|
+
}
|
|
676
680
|
function generateSeed() {
|
|
677
681
|
const cryptoObj = getWebCrypto();
|
|
678
682
|
const bytes = new Uint8Array(64);
|
|
@@ -840,8 +844,8 @@ async function createBuildParams(ctx, options) {
|
|
|
840
844
|
const program = resolveProgramIdentifier(options.program);
|
|
841
845
|
const header = await createTransactionHeader(ctx, options.header ?? {}, feePayerPublicKey);
|
|
842
846
|
const accounts = parseAccounts(options.accounts);
|
|
843
|
-
const context =
|
|
844
|
-
const instructionData = resolveInstructionData(options.instructionData, context);
|
|
847
|
+
const context = createInstructionContext(feePayerPublicKey, program, accounts);
|
|
848
|
+
const instructionData = await resolveInstructionData(options.instructionData, context);
|
|
845
849
|
const proofs = createProofs(options);
|
|
846
850
|
return {
|
|
847
851
|
feePayer: {
|
|
@@ -891,7 +895,7 @@ function parseAccounts(accounts) {
|
|
|
891
895
|
}
|
|
892
896
|
return result;
|
|
893
897
|
}
|
|
894
|
-
function
|
|
898
|
+
function createInstructionContext(feePayer, program, accounts) {
|
|
895
899
|
const allAccounts = [
|
|
896
900
|
feePayer,
|
|
897
901
|
program,
|
|
@@ -919,12 +923,12 @@ function createBuilderContext(feePayer, program, accounts) {
|
|
|
919
923
|
};
|
|
920
924
|
return { accounts: allAccounts, getAccountIndex };
|
|
921
925
|
}
|
|
922
|
-
function resolveInstructionData(value, context) {
|
|
926
|
+
async function resolveInstructionData(value, context) {
|
|
923
927
|
if (value === void 0) {
|
|
924
928
|
return void 0;
|
|
925
929
|
}
|
|
926
930
|
if (typeof value === "function") {
|
|
927
|
-
return value(context);
|
|
931
|
+
return await value(context);
|
|
928
932
|
}
|
|
929
933
|
if (value instanceof Uint8Array) {
|
|
930
934
|
return value;
|
|
@@ -955,6 +959,6 @@ async function fetchFinalizedSlot(ctx) {
|
|
|
955
959
|
return height.finalized;
|
|
956
960
|
}
|
|
957
961
|
|
|
958
|
-
export { CommandService, ConsensusStatus, DEFAULT_HOST, FilterParamValueSchema, FilterSchema, GetVersionRequestSchema, QueryService, StreamingService, Transaction, TransactionBuilder, accounts_exports, batchSendTransactions, blocks_exports, buildAndSignTransaction, buildTransaction, createAccount, deriveProgramAddress, events_exports, generateKeyPair, generateStateProof, getAccount, getBlock, getBlockHeight, getEvent, getRawAccount, getRawBlock, getRawTransaction, getTransaction, getTransactionStatus, height_exports, keys_exports, listAccounts, listBlocks, listTransactionsForAccount, proofs_exports, sendTransaction, streamAccountUpdates, streamBlocks, streamEvents, streamTransactions, streaming_exports, toBlockHash, toPubkey, toSignature, trackTransaction, transactions_exports };
|
|
959
|
-
//# sourceMappingURL=chunk-
|
|
960
|
-
//# sourceMappingURL=chunk-
|
|
962
|
+
export { CommandService, ConsensusStatus, DEFAULT_HOST, FilterParamValueSchema, FilterSchema, GetVersionRequestSchema, QueryService, StreamingService, Transaction, TransactionBuilder, accounts_exports, batchSendTransactions, blocks_exports, buildAndSignTransaction, buildTransaction, createAccount, deriveProgramAddress, events_exports, fromPrivateKey, generateKeyPair, generateStateProof, getAccount, getBlock, getBlockHeight, getEvent, getRawAccount, getRawBlock, getRawTransaction, getTransaction, getTransactionStatus, height_exports, keys_exports, listAccounts, listBlocks, listTransactionsForAccount, proofs_exports, sendTransaction, streamAccountUpdates, streamBlocks, streamEvents, streamTransactions, streaming_exports, toBlockHash, toPubkey, toSignature, trackTransaction, transactions_exports };
|
|
963
|
+
//# sourceMappingURL=chunk-SHMREHP5.js.map
|
|
964
|
+
//# sourceMappingURL=chunk-SHMREHP5.js.map
|