@0xobelisk/sui-client 0.5.16 → 0.5.18

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.
Files changed (43) hide show
  1. package/dist/index.js +360 -205
  2. package/dist/index.js.map +1 -1
  3. package/dist/index.mjs +350 -195
  4. package/dist/index.mjs.map +1 -1
  5. package/package.json +11 -5
  6. package/src/index.ts +9 -8
  7. package/src/libs/multiSig/client.ts +2 -2
  8. package/src/libs/multiSig/publickey.ts +3 -3
  9. package/src/libs/suiAccountManager/index.ts +25 -6
  10. package/src/libs/suiAccountManager/keypair.ts +1 -1
  11. package/src/libs/suiAccountManager/util.ts +1 -1
  12. package/src/libs/suiContractFactory/index.ts +1 -1
  13. package/src/libs/suiContractFactory/types.ts +1 -1
  14. package/src/libs/suiInteractor/suiInteractor.ts +4 -4
  15. package/src/libs/suiModel/suiOwnedObject.ts +6 -4
  16. package/src/libs/suiModel/suiSharedObject.ts +5 -3
  17. package/src/libs/suiTxBuilder/index.ts +102 -84
  18. package/src/libs/suiTxBuilder/util.ts +113 -42
  19. package/src/metadata/index.ts +2 -3
  20. package/src/obelisk.ts +200 -91
  21. package/src/types/index.ts +46 -32
  22. package/dist/index.d.ts +0 -14
  23. package/dist/libs/multiSig/client.d.ts +0 -15
  24. package/dist/libs/multiSig/index.d.ts +0 -1
  25. package/dist/libs/multiSig/publickey.d.ts +0 -2
  26. package/dist/libs/suiAccountManager/crypto.d.ts +0 -1
  27. package/dist/libs/suiAccountManager/index.d.ts +0 -35
  28. package/dist/libs/suiAccountManager/keypair.d.ts +0 -21
  29. package/dist/libs/suiAccountManager/util.d.ts +0 -29
  30. package/dist/libs/suiContractFactory/index.d.ts +0 -20
  31. package/dist/libs/suiContractFactory/types.d.ts +0 -49
  32. package/dist/libs/suiInteractor/index.d.ts +0 -1
  33. package/dist/libs/suiInteractor/suiInteractor.d.ts +0 -50
  34. package/dist/libs/suiInteractor/util.d.ts +0 -1
  35. package/dist/libs/suiModel/index.d.ts +0 -2
  36. package/dist/libs/suiModel/suiOwnedObject.d.ts +0 -24
  37. package/dist/libs/suiModel/suiSharedObject.d.ts +0 -11
  38. package/dist/libs/suiTxBuilder/index.d.ts +0 -333
  39. package/dist/libs/suiTxBuilder/util.d.ts +0 -58
  40. package/dist/metadata/index.d.ts +0 -3
  41. package/dist/obelisk.d.ts +0 -136
  42. package/dist/types/index.d.ts +0 -152
  43. package/dist/utils/index.d.ts +0 -3
@@ -3,23 +3,24 @@ import {
3
3
  normalizeSuiAddress,
4
4
  isValidSuiObjectId,
5
5
  isValidSuiAddress,
6
- } from '@mysten/sui.js/utils';
7
- import { Inputs } from '@mysten/sui.js/transactions';
8
- import { isPureArg } from '@mysten/sui.js/bcs';
9
- import { isSerializedBcs } from '@mysten/bcs';
6
+ } from '@mysten/sui/utils';
7
+ import { Inputs } from '@mysten/sui/transactions';
8
+ import { isSerializedBcs, EnumOutputShapeWithKeys } from '@mysten/bcs';
10
9
  import type {
11
10
  TransactionArgument,
12
- TransactionBlock,
11
+ Transaction,
13
12
  TransactionObjectArgument,
14
- } from '@mysten/sui.js/transactions';
13
+ } from '@mysten/sui/transactions';
14
+ import { bcs } from '@mysten/sui/bcs';
15
15
  import type {
16
16
  SuiInputTypes,
17
17
  SuiObjectArg,
18
18
  SuiAddressArg,
19
19
  SuiTxArg,
20
20
  SuiVecTxArg,
21
+ DryTxReturnValues,
21
22
  } from '../../types';
