@mysten/sui 2.28.0 → 2.29.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 +18 -0
- package/dist/bcs/bcs.d.mts +6 -6
- package/dist/bcs/index.d.mts +36 -36
- package/dist/cryptography/signature.d.mts +6 -6
- package/dist/grpc/client.d.mts +1 -1
- package/dist/grpc/client.d.mts.map +1 -1
- package/dist/grpc/client.mjs +3 -5
- package/dist/grpc/client.mjs.map +1 -1
- package/dist/grpc/core.d.mts.map +1 -1
- package/dist/grpc/core.mjs +10 -10
- package/dist/grpc/core.mjs.map +1 -1
- package/dist/grpc/index.d.mts +4 -3
- package/dist/grpc/index.mjs +4 -2
- package/dist/grpc/proto/sui/forking/v1alpha/forking_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/subscription_service.client.d.mts +4 -4
- package/dist/grpc/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
- package/dist/grpc/transport.d.mts +18 -0
- package/dist/grpc/transport.d.mts.map +1 -0
- package/dist/grpc/transport.mjs +97 -0
- package/dist/grpc/transport.mjs.map +1 -0
- package/dist/transactions/Transaction.d.mts +9 -9
- package/dist/transactions/data/internal.d.mts +127 -127
- package/dist/transactions/data/v1.d.mts +239 -239
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/transactions/data/v2.d.mts.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 +31 -7
- package/package.json +1 -1
- package/src/grpc/client.ts +12 -4
- package/src/grpc/core.ts +18 -14
- package/src/grpc/index.ts +7 -3
- package/src/grpc/transport.ts +160 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { RpcError } from "@protobuf-ts/runtime-rpc";
|
|
2
|
+
import { GrpcStatusCode, GrpcWebFetchTransport } from "@protobuf-ts/grpcweb-transport";
|
|
3
|
+
|
|
4
|
+
//#region src/grpc/transport.ts
|
|
5
|
+
const MESSAGE_DECODED = Symbol.for("@mysten/sui/grpc/decoded-status-message");
|
|
6
|
+
function decodeGrpcStatusMessage(message) {
|
|
7
|
+
if (!message.includes("%")) return message;
|
|
8
|
+
try {
|
|
9
|
+
return decodeURIComponent(message);
|
|
10
|
+
} catch {
|
|
11
|
+
return message;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function markStatusMessageRead(error) {
|
|
15
|
+
if (MESSAGE_DECODED in error) return false;
|
|
16
|
+
Object.defineProperty(error, MESSAGE_DECODED, {
|
|
17
|
+
value: true,
|
|
18
|
+
configurable: true
|
|
19
|
+
});
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
function decodeStatusMessageOnce(error) {
|
|
23
|
+
if (markStatusMessageRead(error)) error.message = decodeGrpcStatusMessage(error.message);
|
|
24
|
+
}
|
|
25
|
+
/** Whether this package's transport decoded the error's status text. */
|
|
26
|
+
function hasDecodedStatusMessage(error) {
|
|
27
|
+
return MESSAGE_DECODED in error;
|
|
28
|
+
}
|
|
29
|
+
function readProperty(value, key) {
|
|
30
|
+
if (typeof value !== "object" || value === null) return void 0;
|
|
31
|
+
try {
|
|
32
|
+
return value[key];
|
|
33
|
+
} catch {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function abortStatus(reason) {
|
|
38
|
+
const code = readProperty(reason, "code");
|
|
39
|
+
if (typeof code === "string" && typeof GrpcStatusCode[code] === "number") return code;
|
|
40
|
+
return readProperty(reason, "name") === "TimeoutError" ? GrpcStatusCode[GrpcStatusCode.DEADLINE_EXCEEDED] : GrpcStatusCode[GrpcStatusCode.CANCELLED];
|
|
41
|
+
}
|
|
42
|
+
function isAbortReasonText(message, reason) {
|
|
43
|
+
if (typeof reason === "string") return message === reason;
|
|
44
|
+
const reasonMessage = readProperty(reason, "message");
|
|
45
|
+
return typeof reasonMessage === "string" && message === reasonMessage;
|
|
46
|
+
}
|
|
47
|
+
function normalizeGrpcError(error, signal) {
|
|
48
|
+
try {
|
|
49
|
+
normalize(error, signal);
|
|
50
|
+
} catch {}
|
|
51
|
+
}
|
|
52
|
+
function normalize(error, signal) {
|
|
53
|
+
if (!(error instanceof RpcError)) return;
|
|
54
|
+
if (signal?.aborted && (error.code === GrpcStatusCode[GrpcStatusCode.INTERNAL] || error.code === GrpcStatusCode[GrpcStatusCode.CANCELLED])) {
|
|
55
|
+
error.code = abortStatus(signal.reason);
|
|
56
|
+
if (isAbortReasonText(error.message, signal.reason)) markStatusMessageRead(error);
|
|
57
|
+
else decodeStatusMessageOnce(error);
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
decodeStatusMessageOnce(error);
|
|
61
|
+
}
|
|
62
|
+
function normalizeRejections(promises, signal) {
|
|
63
|
+
for (const promise of promises) promise.then(void 0, (error) => normalizeGrpcError(error, signal));
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* `GrpcWebFetchTransport` from `@protobuf-ts/grpcweb-transport`, subclassed to decode status
|
|
67
|
+
* messages and to code an aborted call from its reason rather than as `INTERNAL`.
|
|
68
|
+
*
|
|
69
|
+
* `SuiGrpcClient` builds one by default. A transport imported from `@protobuf-ts/grpcweb-transport`
|
|
70
|
+
* keeps that package's behaviour.
|
|
71
|
+
*/
|
|
72
|
+
var GrpcWebFetchTransport$1 = class extends GrpcWebFetchTransport {
|
|
73
|
+
unary(method, input, options) {
|
|
74
|
+
const call = super.unary(method, input, options);
|
|
75
|
+
normalizeRejections([
|
|
76
|
+
call.headers,
|
|
77
|
+
call.response,
|
|
78
|
+
call.status,
|
|
79
|
+
call.trailers
|
|
80
|
+
], options.abort);
|
|
81
|
+
return call;
|
|
82
|
+
}
|
|
83
|
+
serverStreaming(method, input, options) {
|
|
84
|
+
const call = super.serverStreaming(method, input, options);
|
|
85
|
+
call.responses.onError((error) => normalizeGrpcError(error, options.abort));
|
|
86
|
+
normalizeRejections([
|
|
87
|
+
call.headers,
|
|
88
|
+
call.status,
|
|
89
|
+
call.trailers
|
|
90
|
+
], options.abort);
|
|
91
|
+
return call;
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//#endregion
|
|
96
|
+
export { GrpcWebFetchTransport$1 as GrpcWebFetchTransport, hasDecodedStatusMessage };
|
|
97
|
+
//# sourceMappingURL=transport.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.mjs","names":["GrpcWebFetchTransport","UpstreamGrpcWebFetchTransport"],"sources":["../../src/grpc/transport.ts"],"sourcesContent":["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { GrpcStatusCode } from '@protobuf-ts/grpcweb-transport';\nimport { GrpcWebFetchTransport as UpstreamGrpcWebFetchTransport } from '@protobuf-ts/grpcweb-transport';\nimport type {\n\tMethodInfo,\n\tRpcOptions,\n\tServerStreamingCall,\n\tUnaryCall,\n} from '@protobuf-ts/runtime-rpc';\nimport { RpcError } from '@protobuf-ts/runtime-rpc';\n\n// A failed call rejects four promises with the same error, so it is only decoded once. Registered\n// globally so another installed copy of this package sees the same marker.\nconst MESSAGE_DECODED = Symbol.for('@mysten/sui/grpc/decoded-status-message');\n\n// `grpc-message` is percent-encoded on the wire and the upstream transport does not decode it:\n// https://github.com/timostamm/protobuf-ts/pull/739\nfunction decodeGrpcStatusMessage(message: string): string {\n\tif (!message.includes('%')) return message;\n\n\ttry {\n\t\treturn decodeURIComponent(message);\n\t} catch {\n\t\treturn message;\n\t}\n}\n\nfunction markStatusMessageRead(error: RpcError): boolean {\n\tif (MESSAGE_DECODED in error) return false;\n\tObject.defineProperty(error, MESSAGE_DECODED, { value: true, configurable: true });\n\n\treturn true;\n}\n\nfunction decodeStatusMessageOnce(error: RpcError): void {\n\tif (markStatusMessageRead(error)) error.message = decodeGrpcStatusMessage(error.message);\n}\n\n/** Whether this package's transport decoded the error's status text. */\nexport function hasDecodedStatusMessage(error: object): boolean {\n\treturn MESSAGE_DECODED in error;\n}\n\n// An abort reason is arbitrary, and reading a property on it runs code the caller wrote. A read\n// that throws counts as absent, so one bad accessor does not decide the status.\nfunction readProperty(value: unknown, key: 'code' | 'name' | 'message'): unknown {\n\tif (typeof value !== 'object' || value === null) return undefined;\n\n\ttry {\n\t\treturn (value as Record<string, unknown>)[key];\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\n// The reason is read by shape, since another copy of runtime-rpc or another realm fails\n// `instanceof`. `AbortSignal.timeout` aborts with a `TimeoutError`.\nfunction abortStatus(reason: unknown): string {\n\tconst code = readProperty(reason, 'code');\n\n\t// A status name maps to a number; `in` would also match the enum's reverse mapping.\n\tif (\n\t\ttypeof code === 'string' &&\n\t\ttypeof GrpcStatusCode[code as keyof typeof GrpcStatusCode] === 'number'\n\t) {\n\t\treturn code;\n\t}\n\n\treturn readProperty(reason, 'name') === 'TimeoutError'\n\t\t? GrpcStatusCode[GrpcStatusCode.DEADLINE_EXCEEDED]\n\t\t: GrpcStatusCode[GrpcStatusCode.CANCELLED];\n}\n\n// The transport reuses the abort reason's message, so matching it says the text is local. A fetch\n// that substitutes its own error (node-fetch) gives text of its own, which holds nothing to decode.\n// The reason is never coerced: a symbol or a throwing hook would throw here.\nfunction isAbortReasonText(message: string, reason: unknown): boolean {\n\tif (typeof reason === 'string') return message === reason;\n\n\tconst reasonMessage = readProperty(reason, 'message');\n\n\treturn typeof reasonMessage === 'string' && message === reasonMessage;\n}\n\n// Rewritten in place, so every promise a call rejects surfaces the same error. Only the two codes\n// upstream uses for an abort are re-coded; a failure that raced the abort is relabelled with it.\nfunction normalizeGrpcError(error: unknown, signal: AbortSignal | undefined): void {\n\ttry {\n\t\tnormalize(error, signal);\n\t} catch {\n\t\t// Never an unhandled rejection from a discarded handler: the call reports what it was going\n\t\t// to report.\n\t}\n}\n\nfunction normalize(error: unknown, signal: AbortSignal | undefined): void {\n\tif (!(error instanceof RpcError)) return;\n\n\tif (\n\t\tsignal?.aborted &&\n\t\t(error.code === GrpcStatusCode[GrpcStatusCode.INTERNAL] ||\n\t\t\terror.code === GrpcStatusCode[GrpcStatusCode.CANCELLED])\n\t) {\n\t\terror.code = abortStatus(signal.reason);\n\n\t\t// Text the abort reason supplied is local and holds nothing to decode; anything else came off\n\t\t// the wire, even though the abort is what the caller sees. Settled here for the other promises\n\t\t// the call rejects, which no longer match the codes above.\n\t\tif (isAbortReasonText(error.message, signal.reason)) markStatusMessageRead(error);\n\t\telse decodeStatusMessageOnce(error);\n\n\t\treturn;\n\t}\n\n\tdecodeStatusMessageOnce(error);\n}\n\nfunction normalizeRejections(promises: Promise<unknown>[], signal: AbortSignal | undefined) {\n\tfor (const promise of promises) {\n\t\t// Registered before the call is returned, so it runs before the consumer's own await.\n\t\tpromise.then(undefined, (error: unknown) => normalizeGrpcError(error, signal));\n\t}\n}\n\n/**\n * `GrpcWebFetchTransport` from `@protobuf-ts/grpcweb-transport`, subclassed to decode status\n * messages and to code an aborted call from its reason rather than as `INTERNAL`.\n *\n * `SuiGrpcClient` builds one by default. A transport imported from `@protobuf-ts/grpcweb-transport`\n * keeps that package's behaviour.\n */\nexport class GrpcWebFetchTransport extends UpstreamGrpcWebFetchTransport {\n\toverride unary<I extends object, O extends object>(\n\t\tmethod: MethodInfo<I, O>,\n\t\tinput: I,\n\t\toptions: RpcOptions,\n\t): UnaryCall<I, O> {\n\t\tconst call = super.unary(method, input, options);\n\n\t\tnormalizeRejections([call.headers, call.response, call.status, call.trailers], options.abort);\n\n\t\treturn call;\n\t}\n\n\toverride serverStreaming<I extends object, O extends object>(\n\t\tmethod: MethodInfo<I, O>,\n\t\tinput: I,\n\t\toptions: RpcOptions,\n\t): ServerStreamingCall<I, O> {\n\t\tconst call = super.serverStreaming(method, input, options);\n\n\t\t// A finite stream is often read through `responses` without awaiting `status`.\n\t\tcall.responses.onError((error) => normalizeGrpcError(error, options.abort));\n\t\tnormalizeRejections([call.headers, call.status, call.trailers], options.abort);\n\n\t\treturn call;\n\t}\n}\n"],"mappings":";;;;AAeA,MAAM,kBAAkB,OAAO,IAAI,0CAA0C;AAI7E,SAAS,wBAAwB,SAAyB;AACzD,KAAI,CAAC,QAAQ,SAAS,IAAI,CAAE,QAAO;AAEnC,KAAI;AACH,SAAO,mBAAmB,QAAQ;SAC3B;AACP,SAAO;;;AAIT,SAAS,sBAAsB,OAA0B;AACxD,KAAI,mBAAmB,MAAO,QAAO;AACrC,QAAO,eAAe,OAAO,iBAAiB;EAAE,OAAO;EAAM,cAAc;EAAM,CAAC;AAElF,QAAO;;AAGR,SAAS,wBAAwB,OAAuB;AACvD,KAAI,sBAAsB,MAAM,CAAE,OAAM,UAAU,wBAAwB,MAAM,QAAQ;;;AAIzF,SAAgB,wBAAwB,OAAwB;AAC/D,QAAO,mBAAmB;;AAK3B,SAAS,aAAa,OAAgB,KAA2C;AAChF,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;AAExD,KAAI;AACH,SAAQ,MAAkC;SACnC;AACP;;;AAMF,SAAS,YAAY,QAAyB;CAC7C,MAAM,OAAO,aAAa,QAAQ,OAAO;AAGzC,KACC,OAAO,SAAS,YAChB,OAAO,eAAe,UAAyC,SAE/D,QAAO;AAGR,QAAO,aAAa,QAAQ,OAAO,KAAK,iBACrC,eAAe,eAAe,qBAC9B,eAAe,eAAe;;AAMlC,SAAS,kBAAkB,SAAiB,QAA0B;AACrE,KAAI,OAAO,WAAW,SAAU,QAAO,YAAY;CAEnD,MAAM,gBAAgB,aAAa,QAAQ,UAAU;AAErD,QAAO,OAAO,kBAAkB,YAAY,YAAY;;AAKzD,SAAS,mBAAmB,OAAgB,QAAuC;AAClF,KAAI;AACH,YAAU,OAAO,OAAO;SACjB;;AAMT,SAAS,UAAU,OAAgB,QAAuC;AACzE,KAAI,EAAE,iBAAiB,UAAW;AAElC,KACC,QAAQ,YACP,MAAM,SAAS,eAAe,eAAe,aAC7C,MAAM,SAAS,eAAe,eAAe,aAC7C;AACD,QAAM,OAAO,YAAY,OAAO,OAAO;AAKvC,MAAI,kBAAkB,MAAM,SAAS,OAAO,OAAO,CAAE,uBAAsB,MAAM;MAC5E,yBAAwB,MAAM;AAEnC;;AAGD,yBAAwB,MAAM;;AAG/B,SAAS,oBAAoB,UAA8B,QAAiC;AAC3F,MAAK,MAAM,WAAW,SAErB,SAAQ,KAAK,SAAY,UAAmB,mBAAmB,OAAO,OAAO,CAAC;;;;;;;;;AAWhF,IAAaA,0BAAb,cAA2CC,sBAA8B;CACxE,AAAS,MACR,QACA,OACA,SACkB;EAClB,MAAM,OAAO,MAAM,MAAM,QAAQ,OAAO,QAAQ;AAEhD,sBAAoB;GAAC,KAAK;GAAS,KAAK;GAAU,KAAK;GAAQ,KAAK;GAAS,EAAE,QAAQ,MAAM;AAE7F,SAAO;;CAGR,AAAS,gBACR,QACA,OACA,SAC4B;EAC5B,MAAM,OAAO,MAAM,gBAAgB,QAAQ,OAAO,QAAQ;AAG1D,OAAK,UAAU,SAAS,UAAU,mBAAmB,OAAO,QAAQ,MAAM,CAAC;AAC3E,sBAAoB;GAAC,KAAK;GAAS,KAAK;GAAQ,KAAK;GAAS,EAAE,QAAQ,MAAM;AAE9E,SAAO"}
|
|
@@ -8,7 +8,7 @@ import { createPure } from "./pure.mjs";
|
|
|
8
8
|
import { SignatureWithBytes, Signer } from "../cryptography/keypair.mjs";
|
|
9
9
|
import "../cryptography/index.mjs";
|
|
10
10
|
import { ClientWithCoreApi } from "../client/core.mjs";
|
|
11
|
-
import * as
|
|
11
|
+
import * as _mysten_bcs1391 from "@mysten/bcs";
|
|
12
12
|
import { SerializedBcs } from "@mysten/bcs";
|
|
13
13
|
import { InferInput } from "valibot";
|
|
14
14
|
|
|
@@ -91,7 +91,7 @@ declare class Transaction {
|
|
|
91
91
|
getData(): {
|
|
92
92
|
version: 2;
|
|
93
93
|
sender?: string | null | undefined;
|
|
94
|
-
expiration?:
|
|
94
|
+
expiration?: _mysten_bcs1391.EnumOutputShapeWithKeys<{
|
|
95
95
|
None: true;
|
|
96
96
|
Epoch: string | number;
|
|
97
97
|
ValidDuring: {
|
|
@@ -114,7 +114,7 @@ declare class Transaction {
|
|
|
114
114
|
chain: string;
|
|
115
115
|
nonce: number;
|
|
116
116
|
};
|
|
117
|
-
}, "
|
|
117
|
+
}, "None" | "Epoch" | "ValidDuring" | "Validity"> | null | undefined;
|
|
118
118
|
gasData: {
|
|
119
119
|
budget: string | number | null;
|
|
120
120
|
price: string | number | null;
|
|
@@ -125,8 +125,8 @@ declare class Transaction {
|
|
|
125
125
|
digest: string;
|
|
126
126
|
}[] | null;
|
|
127
127
|
};
|
|
128
|
-
inputs:
|
|
129
|
-
Object:
|
|
128
|
+
inputs: _mysten_bcs1391.EnumOutputShapeWithKeys<{
|
|
129
|
+
Object: _mysten_bcs1391.EnumOutputShapeWithKeys<{
|
|
130
130
|
ImmOrOwnedObject: {
|
|
131
131
|
objectId: string;
|
|
132
132
|
version: string | number;
|
|
@@ -142,7 +142,7 @@ declare class Transaction {
|
|
|
142
142
|
version: string | number;
|
|
143
143
|
digest: string;
|
|
144
144
|
};
|
|
145
|
-
}, "
|
|
145
|
+
}, "ImmOrOwnedObject" | "SharedObject" | "Receiving">;
|
|
146
146
|
Pure: {
|
|
147
147
|
bytes: string;
|
|
148
148
|
};
|
|
@@ -165,13 +165,13 @@ declare class Transaction {
|
|
|
165
165
|
Balance: string;
|
|
166
166
|
$kind: "Balance";
|
|
167
167
|
};
|
|
168
|
-
withdrawFrom:
|
|
168
|
+
withdrawFrom: _mysten_bcs1391.EnumOutputShapeWithKeys<{
|
|
169
169
|
Sender: true;
|
|
170
170
|
Sponsor: true;
|
|
171
171
|
}, "Sender" | "Sponsor">;
|
|
172
172
|
};
|
|
173
|
-
}, "
|
|
174
|
-
commands:
|
|
173
|
+
}, "Pure" | "Object" | "FundsWithdrawal" | "UnresolvedPure" | "UnresolvedObject">[];
|
|
174
|
+
commands: _mysten_bcs1391.EnumOutputShapeWithKeys<{
|
|
175
175
|
MoveCall: {
|
|
176
176
|
package: string;
|
|
177
177
|
module: string;
|