@mysten/sui 2.31.3 → 2.33.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 +16 -0
- package/dist/client/protocol-version.mjs +12 -0
- package/dist/client/protocol-version.mjs.map +1 -0
- package/dist/cryptography/signature.d.mts +8 -8
- package/dist/graphql/client.d.mts.map +1 -1
- package/dist/graphql/client.mjs +7 -4
- package/dist/graphql/client.mjs.map +1 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +2 -2
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/proto/sui/rpc/v2/ledger_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/move_package_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/name_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/signature_verification_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/state_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/subscription_service.client.d.mts +4 -4
- package/dist/grpc/transport.d.mts +5 -3
- package/dist/grpc/transport.d.mts.map +1 -1
- package/dist/grpc/transport.mjs +32 -2
- package/dist/grpc/transport.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +9 -6
- package/dist/transactions/Transaction.d.mts.map +1 -1
- package/dist/transactions/Transaction.mjs +4 -1
- package/dist/transactions/Transaction.mjs.map +1 -1
- package/dist/transactions/TransactionData.d.mts +1 -0
- package/dist/transactions/TransactionData.d.mts.map +1 -1
- package/dist/transactions/TransactionData.mjs +3 -0
- package/dist/transactions/TransactionData.mjs.map +1 -1
- package/dist/version.mjs +1 -1
- package/dist/version.mjs.map +1 -1
- package/dist/zklogin/bcs.d.mts +14 -14
- package/docs/clients/grpc.md +7 -1
- package/package.json +1 -1
- package/src/client/protocol-version.ts +11 -0
- package/src/graphql/client.ts +13 -4
- package/src/grpc/client.ts +5 -3
- package/src/grpc/transport.ts +40 -1
- package/src/transactions/Transaction.ts +4 -1
- package/src/transactions/TransactionData.ts +4 -0
- package/src/version.ts +1 -1
package/src/graphql/client.ts
CHANGED
|
@@ -5,6 +5,10 @@ import type { TypedDocumentNode } from '@graphql-typed-document-node/core';
|
|
|
5
5
|
import type { TadaDocumentNode } from 'gql.tada';
|
|
6
6
|
import type { DocumentNode } from 'graphql';
|
|
7
7
|
import { print } from 'graphql';
|
|
8
|
+
import {
|
|
9
|
+
CLIENT_PROTOCOL_VERSION_HEADER,
|
|
10
|
+
MAX_PROTOCOL_VERSION,
|
|
11
|
+
} from '../client/protocol-version.js';
|
|
8
12
|
import { BaseClient } from '../client/index.js';
|
|
9
13
|
import type { SuiClientTypes } from '../client/index.js';
|
|
10
14
|
import { GraphQLCoreClient } from './core.js';
|
|
@@ -137,12 +141,17 @@ export class SuiGraphQLClient<Queries extends Record<string, GraphQLDocument> =
|
|
|
137
141
|
async query<Result = Record<string, unknown>, Variables = Record<string, unknown>>(
|
|
138
142
|
options: GraphQLQueryOptions<Result, Variables>,
|
|
139
143
|
): Promise<GraphQLQueryResult<Result>> {
|
|
144
|
+
const headers = new Headers({
|
|
145
|
+
'Content-Type': 'application/json',
|
|
146
|
+
...this.#headers,
|
|
147
|
+
});
|
|
148
|
+
if (!headers.has(CLIENT_PROTOCOL_VERSION_HEADER)) {
|
|
149
|
+
headers.set(CLIENT_PROTOCOL_VERSION_HEADER, String(MAX_PROTOCOL_VERSION));
|
|
150
|
+
}
|
|
151
|
+
|
|
140
152
|
const res = await this.#fetch(this.#url, {
|
|
141
153
|
method: 'POST',
|
|
142
|
-
headers
|
|
143
|
-
'Content-Type': 'application/json',
|
|
144
|
-
...this.#headers,
|
|
145
|
-
},
|
|
154
|
+
headers,
|
|
146
155
|
body: JSON.stringify({
|
|
147
156
|
query:
|
|
148
157
|
typeof options.query === 'string' || options.query instanceof String
|
package/src/grpc/client.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { fromBase64, toBase64 } from '@mysten/utils';
|
|
|
18
18
|
import { NameServiceClient } from './proto/sui/rpc/v2/name_service.client.js';
|
|
19
19
|
import { ForkingServiceClient } from './proto/sui/forking/v1alpha/forking_service.client.js';
|
|
20
20
|
import type { TransactionPlugin } from '../transactions/index.js';
|
|
21
|
-
import { GrpcWebFetchTransport } from './transport.js';
|
|
21
|
+
import { GrpcWebFetchTransport, withClientProtocolVersion } from './transport.js';
|
|
22
22
|
|
|
23
23
|
interface SuiGrpcTransportOptions extends GrpcWebOptions {
|
|
24
24
|
transport?: never;
|
|
@@ -166,8 +166,10 @@ export class SuiGrpcClient extends BaseClient implements SuiClientTypes.Transpor
|
|
|
166
166
|
...transportOptions
|
|
167
167
|
} = options as SuiGrpcClientOptions & SuiGrpcTransportOptions & { transport?: RpcTransport };
|
|
168
168
|
|
|
169
|
-
//
|
|
170
|
-
const transport =
|
|
169
|
+
// Add the protocol-version default for every transport, including native gRPC.
|
|
170
|
+
const transport = withClientProtocolVersion(
|
|
171
|
+
providedTransport ?? new GrpcWebFetchTransport(transportOptions),
|
|
172
|
+
);
|
|
171
173
|
this.transactionExecutionService = new TransactionExecutionServiceClient(transport);
|
|
172
174
|
this.ledgerService = new LedgerServiceClient(transport);
|
|
173
175
|
this.stateService = new StateServiceClient(transport);
|
package/src/grpc/transport.ts
CHANGED
|
@@ -1,16 +1,23 @@
|
|
|
1
1
|
// Copyright (c) Mysten Labs, Inc.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
+
import type { GrpcWebOptions } from '@protobuf-ts/grpcweb-transport';
|
|
4
5
|
import { GrpcStatusCode } from '@protobuf-ts/grpcweb-transport';
|
|
5
6
|
import { GrpcWebFetchTransport as UpstreamGrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport';
|
|
6
7
|
import type {
|
|
7
8
|
MethodInfo,
|
|
8
9
|
RpcOptions,
|
|
10
|
+
RpcTransport,
|
|
9
11
|
ServerStreamingCall,
|
|
10
12
|
UnaryCall,
|
|
11
13
|
} from '@protobuf-ts/runtime-rpc';
|
|
12
14
|
import { RpcError } from '@protobuf-ts/runtime-rpc';
|
|
13
15
|
|
|
16
|
+
import {
|
|
17
|
+
CLIENT_PROTOCOL_VERSION_HEADER,
|
|
18
|
+
MAX_PROTOCOL_VERSION,
|
|
19
|
+
} from '../client/protocol-version.js';
|
|
20
|
+
|
|
14
21
|
// A failed call rejects four promises with the same error, so it is only decoded once. Registered
|
|
15
22
|
// globally so another installed copy of this package sees the same marker.
|
|
16
23
|
const MESSAGE_DECODED = Symbol.for('@mysten/sui/grpc/decoded-status-message');
|
|
@@ -126,12 +133,24 @@ function normalizeRejections(promises: Promise<unknown>[], signal: AbortSignal |
|
|
|
126
133
|
|
|
127
134
|
/**
|
|
128
135
|
* `GrpcWebFetchTransport` from `@protobuf-ts/grpcweb-transport`, subclassed to decode status
|
|
129
|
-
* messages
|
|
136
|
+
* messages, to code an aborted call from its reason rather than as `INTERNAL`, and to send the
|
|
137
|
+
* `x-sui-client-protocol-version` header.
|
|
130
138
|
*
|
|
131
139
|
* `SuiGrpcClient` builds one by default. A transport imported from `@protobuf-ts/grpcweb-transport`
|
|
132
140
|
* keeps that package's behaviour.
|
|
133
141
|
*/
|
|
134
142
|
export class GrpcWebFetchTransport extends UpstreamGrpcWebFetchTransport {
|
|
143
|
+
constructor(options: GrpcWebOptions) {
|
|
144
|
+
// Lets the server avoid sending types this SDK cannot decode. Caller-supplied `meta` wins.
|
|
145
|
+
super({
|
|
146
|
+
...options,
|
|
147
|
+
meta: {
|
|
148
|
+
[CLIENT_PROTOCOL_VERSION_HEADER]: String(MAX_PROTOCOL_VERSION),
|
|
149
|
+
...options.meta,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
|
|
135
154
|
override unary<I extends object, O extends object>(
|
|
136
155
|
method: MethodInfo<I, O>,
|
|
137
156
|
input: I,
|
|
@@ -158,3 +177,23 @@ export class GrpcWebFetchTransport extends UpstreamGrpcWebFetchTransport {
|
|
|
158
177
|
return call;
|
|
159
178
|
}
|
|
160
179
|
}
|
|
180
|
+
|
|
181
|
+
/** Adds SDK metadata without mutating the caller's transport or its default options. */
|
|
182
|
+
export function withClientProtocolVersion(transport: RpcTransport): RpcTransport {
|
|
183
|
+
return {
|
|
184
|
+
mergeOptions(options) {
|
|
185
|
+
const merged = transport.mergeOptions(options);
|
|
186
|
+
return {
|
|
187
|
+
...merged,
|
|
188
|
+
meta: {
|
|
189
|
+
[CLIENT_PROTOCOL_VERSION_HEADER]: String(MAX_PROTOCOL_VERSION),
|
|
190
|
+
...merged.meta,
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
},
|
|
194
|
+
unary: transport.unary.bind(transport),
|
|
195
|
+
serverStreaming: transport.serverStreaming.bind(transport),
|
|
196
|
+
clientStreaming: transport.clientStreaming.bind(transport),
|
|
197
|
+
duplex: transport.duplex.bind(transport),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -193,6 +193,9 @@ export class Transaction {
|
|
|
193
193
|
* - A string returned from `Transaction#serialize`. The serialized format must be compatible, or it will throw an error.
|
|
194
194
|
* - A byte array (or base64-encoded bytes) containing BCS transaction data.
|
|
195
195
|
*
|
|
196
|
+
* It can also copy an existing `Transaction` or `TransactionDataBuilder` instance. The data is
|
|
197
|
+
* copied, so changes to the new transaction do not affect the original.
|
|
198
|
+
*
|
|
196
199
|
* When copying an in-memory transaction that uses custom intents, pass resolvers for those intents
|
|
197
200
|
* via `options.intentResolvers` so the copy can be created synchronously without first awaiting
|
|
198
201
|
* `prepareForSerialization`. Built-in intents (such as `CoinWithBalance`) are handled automatically.
|
|
@@ -203,7 +206,7 @@ export class Transaction {
|
|
|
203
206
|
) {
|
|
204
207
|
const newTransaction = new Transaction();
|
|
205
208
|
|
|
206
|
-
if (
|
|
209
|
+
if (typeof transaction === 'object' && 'getData' in transaction) {
|
|
207
210
|
newTransaction.#data = TransactionDataBuilder.restore(
|
|
208
211
|
transaction.getData() as InferInput<typeof SerializedTransactionDataV2Schema>,
|
|
209
212
|
);
|
|
@@ -434,6 +434,10 @@ export class TransactionDataBuilder implements TransactionData {
|
|
|
434
434
|
return parse(TransactionDataSchema, this);
|
|
435
435
|
}
|
|
436
436
|
|
|
437
|
+
getData(): TransactionData {
|
|
438
|
+
return this.snapshot();
|
|
439
|
+
}
|
|
440
|
+
|
|
437
441
|
shallowClone() {
|
|
438
442
|
return new TransactionDataBuilder({
|
|
439
443
|
version: this.version,
|
package/src/version.ts
CHANGED