@mysten/sui 2.16.0 → 2.16.2
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 +21 -0
- 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/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/proto/sui/rpc/v2/transaction_execution_service.client.d.mts +4 -4
- package/dist/jsonRpc/http-transport.mjs +1 -2
- package/dist/jsonRpc/http-transport.mjs.map +1 -1
- package/dist/transactions/Transaction.d.mts +7 -7
- package/dist/transactions/data/internal.d.mts +109 -109
- package/dist/transactions/data/internal.d.mts.map +1 -1
- package/dist/transactions/data/v1.d.mts +220 -220
- package/dist/transactions/data/v1.d.mts.map +1 -1
- package/dist/transactions/data/v2.d.mts +16 -16
- package/dist/version.mjs +2 -3
- package/dist/version.mjs.map +1 -1
- package/docs/bcs.md +17 -14
- package/docs/clients/core.md +68 -62
- package/docs/clients/graphql.md +6 -4
- package/docs/clients/grpc.md +18 -13
- package/docs/clients/index.md +17 -15
- package/docs/clients/json-rpc.md +21 -17
- package/docs/cryptography/keypairs.md +16 -7
- package/docs/cryptography/multisig.md +7 -5
- package/docs/cryptography/passkey.md +16 -15
- package/docs/cryptography/webcrypto-signer.md +9 -9
- package/docs/executors.md +25 -22
- package/docs/faucet.md +4 -4
- package/docs/hello-sui.md +8 -7
- package/docs/index.md +20 -21
- package/docs/install.md +4 -4
- package/docs/llm-docs.md +10 -10
- package/docs/llms-index.md +41 -57
- package/docs/migrations/0.38.md +10 -9
- package/docs/migrations/sui-1.0.md +35 -33
- package/docs/migrations/sui-2.0/agent-prompt.md +4 -4
- package/docs/migrations/sui-2.0/dapp-kit.md +47 -47
- package/docs/migrations/sui-2.0/deepbook-v3.md +2 -2
- package/docs/migrations/sui-2.0/index.md +38 -37
- package/docs/migrations/sui-2.0/json-rpc-migration.md +59 -50
- package/docs/migrations/sui-2.0/kiosk.md +9 -9
- package/docs/migrations/sui-2.0/sdk-maintainers.md +8 -8
- package/docs/migrations/sui-2.0/seal.md +2 -2
- package/docs/migrations/sui-2.0/sui.md +17 -17
- package/docs/migrations/sui-2.0/suins.md +6 -4
- package/docs/migrations/sui-2.0/wallet-builders.md +6 -6
- package/docs/migrations/sui-2.0/walrus.md +4 -4
- package/docs/migrations/sui-2.0/zksend.md +7 -6
- package/docs/plugins.md +19 -16
- package/docs/sdk-building.md +37 -33
- package/docs/transaction-building/basics.md +16 -14
- package/docs/transaction-building/gas.md +3 -4
- package/docs/transaction-building/intents.md +6 -5
- package/docs/transaction-building/offline.md +11 -9
- package/docs/transaction-building/sponsored-transactions.md +2 -2
- package/docs/utils/derived_objects.md +13 -13
- package/docs/utils/index.md +2 -2
- package/docs/zklogin.md +7 -2
- package/package.json +4 -5
- package/src/jsonRpc/http-transport.ts +1 -2
- package/src/version.ts +1 -2
- package/src/transactions/__tests__/Transaction.test.ts +0 -184
- package/src/transactions/__tests__/bcs.test.ts +0 -205
|
@@ -1,184 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { toBase58 } from '@mysten/bcs';
|
|
5
|
-
import { describe, expect, it } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { bcs } from '../../bcs/index.js';
|
|
8
|
-
import { TransactionCommands, Transaction } from '../index.js';
|
|
9
|
-
import { Inputs } from '../Inputs.js';
|
|
10
|
-
|
|
11
|
-
it('can construct and serialize an empty tranaction', () => {
|
|
12
|
-
const tx = new Transaction();
|
|
13
|
-
expect(() => tx.serialize()).not.toThrow();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('can construct a receiving transaction argument', () => {
|
|
17
|
-
const tx = new Transaction();
|
|
18
|
-
tx.object(Inputs.ReceivingRef(ref()));
|
|
19
|
-
expect(() => tx.serialize()).not.toThrow();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('receiving transaction argument different from object argument', () => {
|
|
23
|
-
const oref = ref();
|
|
24
|
-
const rtx = new Transaction();
|
|
25
|
-
rtx.object(Inputs.ReceivingRef(oref));
|
|
26
|
-
const otx = new Transaction();
|
|
27
|
-
otx.object(Inputs.ObjectRef(oref));
|
|
28
|
-
expect(() => rtx.serialize()).not.toThrow();
|
|
29
|
-
expect(() => otx.serialize()).not.toThrow();
|
|
30
|
-
expect(otx.serialize()).not.toEqual(rtx.serialize());
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('can be serialized and deserialized to the same values', () => {
|
|
34
|
-
const tx = new Transaction();
|
|
35
|
-
tx.add(TransactionCommands.SplitCoins(tx.gas, [tx.pure.u64(100)]));
|
|
36
|
-
const serialized = tx.serialize();
|
|
37
|
-
const tx2 = Transaction.from(serialized);
|
|
38
|
-
expect(serialized).toEqual(tx2.serialize());
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it('allows transfer with the result of split Commands', () => {
|
|
42
|
-
const tx = new Transaction();
|
|
43
|
-
const coin = tx.add(TransactionCommands.SplitCoins(tx.gas, [tx.pure.u64(100)]));
|
|
44
|
-
tx.add(TransactionCommands.TransferObjects([coin], tx.object('0x2')));
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('supports nested results through either array index or destructuring', () => {
|
|
48
|
-
const tx = new Transaction();
|
|
49
|
-
const registerResult = tx.add(
|
|
50
|
-
TransactionCommands.MoveCall({
|
|
51
|
-
target: '0x2::game::register',
|
|
52
|
-
}),
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const [nft, account] = registerResult;
|
|
56
|
-
|
|
57
|
-
// NOTE: This might seem silly but destructuring works differently than property access.
|
|
58
|
-
expect(nft).toBe(registerResult[0]);
|
|
59
|
-
expect(account).toBe(registerResult[1]);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
describe('offline build', () => {
|
|
63
|
-
it('builds an empty transaction offline when provided sufficient data', async () => {
|
|
64
|
-
const tx = setup();
|
|
65
|
-
await tx.build();
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('supports epoch expiration', async () => {
|
|
69
|
-
const tx = setup();
|
|
70
|
-
tx.setExpiration({ Epoch: 1 });
|
|
71
|
-
await tx.build();
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it('builds a split transaction', async () => {
|
|
75
|
-
const tx = setup();
|
|
76
|
-
tx.add(TransactionCommands.SplitCoins(tx.gas, [tx.pure.u64(100)]));
|
|
77
|
-
await tx.build();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('breaks reference equality', () => {
|
|
81
|
-
const tx = setup();
|
|
82
|
-
const tx2 = Transaction.from(tx);
|
|
83
|
-
|
|
84
|
-
tx.setGasBudget(999);
|
|
85
|
-
|
|
86
|
-
// Ensure that setting budget after a clone does not affect the original:
|
|
87
|
-
expect(tx2.getData()).not.toEqual(tx.getData());
|
|
88
|
-
|
|
89
|
-
// Ensure `getData()` always breaks reference equality:
|
|
90
|
-
expect(tx.getData()).not.toBe(tx.getData());
|
|
91
|
-
expect(tx.getData().gasData).not.toBe(tx.getData().gasData);
|
|
92
|
-
expect(tx.getData().commands).not.toBe(tx.getData().commands);
|
|
93
|
-
expect(tx.getData().inputs).not.toBe(tx.getData().inputs);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it('can determine the type of inputs for built-in Commands', async () => {
|
|
97
|
-
const tx = setup();
|
|
98
|
-
tx.splitCoins(tx.gas, [100]);
|
|
99
|
-
await tx.build();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
it('supports pre-serialized inputs as Uint8Array', async () => {
|
|
103
|
-
const tx = setup();
|
|
104
|
-
const inputBytes = bcs.U64.serialize(100n).toBytes();
|
|
105
|
-
// Use bytes directly in pure value:
|
|
106
|
-
tx.add(TransactionCommands.SplitCoins(tx.gas, [tx.pure(inputBytes)]));
|
|
107
|
-
await tx.build();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
it('builds a more complex interaction', async () => {
|
|
111
|
-
const tx = setup();
|
|
112
|
-
const coin = tx.splitCoins(tx.gas, [100]);
|
|
113
|
-
tx.add(TransactionCommands.MergeCoins(tx.gas, [coin, tx.object(Inputs.ObjectRef(ref()))]));
|
|
114
|
-
tx.add(
|
|
115
|
-
TransactionCommands.MoveCall({
|
|
116
|
-
target: '0x2::devnet_nft::mint',
|
|
117
|
-
typeArguments: [],
|
|
118
|
-
arguments: [tx.pure.string('foo'), tx.pure.string('bar'), tx.pure.string('baz')],
|
|
119
|
-
}),
|
|
120
|
-
);
|
|
121
|
-
await tx.build();
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it('uses a receiving argument', async () => {
|
|
125
|
-
const tx = setup();
|
|
126
|
-
tx.object(Inputs.ObjectRef(ref()));
|
|
127
|
-
const coin = tx.splitCoins(tx.gas, [100]);
|
|
128
|
-
tx.add(TransactionCommands.MergeCoins(tx.gas, [coin, tx.object(Inputs.ObjectRef(ref()))]));
|
|
129
|
-
tx.add(
|
|
130
|
-
TransactionCommands.MoveCall({
|
|
131
|
-
target: '0x2::devnet_nft::mint',
|
|
132
|
-
typeArguments: [],
|
|
133
|
-
arguments: [tx.object(Inputs.ObjectRef(ref())), tx.object(Inputs.ReceivingRef(ref()))],
|
|
134
|
-
}),
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
const bytes = await tx.build();
|
|
138
|
-
const tx2 = Transaction.from(bytes);
|
|
139
|
-
const bytes2 = await tx2.build();
|
|
140
|
-
|
|
141
|
-
expect(bytes).toEqual(bytes2);
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('builds a more complex interaction', async () => {
|
|
145
|
-
const tx = setup();
|
|
146
|
-
const coin = tx.splitCoins(tx.gas, [100]);
|
|
147
|
-
tx.add(TransactionCommands.MergeCoins(tx.gas, [coin, tx.object(Inputs.ObjectRef(ref()))]));
|
|
148
|
-
tx.add(
|
|
149
|
-
TransactionCommands.MoveCall({
|
|
150
|
-
target: '0x2::devnet_nft::mint',
|
|
151
|
-
typeArguments: [],
|
|
152
|
-
arguments: [tx.pure.string('foo'), tx.pure.string('bar'), tx.pure.string('baz')],
|
|
153
|
-
}),
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
const bytes = await tx.build();
|
|
157
|
-
const tx2 = Transaction.from(bytes);
|
|
158
|
-
const bytes2 = await tx2.build();
|
|
159
|
-
|
|
160
|
-
expect(bytes).toEqual(bytes2);
|
|
161
|
-
});
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
function ref(): { objectId: string; version: string; digest: string } {
|
|
165
|
-
return {
|
|
166
|
-
objectId: (Math.random() * 100000).toFixed(0).padEnd(64, '0'),
|
|
167
|
-
version: String((Math.random() * 10000).toFixed(0)),
|
|
168
|
-
digest: toBase58(
|
|
169
|
-
new Uint8Array([
|
|
170
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1,
|
|
171
|
-
2,
|
|
172
|
-
]),
|
|
173
|
-
),
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function setup() {
|
|
178
|
-
const tx = new Transaction();
|
|
179
|
-
tx.setSender('0x2');
|
|
180
|
-
tx.setGasPrice(5);
|
|
181
|
-
tx.setGasBudget(100);
|
|
182
|
-
tx.setGasPayment([ref()]);
|
|
183
|
-
return tx;
|
|
184
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
|
|
4
|
-
import { toBase58 } from '@mysten/bcs';
|
|
5
|
-
import { expect, it } from 'vitest';
|
|
6
|
-
|
|
7
|
-
import { bcs } from '../../bcs/index.js';
|
|
8
|
-
import { normalizeStructTag, normalizeSuiAddress } from '../../utils/sui-types.js';
|
|
9
|
-
|
|
10
|
-
// Oooh-weeee we nailed it!
|
|
11
|
-
it('can serialize simplified programmable call struct', () => {
|
|
12
|
-
const moveCall = {
|
|
13
|
-
package: '0x2',
|
|
14
|
-
module: 'display',
|
|
15
|
-
function: 'new',
|
|
16
|
-
typeArguments: [normalizeStructTag('0x6::capy::Capy')],
|
|
17
|
-
arguments: [
|
|
18
|
-
{
|
|
19
|
-
$kind: 'GasCoin',
|
|
20
|
-
GasCoin: true,
|
|
21
|
-
},
|
|
22
|
-
{
|
|
23
|
-
$kind: 'NestedResult',
|
|
24
|
-
NestedResult: [0, 1],
|
|
25
|
-
},
|
|
26
|
-
{
|
|
27
|
-
$kind: 'Input',
|
|
28
|
-
Input: 3,
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
$kind: 'Result',
|
|
32
|
-
Result: 1,
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
} satisfies typeof bcs.ProgrammableMoveCall.$inferType;
|
|
36
|
-
|
|
37
|
-
const bytes = bcs.ProgrammableMoveCall.serialize(moveCall).toBytes();
|
|
38
|
-
const result = bcs.ProgrammableMoveCall.parse(bytes);
|
|
39
|
-
|
|
40
|
-
// since we normalize addresses when (de)serializing, the returned value differs
|
|
41
|
-
// only check the module and the function; ignore address comparison (it's not an issue
|
|
42
|
-
// with non-0x2 addresses).
|
|
43
|
-
expect(result.arguments).toEqual(moveCall.arguments);
|
|
44
|
-
expect(result.function).toEqual(moveCall.function);
|
|
45
|
-
expect(result.module).toEqual(moveCall.module);
|
|
46
|
-
expect(normalizeSuiAddress(result.package)).toEqual(normalizeSuiAddress(moveCall.package));
|
|
47
|
-
expect(result.typeArguments[0]).toEqual(moveCall.typeArguments[0]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
function ref(): { objectId: string; version: string; digest: string } {
|
|
51
|
-
return {
|
|
52
|
-
objectId: normalizeSuiAddress((Math.random() * 100000).toFixed(0).padEnd(64, '0')),
|
|
53
|
-
version: String((Math.random() * 10000).toFixed(0)),
|
|
54
|
-
digest: toBase58(
|
|
55
|
-
new Uint8Array([
|
|
56
|
-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 1,
|
|
57
|
-
2,
|
|
58
|
-
]),
|
|
59
|
-
),
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
it('can serialize transaction data with a programmable transaction', () => {
|
|
64
|
-
const sui = normalizeSuiAddress('0x2');
|
|
65
|
-
const txData = {
|
|
66
|
-
$kind: 'V1',
|
|
67
|
-
V1: {
|
|
68
|
-
sender: normalizeSuiAddress('0xBAD'),
|
|
69
|
-
expiration: { $kind: 'None', None: true },
|
|
70
|
-
gasData: {
|
|
71
|
-
payment: [ref()],
|
|
72
|
-
owner: sui,
|
|
73
|
-
price: '1',
|
|
74
|
-
budget: '1000000',
|
|
75
|
-
},
|
|
76
|
-
kind: {
|
|
77
|
-
$kind: 'ProgrammableTransaction',
|
|
78
|
-
ProgrammableTransaction: {
|
|
79
|
-
inputs: [
|
|
80
|
-
// first argument is the publisher object
|
|
81
|
-
{
|
|
82
|
-
$kind: 'Object',
|
|
83
|
-
Object: {
|
|
84
|
-
$kind: 'ImmOrOwnedObject',
|
|
85
|
-
ImmOrOwnedObject: ref(),
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
// second argument is a vector of names
|
|
89
|
-
{
|
|
90
|
-
$kind: 'Pure',
|
|
91
|
-
Pure: {
|
|
92
|
-
bytes: bcs
|
|
93
|
-
.vector(bcs.String)
|
|
94
|
-
.serialize(['name', 'description', 'img_url'])
|
|
95
|
-
.toBase64(),
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
// third argument is a vector of values
|
|
99
|
-
{
|
|
100
|
-
$kind: 'Pure',
|
|
101
|
-
Pure: {
|
|
102
|
-
bytes: bcs
|
|
103
|
-
.vector(bcs.String)
|
|
104
|
-
.serialize([
|
|
105
|
-
'Capy {name}',
|
|
106
|
-
'A cute little creature',
|
|
107
|
-
'https://api.capy.art/{id}/svg',
|
|
108
|
-
])
|
|
109
|
-
.toBase64(),
|
|
110
|
-
},
|
|
111
|
-
},
|
|
112
|
-
// 4th and last argument is the account address to send display to
|
|
113
|
-
{
|
|
114
|
-
$kind: 'Pure',
|
|
115
|
-
Pure: {
|
|
116
|
-
bytes: bcs.Address.serialize(ref().objectId).toBase64(),
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
],
|
|
120
|
-
commands: [
|
|
121
|
-
{
|
|
122
|
-
$kind: 'MoveCall',
|
|
123
|
-
MoveCall: {
|
|
124
|
-
package: sui,
|
|
125
|
-
module: 'display',
|
|
126
|
-
function: 'new',
|
|
127
|
-
typeArguments: [`${sui}::capy::Capy`],
|
|
128
|
-
arguments: [
|
|
129
|
-
// publisher object
|
|
130
|
-
{
|
|
131
|
-
$kind: 'Input',
|
|
132
|
-
Input: 0,
|
|
133
|
-
},
|
|
134
|
-
],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
$kind: 'MoveCall',
|
|
139
|
-
MoveCall: {
|
|
140
|
-
package: sui,
|
|
141
|
-
module: 'display',
|
|
142
|
-
function: 'add_multiple',
|
|
143
|
-
typeArguments: [`${sui}::capy::Capy`],
|
|
144
|
-
arguments: [
|
|
145
|
-
// result of the first transaction
|
|
146
|
-
{
|
|
147
|
-
$kind: 'Result',
|
|
148
|
-
Result: 0,
|
|
149
|
-
},
|
|
150
|
-
// second argument - vector of names
|
|
151
|
-
{
|
|
152
|
-
$kind: 'Input',
|
|
153
|
-
Input: 1,
|
|
154
|
-
},
|
|
155
|
-
// third argument - vector of values
|
|
156
|
-
{
|
|
157
|
-
$kind: 'Input',
|
|
158
|
-
Input: 2,
|
|
159
|
-
},
|
|
160
|
-
],
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
{
|
|
164
|
-
$kind: 'MoveCall',
|
|
165
|
-
MoveCall: {
|
|
166
|
-
package: sui,
|
|
167
|
-
module: 'display',
|
|
168
|
-
function: 'update_version',
|
|
169
|
-
typeArguments: [`${sui}::capy::Capy`],
|
|
170
|
-
arguments: [
|
|
171
|
-
// result of the first transaction again
|
|
172
|
-
{
|
|
173
|
-
$kind: 'Result',
|
|
174
|
-
Result: 0,
|
|
175
|
-
},
|
|
176
|
-
],
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
$kind: 'TransferObjects',
|
|
181
|
-
TransferObjects: {
|
|
182
|
-
objects: [
|
|
183
|
-
// the display object
|
|
184
|
-
{
|
|
185
|
-
$kind: 'Result',
|
|
186
|
-
Result: 0,
|
|
187
|
-
},
|
|
188
|
-
],
|
|
189
|
-
// address is also an input
|
|
190
|
-
address: {
|
|
191
|
-
$kind: 'Input',
|
|
192
|
-
Input: 3,
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
} satisfies typeof bcs.TransactionData.$inferType;
|
|
201
|
-
|
|
202
|
-
const bytes = bcs.TransactionData.serialize(txData).toBytes();
|
|
203
|
-
const result = bcs.TransactionData.parse(bytes);
|
|
204
|
-
expect(result).toMatchObject(txData);
|
|
205
|
-
});
|