22
-
23
+ import type { ObjectRef } from '@mysten/sui/transactions';
23
24
  export const getDefaultSuiInputType = (
24
25
  value: SuiTxArg
25
26
  ): SuiInputTypes | undefined => {
@@ -34,6 +35,15 @@ export const getDefaultSuiInputType = (
34
35
  }
35
36
  };
36
37
 
38
+ /**
39
+ * A pure argument.
40
+ */
41
+ export type PureArg = { Pure: Array<number> };
42
+
43
+ export function isPureArg(arg: any): arg is PureArg {
44
+ return (arg as PureArg).Pure !== undefined;
45
+ }
46
+
37
47
  /**
38
48
  * Since we know the elements in the array are the same type
39
49
  * If type is not provided, we will try to infer the type from the first element
@@ -48,7 +58,7 @@ export const getDefaultSuiInputType = (
48
58
  * @param type 'address' | 'bool' | 'u8' | 'u16' | 'u32' | 'u64' | 'u128' | 'u256' | 'signer' | 'object' | string
49
59
  */
50
60
  export function makeVecParam(
51
- txBlock: TransactionBlock,
61
+ tx: Transaction,
52
62
  args: SuiTxArg[],
53
63
  type?: SuiInputTypes
54
64
  ): TransactionArgument {
@@ -62,23 +72,40 @@ export function makeVecParam(
62
72
  type = type || defaultSuiType;
63
73
 
64
74
  if (type === 'object') {
65
- const objects = args.map((arg) =>
75
+ const elements = args.map((arg) =>
66
76
  typeof arg === 'string' && isValidSuiObjectId(arg)
67
- ? txBlock.object(normalizeSuiObjectId(arg))
68
- : convertObjArg(txBlock, arg as SuiObjectArg)
77
+ ? tx.object(normalizeSuiObjectId(arg))
78
+ : convertObjArg(tx, arg as SuiObjectArg)
69
79
  );
70
- return txBlock.makeMoveVec({ objects });
80
+ return tx.makeMoveVec({ elements });
71
81
  } else if (
72
82
  typeof type === 'string' &&
73
83
  !VECTOR_REGEX.test(type) &&
74
84
  !STRUCT_REGEX.test(type)
75
85
  ) {
76
- return txBlock.pure(args, `vector<${type}>`);
86
+ if (type === 'address') {
87
+ return tx.pure(bcs.vector(bcs.Address).serialize(args as string[]));
88
+ } else if (type === 'bool') {
89
+ return tx.pure(bcs.vector(bcs.Bool).serialize(args as boolean[]));
90
+ } else if (type === 'u8') {
91
+ return tx.pure(bcs.vector(bcs.U8).serialize(args as number[]));
92
+ } else if (type === 'u16') {
93
+ return tx.pure(bcs.vector(bcs.U16).serialize(args as number[]));
94
+ } else if (type === 'u32') {
95
+ return tx.pure(bcs.vector(bcs.U32).serialize(args as number[]));
96
+ } else if (type === 'u64') {
97
+ return tx.pure(bcs.vector(bcs.U64).serialize(args as string[]));
98
+ } else if (type === 'u128') {
99
+ return tx.pure(bcs.vector(bcs.U128).serialize(args as string[]));
100
+ } else if (type === 'u256') {
101
+ return tx.pure(bcs.vector(bcs.U256).serialize(args as string[]));
102
+ } else {
103
+ return tx.pure(bcs.vector(bcs.U8).serialize(args as number[]));
104
+ }
105
+ // return tx.pure(args, `vector<${type}>`);
77
106
  } else {
78
- const objects = args.map((arg) =>
79
- convertObjArg(txBlock, arg as SuiObjectArg)
80
- );
81
- return txBlock.makeMoveVec({ objects, type });
107
+ const elements = args.map((arg) => convertObjArg(tx, arg as SuiObjectArg));
108
+ return tx.makeMoveVec({ elements, type });
82
109
  }
83
110
  }
84
111
 
@@ -104,33 +131,68 @@ export function isMoveVecArg(arg: SuiTxArg | SuiVecTxArg): arg is SuiVecTxArg {
104
131
  * @param args The array of argument to convert.
105
132
  * @returns The converted array of TransactionArgument.
106
133
  */
107
- export function convertArgs(
108
- txBlock: TransactionBlock,
109
- args: (SuiTxArg | SuiVecTxArg)[]
110
- ) {
134
+ export function convertArgs(tx: Transaction, args: (SuiTxArg | SuiVecTxArg)[]) {
111
135
  return args.map((arg) => {
112
136
  if (typeof arg === 'string' && isValidSuiObjectId(arg)) {
113
- return txBlock.object(normalizeSuiObjectId(arg));
137
+ return tx.object(normalizeSuiObjectId(arg));
114
138
  } else if (
115
139
  typeof arg == 'object' &&
116
140
  !isSerializedBcs(arg) &&
117
141
  !isPureArg(arg) &&
118
142
  !isMoveVecArg(arg)
119
143
  ) {
120
- return convertObjArg(txBlock, arg as SuiObjectArg);
144
+ return convertObjArg(tx, arg as SuiObjectArg);
121
145
  } else if (isMoveVecArg(arg)) {
122
146
  const vecType = 'vecType' in arg;
123
147
  return vecType
124
- ? makeVecParam(txBlock, arg.value, arg.vecType)
125
- : makeVecParam(txBlock, arg);
148
+ ? makeVecParam(tx, arg.value, arg.vecType)
149
+ : makeVecParam(tx, arg);
126
150
  } else if (isSerializedBcs(arg)) {
127
151
  return arg;
128
152
  } else {
129
- return txBlock.pure(arg);
153
+ let argType = getDefaultSuiInputType(arg);
154
+ if (argType === 'address') {
155
+ return tx.pure.address(arg as string);
156
+ } else if (argType === 'u64') {
157
+ return tx.pure.u64(arg as string);
158
+ } else if (argType === 'bool') {
159
+ return tx.pure.bool(arg as boolean);
160
+ } else {
161
+ return tx.pure.u64(arg as string);
162
+ }
130
163
  }
131
164
  });
132
165
  }
133
166
 
167
+ // /**
168
+ // * Convert any valid input into array of TransactionArgument.
169
+ // *
170
+ // * @param txb The Transaction Block
171
+ // * @param args The array of argument to convert.z
172
+ // * @returns The converted array of TransactionArgument.
173
+ // */
174
+ // export function convertReturnValue(values: DryTxReturnValues) {
175
+ // return values.map(([value, type]) => {
176
+ // if (type === 'address') {
177
+ // return tx.pure.address(value);
178
+ // } else if (type === 'bool') {
179
+ // return tx.pure.bool(value);
180
+ // } else if (type === 'u8') {
181
+ // return tx.pure(bcs.vector(bcs.U8).serialize(args));
182
+ // } else if (type === 'u16') {
183
+ // return tx.pure(bcs.vector(bcs.U16).serialize(args));
184
+ // } else if (type === 'u32') {
185
+ // return tx.pure(bcs.vector(bcs.U32).serialize(args));
186
+ // } else if (type === 'u64') {
187
+ // return tx.pure(bcs.vector(bcs.U64).serialize(args));
188
+ // } else if (type === 'u128') {
189
+ // return tx.pure(bcs.vector(bcs.U128).serialize(args));
190
+ // } else if (type === 'u256') {
191
+ // return tx.pure(bcs.vector(bcs.U256).serialize(args));
192
+ // }
193
+ // });
194
+ // }
195
+
134
196
  /**
135
197
  * Convert any valid address input into a TransactionArgument.
136
198
  *
@@ -138,20 +200,17 @@ export function convertArgs(
138
200
  * @param arg The address argument to convert.
139
201
  * @returns The converted TransactionArgument.
140
202
  */
141
- export function convertAddressArg(
142
- txBlock: TransactionBlock,
143
- arg: SuiAddressArg
144
- ) {
203
+ export function convertAddressArg(tx: Transaction, arg: SuiAddressArg) {
145
204
  if (typeof arg === 'string' && isValidSuiAddress(arg)) {
146
- return txBlock.pure.address(normalizeSuiAddress(arg));
205
+ return tx.pure.address(normalizeSuiAddress(arg));
147
206
  } else if (
148
207
  typeof arg == 'object' &&
149
208
  !isSerializedBcs(arg) &&
150
209
  !isPureArg(arg)
151
210
  ) {
152
- return convertObjArg(txBlock, arg as SuiObjectArg);
211
+ return convertObjArg(tx, arg as SuiObjectArg);
153
212
  } else if (isPureArg(arg)) {
154
- return txBlock.pure(arg);
213
+ return tx.pure(Uint8Array.from(arg.Pure));
155
214
  } else {
156
215
  return arg;
157
216
  }
@@ -160,31 +219,43 @@ export function convertAddressArg(
160
219
  /**
161
220
  * Convert any valid object input into a TransactionArgument.
162
221
  *
163
- * @param txb The Transaction Block
222
+ * @param tx The Transaction
164
223
  * @param arg The object argument to convert.
165
224
  * @returns The converted TransactionArgument.
166
225
  */
167
226
  export function convertObjArg(
168
- txb: TransactionBlock,
227
+ tx: Transaction,
169
228
  arg: SuiObjectArg
170
229
  ): TransactionObjectArgument {
171
230
  if (typeof arg === 'string') {
172
- return txb.object(arg);
231
+ return tx.object(arg);
173
232
  }
174
233
 
175
234
  if ('digest' in arg && 'version' in arg && 'objectId' in arg) {
176
- return txb.objectRef(arg);
235
+ return tx.objectRef(arg);
177
236
  }
178
237
 
179
238
  if ('objectId' in arg && 'initialSharedVersion' in arg && 'mutable' in arg) {
180
- return txb.sharedObjectRef(arg);
239
+ return tx.sharedObjectRef(arg);
181
240
  }
182
241
 
183
242
  if ('Object' in arg) {
184
- if ('ImmOrOwned' in arg.Object) {
185
- return txb.object(Inputs.ObjectRef(arg.Object.ImmOrOwned));
186
- } else if ('Shared' in arg.Object) {
187
- return txb.object(Inputs.SharedObjectRef(arg.Object.Shared));
243
+ if ('ImmOrOwnedObject' in arg.Object) {
244
+ return tx.object(
245
+ Inputs.ObjectRef(arg.Object.ImmOrOwnedObject as ObjectRef)
246
+ );
247
+ } else if ('SharedObject' in arg.Object) {
248
+ return tx.object(
249
+ Inputs.SharedObjectRef(
250
+ arg.Object.SharedObject as {
251
+ objectId: string;
252
+ mutable: boolean;
253
+ initialSharedVersion: number | string;
254
+ }
255
+ )
256
+ );
257
+ } else if ('Receiving' in arg.Object) {
258
+ return tx.object(Inputs.ReceivingRef(arg.Object.Receiving as ObjectRef));
188
259
  } else {
189
260
  throw new Error('Invalid argument type');
190
261
  }
@@ -1,8 +1,7 @@
1
- import { SuiMoveNormalizedModules } from '@mysten/sui.js/client';
2
- import { getFullnodeUrl } from '@mysten/sui.js/client';
1
+ import { SuiMoveNormalizedModules } from '@mysten/sui/client';
2
+ import { getFullnodeUrl } from '@mysten/sui/client';
3
3
 
4
4
  import { SuiInteractor } from '../libs/suiInteractor';
5
-
6
5
  import { NetworkType } from '../types';
7
6
 
8
7
  export async function loadMetadata(