@aptos-labs/ts-sdk 0.0.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.
Files changed (110) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +144 -0
  3. package/dist/browser/index.global.js +410 -0
  4. package/dist/browser/index.global.js.map +1 -0
  5. package/dist/cjs/index.d.ts +4965 -0
  6. package/dist/cjs/index.js +4762 -0
  7. package/dist/cjs/index.js.map +1 -0
  8. package/dist/esm/index.d.ts +4965 -0
  9. package/dist/esm/index.mjs +4645 -0
  10. package/dist/esm/index.mjs.map +1 -0
  11. package/dist/types/index.d.ts +1247 -0
  12. package/dist/types/index.js +151 -0
  13. package/dist/types/index.js.map +1 -0
  14. package/package.json +79 -0
  15. package/src/api/account.ts +360 -0
  16. package/src/api/aptos.ts +103 -0
  17. package/src/api/aptosConfig.ts +77 -0
  18. package/src/api/coin.ts +39 -0
  19. package/src/api/digitalAsset.ts +192 -0
  20. package/src/api/event.ts +78 -0
  21. package/src/api/faucet.ts +30 -0
  22. package/src/api/fungibleAsset.ts +82 -0
  23. package/src/api/general.ts +188 -0
  24. package/src/api/index.ts +5 -0
  25. package/src/api/staking.ts +58 -0
  26. package/src/api/transaction.ts +135 -0
  27. package/src/api/transactionSubmission.ts +168 -0
  28. package/src/bcs/consts.ts +12 -0
  29. package/src/bcs/deserializer.ts +248 -0
  30. package/src/bcs/index.ts +9 -0
  31. package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
  32. package/src/bcs/serializable/fixedBytes.ts +65 -0
  33. package/src/bcs/serializable/movePrimitives.ts +211 -0
  34. package/src/bcs/serializable/moveStructs.ts +462 -0
  35. package/src/bcs/serializer.ts +353 -0
  36. package/src/client/core.ts +106 -0
  37. package/src/client/get.ts +109 -0
  38. package/src/client/index.ts +7 -0
  39. package/src/client/post.ts +90 -0
  40. package/src/client/types.ts +58 -0
  41. package/src/core/account.ts +180 -0
  42. package/src/core/accountAddress.ts +407 -0
  43. package/src/core/authenticationKey.ts +102 -0
  44. package/src/core/common.ts +40 -0
  45. package/src/core/crypto/asymmetricCrypto.ts +77 -0
  46. package/src/core/crypto/ed25519.ts +224 -0
  47. package/src/core/crypto/index.ts +7 -0
  48. package/src/core/crypto/multiEd25519.ts +251 -0
  49. package/src/core/crypto/secp256k1.ts +227 -0
  50. package/src/core/hex.ts +177 -0
  51. package/src/core/index.ts +9 -0
  52. package/src/index.ts +12 -0
  53. package/src/internal/account.ts +484 -0
  54. package/src/internal/coin.ts +32 -0
  55. package/src/internal/digitalAsset.ts +302 -0
  56. package/src/internal/event.ts +88 -0
  57. package/src/internal/faucet.ts +41 -0
  58. package/src/internal/fungibleAsset.ts +114 -0
  59. package/src/internal/general.ts +160 -0
  60. package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
  61. package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
  62. package/src/internal/queries/getAccountCoinCount.graphql +7 -0
  63. package/src/internal/queries/getAccountCoinsData.graphql +32 -0
  64. package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
  65. package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
  66. package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
  67. package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
  68. package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
  69. package/src/internal/queries/getAccountTokensCount.graphql +7 -0
  70. package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
  71. package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
  72. package/src/internal/queries/getCollectionData.graphql +20 -0
  73. package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
  74. package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
  75. package/src/internal/queries/getEvents.graphql +12 -0
  76. package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
  77. package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
  78. package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
  79. package/src/internal/queries/getProcessorStatus.graphql +7 -0
  80. package/src/internal/queries/getTokenActivity.graphql +11 -0
  81. package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
  82. package/src/internal/queries/getTokenData.graphql +38 -0
  83. package/src/internal/staking.ts +68 -0
  84. package/src/internal/transaction.ts +245 -0
  85. package/src/internal/transactionSubmission.ts +162 -0
  86. package/src/transactions/authenticator/account.ts +121 -0
  87. package/src/transactions/authenticator/transaction.ts +222 -0
  88. package/src/transactions/instances/chainId.ts +26 -0
  89. package/src/transactions/instances/identifier.ts +28 -0
  90. package/src/transactions/instances/index.ts +9 -0
  91. package/src/transactions/instances/moduleId.ts +53 -0
  92. package/src/transactions/instances/rawTransaction.ts +199 -0
  93. package/src/transactions/instances/signedTransaction.ts +43 -0
  94. package/src/transactions/instances/transactionArgument.ts +37 -0
  95. package/src/transactions/instances/transactionPayload.ts +407 -0
  96. package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
  97. package/src/transactions/typeTag/typeTag.ts +487 -0
  98. package/src/transactions/types.ts +262 -0
  99. package/src/types/codegen.yaml +33 -0
  100. package/src/types/generated/operations.ts +623 -0
  101. package/src/types/generated/queries.ts +737 -0
  102. package/src/types/generated/types.ts +10387 -0
  103. package/src/types/index.ts +944 -0
  104. package/src/types/indexer.ts +93 -0
  105. package/src/utils/apiEndpoints.ts +36 -0
  106. package/src/utils/const.ts +51 -0
  107. package/src/utils/hdKey.ts +113 -0
  108. package/src/utils/helpers.ts +12 -0
  109. package/src/utils/memoize.ts +68 -0
  110. package/src/version.ts +9 -0
