@mysten/sui 1.6.0 → 1.7.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 +19 -0
- package/dist/cjs/transactions/Arguments.d.ts +26 -4
- package/dist/cjs/transactions/Arguments.js +4 -1
- package/dist/cjs/transactions/Arguments.js.map +2 -2
- package/dist/cjs/transactions/Transaction.d.ts +28 -4
- package/dist/cjs/transactions/Transaction.js +53 -25
- package/dist/cjs/transactions/Transaction.js.map +2 -2
- package/dist/cjs/transactions/executor/parallel.d.ts +2 -2
- package/dist/cjs/transactions/executor/parallel.js +5 -6
- package/dist/cjs/transactions/executor/parallel.js.map +2 -2
- package/dist/cjs/transactions/executor/serial.d.ts +5 -3
- package/dist/cjs/transactions/executor/serial.js +9 -3
- package/dist/cjs/transactions/executor/serial.js.map +2 -2
- package/dist/cjs/transactions/object.d.ts +8 -0
- package/dist/cjs/transactions/object.js +34 -0
- package/dist/cjs/transactions/object.js.map +7 -0
- package/dist/cjs/verify/verify.d.ts +6 -2
- package/dist/cjs/verify/verify.js +4 -4
- package/dist/cjs/verify/verify.js.map +2 -2
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/zklogin/publickey.js.map +2 -2
- package/dist/esm/transactions/Arguments.d.ts +26 -4
- package/dist/esm/transactions/Arguments.js +4 -1
- package/dist/esm/transactions/Arguments.js.map +2 -2
- package/dist/esm/transactions/Transaction.d.ts +28 -4
- package/dist/esm/transactions/Transaction.js +53 -25
- package/dist/esm/transactions/Transaction.js.map +2 -2
- package/dist/esm/transactions/executor/parallel.d.ts +2 -2
- package/dist/esm/transactions/executor/parallel.js +5 -6
- package/dist/esm/transactions/executor/parallel.js.map +2 -2
- package/dist/esm/transactions/executor/serial.d.ts +5 -3
- package/dist/esm/transactions/executor/serial.js +9 -3
- package/dist/esm/transactions/executor/serial.js.map +2 -2
- package/dist/esm/transactions/object.d.ts +8 -0
- package/dist/esm/transactions/object.js +14 -0
- package/dist/esm/transactions/object.js.map +7 -0
- package/dist/esm/verify/verify.d.ts +6 -2
- package/dist/esm/verify/verify.js +4 -4
- package/dist/esm/verify/verify.js.map +2 -2
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/zklogin/publickey.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/transactions/Arguments.ts +4 -1
- package/src/transactions/Transaction.ts +71 -28
- package/src/transactions/executor/parallel.ts +10 -7
- package/src/transactions/executor/serial.ts +12 -2
- package/src/transactions/object.ts +17 -0
- package/src/verify/verify.ts +7 -3
- package/src/version.ts +1 -1
- package/src/zklogin/publickey.ts +1 -0
|
@@ -22,6 +22,7 @@ import type {
|
|
|
22
22
|
TransactionPlugin,
|
|
23
23
|
} from './json-rpc-resolver.js';
|
|
24
24
|
import { resolveTransactionData } from './json-rpc-resolver.js';
|
|
25
|
+
import { createObjectMethods } from './object.js';
|
|
25
26
|
import { createPure } from './pure.js';
|
|
26
27
|
import { TransactionDataBuilder } from './TransactionData.js';
|
|
27
28
|
import { getIdFromCallArg } from './utils.js';
|
|
@@ -98,12 +99,37 @@ export function isTransaction(obj: unknown): obj is Transaction {
|
|
|
98
99
|
|
|
99
100
|
export type TransactionObjectInput = string | CallArg | TransactionObjectArgument;
|
|
100
101
|
|
|
102
|
+
const modulePluginRegistry = {
|
|
103
|
+
buildPlugins: [] as TransactionPlugin[],
|
|
104
|
+
serializationPlugins: [] as TransactionPlugin[],
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const TRANSACTION_REGISTRY_KEY = Symbol.for('@mysten/transaction/registry');
|
|
108
|
+
function getGlobalPluginRegistry() {
|
|
109
|
+
try {
|
|
110
|
+
const target = globalThis as {
|
|
111
|
+
[TRANSACTION_REGISTRY_KEY]?: {
|
|
112
|
+
buildPlugins: TransactionPlugin[];
|
|
113
|
+
serializationPlugins: TransactionPlugin[];
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
if (!target[TRANSACTION_REGISTRY_KEY]) {
|
|
118
|
+
target[TRANSACTION_REGISTRY_KEY] = modulePluginRegistry;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return target[TRANSACTION_REGISTRY_KEY];
|
|
122
|
+
} catch (e) {
|
|
123
|
+
return modulePluginRegistry;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
101
127
|
/**
|
|
102
128
|
* Transaction Builder
|
|
103
129
|
*/
|
|
104
130
|
export class Transaction {
|
|
105
|
-
#serializationPlugins: TransactionPlugin[]
|
|
106
|
-
#buildPlugins: TransactionPlugin[]
|
|
131
|
+
#serializationPlugins: TransactionPlugin[];
|
|
132
|
+
#buildPlugins: TransactionPlugin[];
|
|
107
133
|
#intentResolvers = new Map<string, TransactionPlugin>();
|
|
108
134
|
|
|
109
135
|
/**
|
|
@@ -142,6 +168,14 @@ export class Transaction {
|
|
|
142
168
|
return newTransaction;
|
|
143
169
|
}
|
|
144
170
|
|
|
171
|
+
static registerGlobalSerializationPlugin(step: TransactionPlugin) {
|
|
172
|
+
getGlobalPluginRegistry().serializationPlugins.push(step);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
static registerGlobalBuildPlugin(step: TransactionPlugin) {
|
|
176
|
+
getGlobalPluginRegistry().buildPlugins.push(step);
|
|
177
|
+
}
|
|
178
|
+
|
|
145
179
|
addSerializationPlugin(step: TransactionPlugin) {
|
|
146
180
|
this.#serializationPlugins.push(step);
|
|
147
181
|
}
|
|
@@ -241,7 +275,10 @@ export class Transaction {
|
|
|
241
275
|
}
|
|
242
276
|
|
|
243
277
|
constructor() {
|
|
278
|
+
const globalPlugins = getGlobalPluginRegistry();
|
|
244
279
|
this.#data = new TransactionDataBuilder();
|
|
280
|
+
this.#buildPlugins = [...globalPlugins.buildPlugins];
|
|
281
|
+
this.#serializationPlugins = [...globalPlugins.serializationPlugins];
|
|
245
282
|
}
|
|
246
283
|
|
|
247
284
|
/** Returns an argument for the gas coin, to be used in a transaction. */
|
|
@@ -252,37 +289,43 @@ export class Transaction {
|
|
|
252
289
|
/**
|
|
253
290
|
* Add a new object input to the transaction.
|
|
254
291
|
*/
|
|
255
|
-
object
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
292
|
+
object = createObjectMethods(
|
|
293
|
+
(value: TransactionObjectInput): { $kind: 'Input'; Input: number; type?: 'object' } => {
|
|
294
|
+
if (typeof value === 'function') {
|
|
295
|
+
return this.object(value(this));
|
|
296
|
+
}
|
|
259
297
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
298
|
+
if (typeof value === 'object' && is(Argument, value)) {
|
|
299
|
+
return value as { $kind: 'Input'; Input: number; type?: 'object' };
|
|
300
|
+
}
|
|
263
301
|
|
|
264
|
-
|
|
302
|
+
const id = getIdFromCallArg(value);
|
|
265
303
|
|
|
266
|
-
|
|
304
|
+
const inserted = this.#data.inputs.find((i) => id === getIdFromCallArg(i));
|
|
267
305
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
306
|
+
// Upgrade shared object inputs to mutable if needed:
|
|
307
|
+
if (
|
|
308
|
+
inserted?.Object?.SharedObject &&
|
|
309
|
+
typeof value === 'object' &&
|
|
310
|
+
value.Object?.SharedObject
|
|
311
|
+
) {
|
|
312
|
+
inserted.Object.SharedObject.mutable =
|
|
313
|
+
inserted.Object.SharedObject.mutable || value.Object.SharedObject.mutable;
|
|
314
|
+
}
|
|
273
315
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
316
|
+
return inserted
|
|
317
|
+
? { $kind: 'Input', Input: this.#data.inputs.indexOf(inserted), type: 'object' }
|
|
318
|
+
: this.#data.addInput(
|
|
319
|
+
'object',
|
|
320
|
+
typeof value === 'string'
|
|
321
|
+
? {
|
|
322
|
+
$kind: 'UnresolvedObject',
|
|
323
|
+
UnresolvedObject: { objectId: normalizeSuiAddress(value) },
|
|
324
|
+
}
|
|
325
|
+
: value,
|
|
326
|
+
);
|
|
327
|
+
},
|
|
328
|
+
);
|
|
286
329
|
|
|
287
330
|
/**
|
|
288
331
|
* Add a new object input to the transaction using the fully-resolved object reference.
|
|
@@ -5,7 +5,7 @@ import { toB64 } from '@mysten/bcs';
|
|
|
5
5
|
|
|
6
6
|
import { bcs } from '../../bcs/index.js';
|
|
7
7
|
import type { SuiObjectRef } from '../../bcs/types.js';
|
|
8
|
-
import type { SuiClient } from '../../client/index.js';
|
|
8
|
+
import type { SuiClient, SuiTransactionBlockResponseOptions } from '../../client/index.js';
|
|
9
9
|
import type { Signer } from '../../cryptography/index.js';
|
|
10
10
|
import type { ObjectCacheOptions } from '../ObjectCache.js';
|
|
11
11
|
import { Transaction } from '../Transaction.js';
|
|
@@ -104,7 +104,7 @@ export class ParallelTransactionExecutor {
|
|
|
104
104
|
await this.#updateCache(() => this.#waitForLastDigest());
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
async executeTransaction(transaction: Transaction) {
|
|
107
|
+
async executeTransaction(transaction: Transaction, options?: SuiTransactionBlockResponseOptions) {
|
|
108
108
|
const { promise, resolve, reject } = promiseWithResolvers<{
|
|
109
109
|
digest: string;
|
|
110
110
|
effects: string;
|
|
@@ -113,7 +113,7 @@ export class ParallelTransactionExecutor {
|
|
|
113
113
|
|
|
114
114
|
const execute = () => {
|
|
115
115
|
this.#executeQueue.runTask(() => {
|
|
116
|
-
const promise = this.#execute(transaction, usedObjects);
|
|
116
|
+
const promise = this.#execute(transaction, usedObjects, options);
|
|
117
117
|
|
|
118
118
|
return promise.then(resolve, reject);
|
|
119
119
|
});
|
|
@@ -174,7 +174,11 @@ export class ParallelTransactionExecutor {
|
|
|
174
174
|
return usedObjects;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
async #execute(
|
|
177
|
+
async #execute(
|
|
178
|
+
transaction: Transaction,
|
|
179
|
+
usedObjects: Set<string>,
|
|
180
|
+
options?: SuiTransactionBlockResponseOptions,
|
|
181
|
+
) {
|
|
178
182
|
let gasCoin!: CoinWithBalance;
|
|
179
183
|
try {
|
|
180
184
|
transaction.setSenderIfNotSet(this.#signer.toSuiAddress());
|
|
@@ -186,9 +190,7 @@ export class ParallelTransactionExecutor {
|
|
|
186
190
|
transaction.setGasPrice(await this.#getGasPrice());
|
|
187
191
|
}
|
|
188
192
|
|
|
189
|
-
|
|
190
|
-
transaction.setGasBudget(this.#defaultGasBudget);
|
|
191
|
-
}
|
|
193
|
+
transaction.setGasBudgetIfNotSet(this.#defaultGasBudget);
|
|
192
194
|
|
|
193
195
|
await this.#updateCache();
|
|
194
196
|
gasCoin = await this.#getGasCoin();
|
|
@@ -213,6 +215,7 @@ export class ParallelTransactionExecutor {
|
|
|
213
215
|
transaction: bytes,
|
|
214
216
|
signature,
|
|
215
217
|
options: {
|
|
218
|
+
...options,
|
|
216
219
|
showEffects: true,
|
|
217
220
|
},
|
|
218
221
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { toB64 } from '@mysten/bcs';
|
|
5
5
|
|
|
6
6
|
import { bcs } from '../../bcs/index.js';
|
|
7
|
-
import type { SuiClient } from '../../client/index.js';
|
|
7
|
+
import type { SuiClient, SuiTransactionBlockResponseOptions } from '../../client/index.js';
|
|
8
8
|
import type { Signer } from '../../cryptography/keypair.js';
|
|
9
9
|
import type { ObjectCacheOptions } from '../ObjectCache.js';
|
|
10
10
|
import { isTransaction, Transaction } from '../Transaction.js';
|
|
@@ -15,15 +15,20 @@ export class SerialTransactionExecutor {
|
|
|
15
15
|
#queue = new SerialQueue();
|
|
16
16
|
#signer: Signer;
|
|
17
17
|
#cache: CachingTransactionExecutor;
|
|
18
|
+
#defaultGasBudget: bigint;
|
|
18
19
|
|
|
19
20
|
constructor({
|
|
20
21
|
signer,
|
|
22
|
+
defaultGasBudget = 50_000_000n,
|
|
21
23
|
...options
|
|
22
24
|
}: Omit<ObjectCacheOptions, 'address'> & {
|
|
23
25
|
client: SuiClient;
|
|
24
26
|
signer: Signer;
|
|
27
|
+
/** The gasBudget to use if the transaction has not defined it's own gasBudget, defaults to `50_000_000n` */
|
|
28
|
+
defaultGasBudget?: bigint;
|
|
25
29
|
}) {
|
|
26
30
|
this.#signer = signer;
|
|
31
|
+
this.#defaultGasBudget = defaultGasBudget;
|
|
27
32
|
this.#cache = new CachingTransactionExecutor({
|
|
28
33
|
client: options.client,
|
|
29
34
|
cache: options.cache,
|
|
@@ -63,6 +68,7 @@ export class SerialTransactionExecutor {
|
|
|
63
68
|
copy.setGasPayment([gasCoin]);
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
copy.setGasBudgetIfNotSet(this.#defaultGasBudget);
|
|
66
72
|
copy.setSenderIfNotSet(this.#signer.toSuiAddress());
|
|
67
73
|
|
|
68
74
|
return this.#cache.buildTransaction({ transaction: copy });
|
|
@@ -76,7 +82,10 @@ export class SerialTransactionExecutor {
|
|
|
76
82
|
return this.#cache.waitForLastTransaction();
|
|
77
83
|
}
|
|
78
84
|
|
|
79
|
-
executeTransaction(
|
|
85
|
+
executeTransaction(
|
|
86
|
+
transaction: Transaction | Uint8Array,
|
|
87
|
+
options?: SuiTransactionBlockResponseOptions,
|
|
88
|
+
) {
|
|
80
89
|
return this.#queue.runTask(async () => {
|
|
81
90
|
const bytes = isTransaction(transaction)
|
|
82
91
|
? await this.#buildTransaction(transaction)
|
|
@@ -87,6 +96,7 @@ export class SerialTransactionExecutor {
|
|
|
87
96
|
.executeTransaction({
|
|
88
97
|
signature,
|
|
89
98
|
transaction: bytes,
|
|
99
|
+
options,
|
|
90
100
|
})
|
|
91
101
|
.catch(async (error) => {
|
|
92
102
|
await this.resetCache();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { TransactionObjectInput } from './Transaction.js';
|
|
5
|
+
|
|
6
|
+
export function createObjectMethods<T>(makeObject: (value: TransactionObjectInput) => T) {
|
|
7
|
+
function object(value: TransactionObjectInput) {
|
|
8
|
+
return makeObject(value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
object.system = () => object('0x5');
|
|
12
|
+
object.clock = () => object('0x6');
|
|
13
|
+
object.random = () => object('0x8');
|
|
14
|
+
object.denyList = () => object('0x403');
|
|
15
|
+
|
|
16
|
+
return object;
|
|
17
|
+
}
|
package/src/verify/verify.ts
CHANGED
|
@@ -45,8 +45,9 @@ export async function verifyPersonalMessageSignature(
|
|
|
45
45
|
export async function verifyTransactionSignature(
|
|
46
46
|
transaction: Uint8Array,
|
|
47
47
|
signature: string,
|
|
48
|
+
options: { client?: SuiGraphQLClient } = {},
|
|
48
49
|
): Promise<PublicKey> {
|
|
49
|
-
const parsedSignature = parseSignature(signature);
|
|
50
|
+
const parsedSignature = parseSignature(signature, options);
|
|
50
51
|
|
|
51
52
|
if (
|
|
52
53
|
!(await parsedSignature.publicKey.verifyTransaction(
|
|
@@ -102,10 +103,13 @@ export function publicKeyFromRawBytes(
|
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
105
|
|
|
105
|
-
export function publicKeyFromSuiBytes(
|
|
106
|
+
export function publicKeyFromSuiBytes(
|
|
107
|
+
publicKey: string | Uint8Array,
|
|
108
|
+
options: { client?: SuiGraphQLClient } = {},
|
|
109
|
+
) {
|
|
106
110
|
const bytes = typeof publicKey === 'string' ? fromB64(publicKey) : publicKey;
|
|
107
111
|
|
|
108
112
|
const signatureScheme = SIGNATURE_FLAG_TO_SCHEME[bytes[0] as SignatureFlag];
|
|
109
113
|
|
|
110
|
-
return publicKeyFromRawBytes(signatureScheme, bytes.slice(1));
|
|
114
|
+
return publicKeyFromRawBytes(signatureScheme, bytes.slice(1), options);
|
|
111
115
|
}
|
package/src/version.ts
CHANGED
package/src/zklogin/publickey.ts
CHANGED
|
@@ -71,6 +71,7 @@ export class ZkLoginPublicIdentifier extends PublicKey {
|
|
|
71
71
|
verifyPersonalMessage(message: Uint8Array, signature: Uint8Array | string): Promise<boolean> {
|
|
72
72
|
const parsedSignature = parseSerializedZkLoginSignature(signature);
|
|
73
73
|
const address = new ZkLoginPublicIdentifier(parsedSignature.publicKey).toSuiAddress();
|
|
74
|
+
|
|
74
75
|
return graphqlVerifyZkLoginSignature({
|
|
75
76
|
address: address,
|
|
76
77
|
bytes: toB64(message),
|