@@ -0,0 +1,462 @@
1
+ // Copyright © Aptos Foundation
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { Bool, U128, U16, U256, U32, U64, U8 } from "./movePrimitives";
5
+ import { Serializable, Serializer } from "../serializer";
6
+ import { Deserializable, Deserializer } from "../deserializer";
7
+ import { AnyNumber, HexInput, ScriptTransactionArgumentVariants } from "../../types";
8
+ import { Hex } from "../../core/hex";
9
+ import { AccountAddress } from "../../core/accountAddress";
10
+ import { EntryFunctionArgument, TransactionArgument } from "../../transactions/instances/transactionArgument";
11
+
12
+ /**
13
+ * This class is the Aptos Typescript SDK representation of a Move `vector<T>`,
14
+ * where `T` represents either a primitive type (`bool`, `u8`, `u64`, ...)
15
+ * or a BCS-serializable struct itself.
16
+ *
17
+ * It is a BCS-serializable, array-like type that contains an array of values of type `T`,
18
+ * where `T` is a class that implements `Serializable`.
19
+ *
20
+ * The purpose of this class is to facilitate easy construction of BCS-serializable
21
+ * Move `vector<T>` types.
22
+ *
23
+ * @example
24
+ * // in Move: `vector<u8> [1, 2, 3, 4];`
25
+ * const vecOfU8s = new MoveVector<U8>([new U8(1), new U8(2), new U8(3), new U8(4)]);
26
+ * // in Move: `std::bcs::to_bytes(vector<u8> [1, 2, 3, 4]);`
27
+ * const bcsBytes = vecOfU8s.toUint8Array();
28
+ *
29
+ * // vector<vector<u8>> [ vector<u8> [1], vector<u8> [1, 2, 3, 4], vector<u8> [5, 6, 7, 8] ];
30
+ * const vecOfVecs = new MoveVector<MoveVector<U8>>([
31
+ * new MoveVector<U8>([new U8(1)]),
32
+ * MoveVector.U8([1, 2, 3, 4]),
33
+ * MoveVector.U8([5, 6, 7, 8]),
34
+ * ]);
35
+ *
36
+ * // vector<Option<u8>> [ std::option::some<u8>(1), std::option::some<u8>(2) ];
37
+ * const vecOfOptionU8s = new MoveVector<MoveOption<U8>>([
38
+ * MoveOption.U8(1),
39
+ * MoveOption.U8(2),
40
+ * ]);
41
+ *
42
+ * // vector<MoveString> [ std::string::utf8(b"hello"), std::string::utf8(b"world") ];
43
+ * const vecOfStrings = new MoveVector([new MoveString("hello"), new MoveString("world")]);
44
+ * const vecOfStrings2 = MoveVector.MoveString(["hello", "world"]);
45
+ *
46
+ * // where MySerializableStruct is a class you've made that implements Serializable
47
+ * const vecOfSerializableValues = new MoveVector<MySerializableStruct>([
48
+ * new MySerializableStruct("hello", "world"),
49
+ * new MySerializableStruct("foo", "bar"),
50
+ * ]);
51
+ * @params
52
+ * values: an Array<T> of values where T is a class that implements Serializable
53
+ * @returns a `MoveVector<T>` with the values `values`
54
+ */
55
+ export class MoveVector<T extends Serializable> extends Serializable implements TransactionArgument {
56
+ public values: Array<T>;
57
+
58
+ constructor(values: Array<T>) {
59
+ super();
60
+ this.values = values;
61
+ }
62
+
63
+ serializeForEntryFunction(serializer: Serializer): void {
64
+ const bcsBytes = this.bcsToBytes();
65
+ serializer.serializeBytes(bcsBytes);
66
+ }
67
+
68
+ /**
69
+ * NOTE: This function will only work when the inner values in the `MoveVector` are `U8`s.
70
+ * @param serializer
71
+ */
72
+ serializeForScriptFunction(serializer: Serializer): void {
73
+ // runtime check to ensure that you can't serialize anything other than vector<u8>
74
+ // TODO: consider adding support for MoveString later?
75
+ const isU8 = this.values[0] instanceof U8;
76
+ if (!isU8) {
77
+ throw new Error("Script function arguments only accept u8 vectors");
78
+ }
79
+ serializer.serializeU32AsUleb128(ScriptTransactionArgumentVariants.U8Vector);
80
+ serializer.serialize(this);
81
+ }
82
+
83
+ /**
84
+ * Factory method to generate a MoveVector of U8s from an array of numbers.
85
+ *
86
+ * @example
87
+ * const v = MoveVector.U8([1, 2, 3, 4]);
88
+ * @params values: an array of `numbers` to convert to U8s
89
+ * @returns a `MoveVector<U8>`
90
+ */
91
+ static U8(values: Array<number> | HexInput): MoveVector<U8> {
92
+ let numbers: Array<number>;
93
+
94
+ if (Array.isArray(values) && typeof values[0] === "number") {
95
+ numbers = values;
96
+ } else if (typeof values === "string") {
97
+ const hex = Hex.fromHexInput(values);
98
+ numbers = Array.from(hex.toUint8Array());
99
+ } else if (values instanceof Uint8Array) {
100
+ numbers = Array.from(values);
101
+ } else {
102
+ throw new Error("Invalid input type");
103
+ }
104
+
105
+ return new MoveVector<U8>(numbers.map((v) => new U8(v)));
106
+ }
107
+
108
+ /**
109
+ * Factory method to generate a MoveVector of U16s from an array of numbers.
110
+ *
111
+ * @example
112
+ * const v = MoveVector.U16([1, 2, 3, 4]);
113
+ * @params values: an array of `numbers` to convert to U16s
114
+ * @returns a `MoveVector<U16>`
115
+ */
116
+ static U16(values: Array<number>): MoveVector<U16> {
117
+ return new MoveVector<U16>(values.map((v) => new U16(v)));
118
+ }
119
+
120
+ /**
121
+ * Factory method to generate a MoveVector of U32s from an array of numbers.
122
+ *
123
+ * @example
124
+ * const v = MoveVector.U32([1, 2, 3, 4]);
125
+ * @params values: an array of `numbers` to convert to U32s
126
+ * @returns a `MoveVector<U32>`
127
+ */
128
+ static U32(values: Array<number>): MoveVector<U32> {
129
+ return new MoveVector<U32>(values.map((v) => new U32(v)));
130
+ }
131
+
132
+ /**
133
+ * Factory method to generate a MoveVector of U64s from an array of numbers or bigints.
134
+ *
135
+ * @example
136
+ * const v = MoveVector.U64([1, 2, 3, 4]);
137
+ * @params values: an array of numbers of type `number | bigint` to convert to U64s
138
+ * @returns a `MoveVector<U64>`
139
+ */
140
+ static U64(values: Array<AnyNumber>): MoveVector<U64> {
141
+ return new MoveVector<U64>(values.map((v) => new U64(v)));
142
+ }
143
+
144
+ /**
145
+ * Factory method to generate a MoveVector of U128s from an array of numbers or bigints.
146
+ *
147
+ * @example
148
+ * const v = MoveVector.U128([1, 2, 3, 4]);
149
+ * @params values: an array of numbers of type `number | bigint` to convert to U128s
150
+ * @returns a `MoveVector<U128>`
151
+ */
152
+ static U128(values: Array<AnyNumber>): MoveVector<U128> {
153
+ return new MoveVector<U128>(values.map((v) => new U128(v)));
154
+ }
155
+
156
+ /**
157
+ * Factory method to generate a MoveVector of U256s from an array of numbers or bigints.
158
+ *
159
+ * @example
160
+ * const v = MoveVector.U256([1, 2, 3, 4]);
161
+ * @params values: an array of numbers of type `number | bigint` to convert to U256s
162
+ * @returns a `MoveVector<U256>`
163
+ */
164
+ static U256(values: Array<AnyNumber>): MoveVector<U256> {
165
+ return new MoveVector<U256>(values.map((v) => new U256(v)));
166
+ }
167
+
168
+ /**
169
+ * Factory method to generate a MoveVector of Bools from an array of booleans.
170
+ *
171
+ * @example
172
+ * const v = MoveVector.Bool([true, false, true, false]);
173
+ * @params values: an array of `numbers` to convert to Bools
174
+ * @returns a `MoveVector<Bool>`
175
+ */
176
+ static Bool(values: Array<boolean>): MoveVector<Bool> {
177
+ return new MoveVector<Bool>(values.map((v) => new Bool(v)));
178
+ }
179
+
180
+ /**
181
+ * Factory method to generate a MoveVector of MoveStrings from an array of strings.
182
+ *
183
+ * @example
184
+ * const v = MoveVector.MoveString(["hello", "world"]);
185
+ * @params values: an array of `numbers` to convert to MoveStrings
186
+ * @returns a `MoveVector<MoveString>`
187
+ */
188
+ static MoveString(values: Array<string>): MoveVector<MoveString> {
189
+ return new MoveVector<MoveString>(values.map((v) => new MoveString(v)));
190
+ }
191
+
192
+ serialize(serializer: Serializer): void {
193
+ serializer.serializeVector(this.values);
194
+ }
195
+
196
+ /**
197
+ * Deserialize a MoveVector of type T, specifically where T is a Serializable and Deserializable type.
198
+ *
199
+ * NOTE: This only works with a depth of one. Generics will not work.
200
+ *
201
+ * NOTE: This will not work with types that aren't of the Serializable class.
202
+ *
203
+ * If you want to use types that merely implement Deserializable,
204
+ * please use the deserializeVector function in the Deserializer class.
205
+ * @example
206
+ * const vec = MoveVector.deserialize(deserializer, U64);
207
+ * @params deserializer: the Deserializer instance to use, with bytes loaded into it already.
208
+ * cls: the class to typecast the input values to, must be a Serializable and Deserializable type.
209
+ * @returns a MoveVector of the corresponding class T
210
+ * *
211
+ */
212
+ static deserialize<T extends Serializable>(deserializer: Deserializer, cls: Deserializable<T>): MoveVector<T> {
213
+ const length = deserializer.deserializeUleb128AsU32();
214
+ const values = new Array<T>();
215
+ for (let i = 0; i < length; i += 1) {
216
+ values.push(cls.deserialize(deserializer));
217
+ }
218
+ return new MoveVector(values);
219
+ }
220
+ }
221
+
222
+ export class MoveString extends Serializable implements TransactionArgument {
223
+ public value: string;
224
+
225
+ constructor(value: string) {
226
+ super();
227
+ this.value = value;
228
+ }
229
+
230
+ serialize(serializer: Serializer): void {
231
+ serializer.serializeStr(this.value);
232
+ }
233
+
234
+ serializeForEntryFunction(serializer: Serializer): void {
235
+ const bcsBytes = this.bcsToBytes();
236
+ serializer.serializeBytes(bcsBytes);
237
+ }
238
+
239
+ serializeForScriptFunction(serializer: Serializer): void {
240
+ // serialize the string, load it into a vector<u8> and serialize it as a script vector<u8> argument
241
+ const vectorU8 = MoveVector.U8(this.bcsToBytes());
242
+ vectorU8.serializeForScriptFunction(serializer);
243
+ }
244
+
245
+ static deserialize(deserializer: Deserializer): MoveString {
246
+ return new MoveString(deserializer.deserializeStr());
247
+ }
248
+ }
249
+
250
+ export class MoveOption<T extends Serializable> extends Serializable implements EntryFunctionArgument {
251
+ private vec: MoveVector<T>;
252
+
253
+ public readonly value?: T;
254
+
255
+ constructor(value?: T | null) {
256
+ super();
257
+ if (typeof value !== "undefined" && value !== null) {
258
+ this.vec = new MoveVector([value]);
259
+ } else {
260
+ this.vec = new MoveVector([]);
261
+ }
262
+
263
+ [this.value] = this.vec.values;
264
+ }
265
+
266
+ serializeForEntryFunction(serializer: Serializer): void {
267
+ const bcsBytes = this.bcsToBytes();
268
+ serializer.serializeBytes(bcsBytes);
269
+ }
270
+
271
+ /**
272
+ * Retrieves the inner value of the MoveOption.
273
+ *
274
+ * This method is inspired by Rust's `Option<T>.unwrap()`.
275
+ * In Rust, attempting to unwrap a `None` value results in a panic.
276
+ *
277
+ * Similarly, this method will throw an error if the value is not present.
278
+ *
279
+ * @example
280
+ * const option = new MoveOption<Bool>(new Bool(true));
281
+ * const value = option.unwrap(); // Returns the Bool instance
282
+ *
283
+ * @throws {Error} Throws an error if the MoveOption does not contain a value.
284
+ *
285
+ * @returns {T} The contained value if present.
286
+ */
287
+ unwrap(): T {
288
+ if (!this.isSome()) {
289
+ throw new Error("Called unwrap on a MoveOption with no value");
290
+ } else {
291
+ return this.vec.values[0];
292
+ }
293
+ }
294
+
295
+ // Check if the MoveOption has a value.
296
+ isSome(): boolean {
297
+ return this.vec.values.length === 1;
298
+ }
299
+
300
+ serialize(serializer: Serializer): void {
301
+ // serialize 0 or 1
302
+ // if 1, serialize the value
303
+ this.vec.serialize(serializer);
304
+ }
305
+
306
+ /**
307
+ * Factory method to generate a MoveOption<U8> from a `number` or `undefined`.
308
+ *
309
+ * @example
310
+ * MoveOption.U8(1).isSome() === true;
311
+ * MoveOption.U8().isSome() === false;
312
+ * MoveOption.U8(undefined).isSome() === false;
313
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
314
+ * the resulting MoveOption's .isSome() method will return false.
315
+ * @returns a MoveOption<U8> with an inner value `value`
316
+ */
317
+ static U8(value?: number | null): MoveOption<U8> {
318
+ return new MoveOption<U8>(value !== null && value !== undefined ? new U8(value) : undefined);
319
+ }
320
+
321
+ /**
322
+ * Factory method to generate a MoveOption<U16> from a `number` or `undefined`.
323
+ *
324
+ * @example
325
+ * MoveOption.U16(1).isSome() === true;
326
+ * MoveOption.U16().isSome() === false;
327
+ * MoveOption.U16(undefined).isSome() === false;
328
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
329
+ * the resulting MoveOption's .isSome() method will return false.
330
+ * @returns a MoveOption<U16> with an inner value `value`
331
+ */
332
+ static U16(value?: number | null): MoveOption<U16> {
333
+ return new MoveOption<U16>(value !== null && value !== undefined ? new U16(value) : undefined);
334
+ }
335
+
336
+ /**
337
+ * Factory method to generate a MoveOption<U32> from a `number` or `undefined`.
338
+ *
339
+ * @example
340
+ * MoveOption.U32(1).isSome() === true;
341
+ * MoveOption.U32().isSome() === false;
342
+ * MoveOption.U32(undefined).isSome() === false;
343
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
344
+ * the resulting MoveOption's .isSome() method will return false.
345
+ * @returns a MoveOption<U32> with an inner value `value`
346
+ */
347
+ static U32(value?: number | null): MoveOption<U32> {
348
+ return new MoveOption<U32>(value !== null && value !== undefined ? new U32(value) : undefined);
349
+ }
350
+
351
+ /**
352
+ * Factory method to generate a MoveOption<U64> from a `number` or a `bigint` or `undefined`.
353
+ *
354
+ * @example
355
+ * MoveOption.U64(1).isSome() === true;
356
+ * MoveOption.U64().isSome() === false;
357
+ * MoveOption.U64(undefined).isSome() === false;
358
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
359
+ * the resulting MoveOption's .isSome() method will return false.
360
+ * @returns a MoveOption<U64> with an inner value `value`
361
+ */
362
+ static U64(value?: AnyNumber | null): MoveOption<U64> {
363
+ return new MoveOption<U64>(value !== null && value !== undefined ? new U64(value) : undefined);
364
+ }
365
+
366
+ /**
367
+ * Factory method to generate a MoveOption<U128> from a `number` or a `bigint` or `undefined`.
368
+ *
369
+ * @example
370
+ * MoveOption.U128(1).isSome() === true;
371
+ * MoveOption.U128().isSome() === false;
372
+ * MoveOption.U128(undefined).isSome() === false;
373
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
374
+ * the resulting MoveOption's .isSome() method will return false.
375
+ * @returns a MoveOption<U128> with an inner value `value`
376
+ */
377
+ static U128(value?: AnyNumber | null): MoveOption<U128> {
378
+ return new MoveOption<U128>(value !== null && value !== undefined ? new U128(value) : undefined);
379
+ }
380
+
381
+ /**
382
+ * Factory method to generate a MoveOption<U256> from a `number` or a `bigint` or `undefined`.
383
+ *
384
+ * @example
385
+ * MoveOption.U256(1).isSome() === true;
386
+ * MoveOption.U256().isSome() === false;
387
+ * MoveOption.U256(undefined).isSome() === false;
388
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
389
+ * the resulting MoveOption's .isSome() method will return false.
390
+ * @returns a MoveOption<U256> with an inner value `value`
391
+ */
392
+ static U256(value?: AnyNumber | null): MoveOption<U256> {
393
+ return new MoveOption<U256>(value !== null && value !== undefined ? new U256(value) : undefined);
394
+ }
395
+
396
+ /**
397
+ * Factory method to generate a MoveOption<Bool> from a `boolean` or `undefined`.
398
+ *
399
+ * @example
400
+ * MoveOption.Bool(true).isSome() === true;
401
+ * MoveOption.Bool().isSome() === false;
402
+ * MoveOption.Bool(undefined).isSome() === false;
403
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
404
+ * the resulting MoveOption's .isSome() method will return false.
405
+ * @returns a MoveOption<Bool> with an inner value `value`
406
+ */
407
+ static Bool(value?: boolean | null): MoveOption<Bool> {
408
+ return new MoveOption<Bool>(value !== null && value !== undefined ? new Bool(value) : undefined);
409
+ }
410
+
411
+ /**
412
+ * Factory method to generate a MoveOption<MoveString> from a `string` or `undefined`.
413
+ *
414
+ * @example
415
+ * MoveOption.MoveString("hello").isSome() === true;
416
+ * MoveOption.MoveString("").isSome() === true;
417
+ * MoveOption.MoveString().isSome() === false;
418
+ * MoveOption.MoveString(undefined).isSome() === false;
419
+ * @params value: the value used to fill the MoveOption. If `value` is undefined
420
+ * the resulting MoveOption's .isSome() method will return false.
421
+ * @returns a MoveOption<MoveString> with an inner value `value`
422
+ */
423
+ static MoveString(value?: string | null): MoveOption<MoveString> {
424
+ return new MoveOption<MoveString>(value !== null && value !== undefined ? new MoveString(value) : undefined);
425
+ }
426
+
427
+ static deserialize<U extends Serializable>(deserializer: Deserializer, cls: Deserializable<U>): MoveOption<U> {
428
+ const vector = MoveVector.deserialize(deserializer, cls);
429
+ return new MoveOption(vector.values[0]);
430
+ }
431
+ }
432
+
433
+ export class MoveObject extends Serializable implements TransactionArgument {
434
+ public value: AccountAddress;
435
+
436
+ constructor(value: HexInput | AccountAddress) {
437
+ super();
438
+
439
+ if (value instanceof AccountAddress) {
440
+ this.value = value;
441
+ } else {
442
+ this.value = AccountAddress.fromHexInputRelaxed(value);
443
+ }
444
+ }
445
+
446
+ serialize(serializer: Serializer): void {
447
+ serializer.serialize(this.value);
448
+ }
449
+
450
+ serializeForEntryFunction(serializer: Serializer): void {
451
+ this.value.serializeForEntryFunction(serializer);
452
+ }
453
+
454
+ serializeForScriptFunction(serializer: Serializer): void {
455
+ this.value.serializeForScriptFunction(serializer);
456
+ }
457
+
458
+ static deserialize(deserializer: Deserializer): MoveObject {
459
+ const address = deserializer.deserialize(AccountAddress);
460
+ return new MoveObject(address);
461
+ }
462
+ }