@aptos-labs/ts-sdk 0.0.2 → 0.0.3

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 (51) hide show
  1. package/README.md +32 -24
  2. package/dist/browser/index.global.js +25 -25
  3. package/dist/browser/index.global.js.map +1 -1
  4. package/dist/cjs/index.d.ts +665 -157
  5. package/dist/cjs/index.js +1291 -652
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/esm/index.d.ts +665 -157
  8. package/dist/esm/index.mjs +1224 -650
  9. package/dist/esm/index.mjs.map +1 -1
  10. package/dist/types/index.d.ts +20 -19
  11. package/dist/types/index.js +4 -2
  12. package/dist/types/index.js.map +1 -1
  13. package/package.json +1 -1
  14. package/src/api/account.ts +2 -2
  15. package/src/api/coin.ts +5 -5
  16. package/src/api/digitalAsset.ts +5 -5
  17. package/src/api/event.ts +2 -2
  18. package/src/api/faucet.ts +7 -3
  19. package/src/api/transactionSubmission.ts +24 -24
  20. package/src/bcs/serializable/fixedBytes.ts +1 -1
  21. package/src/bcs/serializable/moveStructs.ts +16 -36
  22. package/src/core/account.ts +12 -8
  23. package/src/core/accountAddress.ts +4 -2
  24. package/src/core/authenticationKey.ts +24 -2
  25. package/src/core/crypto/anyPublicKey.ts +14 -18
  26. package/src/core/crypto/ed25519.ts +6 -0
  27. package/src/core/crypto/index.ts +1 -0
  28. package/src/core/crypto/multiKey.ts +122 -0
  29. package/src/core/crypto/secp256k1.ts +2 -0
  30. package/src/index.ts +1 -2
  31. package/src/internal/account.ts +5 -5
  32. package/src/internal/coin.ts +8 -8
  33. package/src/internal/digitalAsset.ts +7 -7
  34. package/src/internal/event.ts +2 -2
  35. package/src/internal/faucet.ts +9 -5
  36. package/src/internal/transactionSubmission.ts +40 -15
  37. package/src/transactions/authenticator/account.ts +39 -0
  38. package/src/transactions/authenticator/index.ts +5 -0
  39. package/src/transactions/authenticator/transaction.ts +6 -6
  40. package/src/transactions/index.ts +9 -0
  41. package/src/transactions/instances/index.ts +1 -0
  42. package/src/transactions/instances/transactionPayload.ts +13 -8
  43. package/src/transactions/transactionBuilder/helpers.ts +99 -0
  44. package/src/transactions/transactionBuilder/index.ts +6 -0
  45. package/src/transactions/transactionBuilder/remoteAbi.ts +339 -0
  46. package/src/transactions/{transaction_builder/transaction_builder.ts → transactionBuilder/transactionBuilder.ts} +149 -68
  47. package/src/transactions/typeTag/index.ts +385 -0
  48. package/src/transactions/typeTag/parser.ts +21 -8
  49. package/src/transactions/types.ts +87 -46
  50. package/src/types/index.ts +18 -16
  51. package/src/transactions/typeTag/typeTag.ts +0 -487
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  import { AptosConfig } from "../api/aptosConfig";
5
- import { MoveObject, MoveOption, MoveString, MoveVector } from "../bcs/serializable/moveStructs";
5
+ import { MoveOption, MoveString, MoveVector } from "../bcs/serializable/moveStructs";
6
6
  import { Bool, U128, U16, U256, U32, U64, U8 } from "../bcs/serializable/movePrimitives";
7
7
  import { FixedBytes } from "../bcs/serializable/fixedBytes";
8
8
  import { AccountAddress } from "../core";
@@ -15,9 +15,25 @@ import {
15
15
  TransactionPayloadMultisig,
16
16
  TransactionPayloadScript,
17
17
  } from "./instances";
18
- import { AnyNumber, HexInput, MoveStructType } from "../types";
19
- import { TypeTag } from "./typeTag/typeTag";
18
+ import { AnyNumber, HexInput, MoveFunctionGenericTypeParam, MoveStructType } from "../types";
19
+ import { TypeTag } from "./typeTag";
20
20
 
21
+ /**
22
+ * Entry function arguments to be used when building a raw transaction using remote ABI
23
+ */
24
+ export type SimpleEntryFunctionArgumentTypes =
25
+ | boolean
26
+ | number
27
+ | bigint
28
+ | string
29
+ | null // To support optional empty
30
+ | undefined // To support optional empty
31
+ | Uint8Array
32
+ | Array<SimpleEntryFunctionArgumentTypes>;
33
+
34
+ /**
35
+ * Entry function arguments to be used when building a raw transaction using BCS serialized arguments
36
+ */
21
37
  export type EntryFunctionArgumentTypes =
22
38
  | Bool
23
39
  | U8
@@ -27,11 +43,14 @@ export type EntryFunctionArgumentTypes =
27
43
  | U128
28
44
  | U256
29
45
  | AccountAddress
30
- | MoveObject
31
46
  | MoveVector<EntryFunctionArgumentTypes>
32
47
  | MoveOption<EntryFunctionArgumentTypes>
33
48
  | MoveString
34
49
  | FixedBytes;
50
+
51
+ /**
52
+ * Script function arguments to be used when building a raw transaction using BCS serialized arguments
53
+ */
35
54
  export type ScriptFunctionArgumentTypes =
36
55
  | Bool
37
56
  | U8
@@ -41,7 +60,6 @@ export type ScriptFunctionArgumentTypes =
41
60
  | U128
42
61
  | U256
43
62
  | AccountAddress
44
- | MoveObject
45
63
  | MoveVector<U8>
46
64
  | MoveString
47
65
  | FixedBytes;
@@ -56,7 +74,7 @@ export type AnyRawTransactionInstance = RawTransaction | MultiAgentRawTransactio
56
74
  /**
57
75
  * Optional options to set when generating a transaction
58
76
  */
59
- export type GenerateTransactionOptions = {
77
+ export type InputGenerateTransactionOptions = {
60
78
  maxGasAmount?: AnyNumber;
61
79
  gasUnitPrice?: AnyNumber;
62
80
  expireTimestamp?: AnyNumber;
@@ -66,7 +84,7 @@ export type GenerateTransactionOptions = {
66
84
  /**
67
85
  * The generated transaction payload type that was produces from `generateTransactionPayload()` function.
68
86
  */
69
- export type TransactionPayload =
87
+ export type AnyTransactionPayloadInstance =
70
88
  | TransactionPayloadEntryFunction
71
89
  | TransactionPayloadScript
72
90
  | TransactionPayloadMultisig;
@@ -75,86 +93,109 @@ export type TransactionPayload =
75
93
  * Unified type for the data needed to generate a transaction payload of types:
76
94
  * Entry Function | Script | Multi Sig
77
95
  */
78
- export type GenerateTransactionPayloadData = EntryFunctionData | ScriptData | MultiSigData;
96
+ export type InputGenerateTransactionPayloadData = InputEntryFunctionData | InputScriptData | InputMultiSigData;
97
+
98
+ export type InputGenerateTransactionPayloadDataWithRemoteABI =
99
+ | (InputScriptData & { aptosConfig?: undefined })
100
+ | InputEntryFunctionDataWithRemoteABI
101
+ | InputMultiSigDataWithRemoteABI;
79
102
 
80
103
  /**
81
104
  * The data needed to generate an Entry Function payload
82
105
  */
83
- export type EntryFunctionData = {
106
+ export type InputEntryFunctionData = {
84
107
  function: MoveStructType;
85
108
  typeArguments?: Array<TypeTag>;
86
- functionArguments: Array<EntryFunctionArgumentTypes>;
109
+ functionArguments: Array<EntryFunctionArgumentTypes | SimpleEntryFunctionArgumentTypes>;
87
110
  };
88
111
 
112
+ export type InputEntryFunctionDataWithRemoteABI = InputEntryFunctionData & { aptosConfig: AptosConfig };
89
113
  /**
90
114
  * The data needed to generate a Multi Sig payload
91
115
  */
92
- export type MultiSigData = {
116
+ export type InputMultiSigData = {
93
117
  multisigAddress: AccountAddress;
94
- } & EntryFunctionData;
118
+ } & InputEntryFunctionData;
119
+
120
+ /**
121
+ * The data needed to generate a Multi Sig payload
122
+ */
123
+ export type InputMultiSigDataWithRemoteABI = {
124
+ multisigAddress: AccountAddress | string;
125
+ } & InputEntryFunctionDataWithRemoteABI;
95
126
 
96
127
  /**
97
128
  * The data needed to generate a Script payload
98
129
  */
99
- export type ScriptData = {
130
+ export type InputScriptData = {
100
131
  bytecode: HexInput;
101
132
  typeArguments?: Array<TypeTag>;
102
133
  functionArguments: Array<ScriptFunctionArgumentTypes>;
103
134
  };
104
135
 
136
+ /**
137
+ * Interface of an Entry function's ABI.
138
+ *
139
+ * This is used to provide type checking and simple input conversion on ABI based transaction submission.
140
+ */
141
+ export type EntryFunctionABI = {
142
+ typeParameters: Array<MoveFunctionGenericTypeParam>;
143
+ parameters: Array<TypeTag>;
144
+ };
145
+
105
146
  /**
106
147
  * Interface of the arguments to generate a single signer transaction.
107
148
  * Used to provide to `generateTransaction()` method in the transaction builder flow
108
149
  */
109
- export interface GenerateSingleSignerRawTransactionArgs {
150
+ export interface InputGenerateSingleSignerRawTransactionArgs {
110
151
  aptosConfig: AptosConfig;
111
152
  sender: HexInput;
112
- payload: TransactionPayload;
153
+ payload: AnyTransactionPayloadInstance;
113
154
  feePayerAddress?: undefined;
114
155
  secondarySignerAddresses?: undefined;
115
- options?: GenerateTransactionOptions;
156
+ options?: InputGenerateTransactionOptions;
116
157
  }
117
158
 
118
159
  /**
119
160
  * Interface of the arguments to generate a fee payer transaction.
120
161
  * Used to provide to `generateTransaction()` method in the transaction builder flow
121
162
  */
122
- export interface GenerateFeePayerRawTransactionArgs {
163
+ export interface InputGenerateFeePayerRawTransactionArgs {
123
164
  aptosConfig: AptosConfig;
124
165
  sender: HexInput;
125
- payload: TransactionPayload;
166
+ payload: AnyTransactionPayloadInstance;
126
167
  feePayerAddress: HexInput;
127
168
  secondarySignerAddresses?: HexInput[];
128
- options?: GenerateTransactionOptions;
169
+ options?: InputGenerateTransactionOptions;
129
170
  }
130
171
 
131
172
  /**
132
173
  * Interface of the arguments to generate a multi-agent transaction.
133
174
  * Used to provide to `generateTransaction()` method in the transaction builder flow
134
175
  */
135
- export interface GenerateMultiAgentRawTransactionArgs {
176
+ export interface InputGenerateMultiAgentRawTransactionArgs {
136
177
  aptosConfig: AptosConfig;
137
178
  sender: HexInput;
138
- payload: TransactionPayload;
179
+ payload: AnyTransactionPayloadInstance;
139
180
  secondarySignerAddresses: HexInput[];
140
181
  feePayerAddress?: undefined;
141
- options?: GenerateTransactionOptions;
182
+ options?: InputGenerateTransactionOptions;
142
183
  }
143
184
 
144
185
  /**
145
186
  * Unified type that holds all the interfaces to generate different transaction types
146
187
  */
147
- export type GenerateRawTransactionArgs =
148
- | GenerateSingleSignerRawTransactionArgs
149
- | GenerateFeePayerRawTransactionArgs
150
- | GenerateMultiAgentRawTransactionArgs;
188
+ export type InputGenerateRawTransactionArgs =
189
+ | InputGenerateSingleSignerRawTransactionArgs
190
+ | InputGenerateFeePayerRawTransactionArgs
191
+ | InputGenerateMultiAgentRawTransactionArgs;
151
192
 
152
193
  /**
153
194
  * Interface that holds the return data when generating a single signer transaction
154
195
  *
155
196
  * @param rawTransaction a bcs serialized raw transaction
156
197
  */
157
- export interface SingleSignerTransaction {
198
+ export interface InputSingleSignerTransaction {
158
199
  rawTransaction: Uint8Array;
159
200
  feePayerAddress?: undefined;
160
201
  secondarySignerAddresses?: undefined;
@@ -167,7 +208,7 @@ export interface SingleSignerTransaction {
167
208
  * @param secondarySignerAddresses optional. secondary signer addresses for multi-agent transaction
168
209
  * @param feePayerAddress fee payer address for a fee payer transaction (aka Sponsored Transaction)
169
210
  */
170
- export interface FeePayerTransaction {
211
+ export interface InputFeePayerTransaction {
171
212
  rawTransaction: Uint8Array;
172
213
  feePayerAddress: AccountAddress;
173
214
  secondarySignerAddresses?: AccountAddress[];
@@ -179,7 +220,7 @@ export interface FeePayerTransaction {
179
220
  * @param rawTransaction a bcs serialized raw transaction
180
221
  * @param secondarySignerAddresses secondary signer addresses for multi-agent transaction
181
222
  */
182
- export interface MultiAgentTransaction {
223
+ export interface InputMultiAgentTransaction {
183
224
  rawTransaction: Uint8Array;
184
225
  secondarySignerAddresses: AccountAddress[];
185
226
  feePayerAddress?: undefined;
@@ -188,11 +229,11 @@ export interface MultiAgentTransaction {
188
229
  /**
189
230
  * Unified type that holds all the return interfaces when generating different transaction types
190
231
  */
191
- export type AnyRawTransaction = SingleSignerTransaction | FeePayerTransaction | MultiAgentTransaction;
232
+ export type AnyRawTransaction = InputSingleSignerTransaction | InputFeePayerTransaction | InputMultiAgentTransaction;
192
233
 
193
234
  // TRANSACTION SIMULATION TYPES //
194
235
 
195
- export type SimulateTransactionData = {
236
+ export type InputSimulateTransactionData = {
196
237
  /**
197
238
  * The transaction to simulate, probably generated by `generateTransaction()`
198
239
  */
@@ -209,10 +250,10 @@ export type SimulateTransactionData = {
209
250
  * For a fee payer transaction (aka Sponsored Transaction)
210
251
  */
211
252
  feePayerPublicKey?: PublicKey;
212
- options?: SimulateTransactionOptions;
253
+ options?: InputSimulateTransactionOptions;
213
254
  };
214
255
 
215
- export type SimulateTransactionOptions = {
256
+ export type InputSimulateTransactionOptions = {
216
257
  estimateGasUnitPrice?: boolean;
217
258
  estimateMaxGasAmount?: boolean;
218
259
  estimatePrioritizedGasUnitPrice?: boolean;
@@ -223,40 +264,40 @@ export type SimulateTransactionOptions = {
223
264
  /**
224
265
  * Interface that holds the user data input when generating a single signer transaction
225
266
  */
226
- export interface GenerateSingleSignerRawTransactionInput {
267
+ export interface InputGenerateSingleSignerRawTransactionData {
227
268
  sender: HexInput;
228
269
  feePayerAddress?: undefined;
229
270
  secondarySignerAddresses?: undefined;
230
- options?: GenerateTransactionOptions;
231
- data: GenerateTransactionPayloadData;
271
+ options?: InputGenerateTransactionOptions;
272
+ data: InputGenerateTransactionPayloadData;
232
273
  }
233
274
 
234
275
  /**
235
276
  * Interface that holds the user data input when generating a fee payer transaction
236
277
  */
237
- export interface GenerateFeePayerRawTransactionInput {
278
+ export interface InputGenerateFeePayerRawTransactionData {
238
279
  sender: HexInput;
239
280
  feePayerAddress: HexInput;
240
281
  secondarySignerAddresses?: HexInput[];
241
- options?: GenerateTransactionOptions;
242
- data: GenerateTransactionPayloadData;
282
+ options?: InputGenerateTransactionOptions;
283
+ data: InputGenerateTransactionPayloadData;
243
284
  }
244
285
 
245
286
  /**
246
287
  * Interface that holds the user data input when generating a multi-agent transaction
247
288
  */
248
- export interface GenerateMultiAgentRawTransactionInput {
289
+ export interface InputGenerateMultiAgentRawTransactionData {
249
290
  sender: HexInput;
250
291
  secondarySignerAddresses: HexInput[];
251
292
  feePayerAddress?: undefined;
252
- options?: GenerateTransactionOptions;
253
- data: GenerateTransactionPayloadData;
293
+ options?: InputGenerateTransactionOptions;
294
+ data: InputGenerateTransactionPayloadData;
254
295
  }
255
296
 
256
297
  /**
257
298
  * Unified type that holds all the user data input interfaces when generating different transaction types
258
299
  */
259
- export type GenerateTransactionInput =
260
- | GenerateMultiAgentRawTransactionInput
261
- | GenerateFeePayerRawTransactionInput
262
- | GenerateSingleSignerRawTransactionInput;
300
+ export type InputGenerateTransactionData =
301
+ | InputGenerateMultiAgentRawTransactionData
302
+ | InputGenerateFeePayerRawTransactionData
303
+ | InputGenerateSingleSignerRawTransactionData;
@@ -26,7 +26,7 @@ export enum MimeType {
26
26
  export type HexInput = string | Uint8Array;
27
27
 
28
28
  /**
29
- * Script transaction arguments enum as they are represented in Rust
29
+ * TypeTag enum as they are represented in Rust
30
30
  * {@link https://github.com/aptos-labs/aptos-core/blob/main/third_party/move/move-core/types/src/language_storage.rs#L27}
31
31
  */
32
32
  export enum TypeTagVariants {
@@ -41,6 +41,8 @@ export enum TypeTagVariants {
41
41
  U16 = 8,
42
42
  U32 = 9,
43
43
  U256 = 10,
44
+ Reference = 254, // This is specifically a placeholder and does not represent a real type
45
+ Generic = 255, // This is specifically a placeholder and does not represent a real type
44
46
  }
45
47
 
46
48
  /**
@@ -87,7 +89,7 @@ export enum TransactionAuthenticatorVariant {
87
89
  MultiEd25519 = 1,
88
90
  MultiAgent = 2,
89
91
  FeePayer = 3,
90
- SingleSenderTransactionAuthenticator = 4,
92
+ SingleSender = 4,
91
93
  }
92
94
 
93
95
  /**
@@ -248,7 +250,7 @@ export type GasEstimation = {
248
250
  };
249
251
 
250
252
  export type MoveResource = {
251
- type: MoveResourceType;
253
+ type: MoveStructType;
252
254
  data: {};
253
255
  };
254
256
 
@@ -517,7 +519,7 @@ export type TransactionPayloadResponse = EntryFunctionPayloadResponse | ScriptPa
517
519
 
518
520
  export type EntryFunctionPayloadResponse = {
519
521
  type: string;
520
- function: MoveResourceType;
522
+ function: MoveStructType;
521
523
  /**
522
524
  * Type arguments of the function
523
525
  */
@@ -678,12 +680,11 @@ export type MoveUint128Type = string;
678
680
  export type MoveUint256Type = string;
679
681
  export type MoveAddressType = string;
680
682
  export type MoveObjectType = string;
681
- export type MoveStructType = `${string}::${string}::${string}`;
682
683
  export type MoveOptionType = MoveType | null | undefined;
683
684
  /**
684
- * String representation of a on-chain Move struct type.
685
+ * This is the format for a fully qualified struct, resource, or entry function in Move.
685
686
  */
686
- export type MoveResourceType = `${string}::${string}::${string}`;
687
+ export type MoveStructType = `${string}::${string}::${string}`;
687
688
 
688
689
  export type MoveType =
689
690
  | boolean
@@ -892,7 +893,7 @@ export type Block = {
892
893
  */
893
894
  export type ViewRequestData = {
894
895
  function: MoveStructType;
895
- typeArguments?: Array<MoveResourceType>;
896
+ typeArguments?: Array<MoveStructType>;
896
897
  functionArguments?: Array<MoveValue>;
897
898
  };
898
899
 
@@ -901,14 +902,14 @@ export type ViewRequestData = {
901
902
  /**
902
903
  * View request for the Move view function API
903
904
  *
904
- * `type MoveResourceType = ${string}::${string}::${string}`;
905
+ * `type MoveStructType = ${string}::${string}::${string}`;
905
906
  */
906
907
  export type ViewRequest = {
907
- function: MoveResourceType;
908
+ function: MoveStructType;
908
909
  /**
909
910
  * Type arguments of the function
910
911
  */
911
- type_arguments: Array<MoveResourceType>;
912
+ type_arguments: Array<MoveStructType>;
912
913
  /**
913
914
  * Arguments of the function
914
915
  */
@@ -947,6 +948,8 @@ export enum SigningScheme {
947
948
  * For SingleKey ecdsa
948
949
  */
949
950
  SingleKey = 2,
951
+
952
+ MultiKey = 3,
950
953
  }
951
954
 
952
955
  export enum SigningSchemeInput {
@@ -954,10 +957,6 @@ export enum SigningSchemeInput {
954
957
  * For Ed25519PublicKey
955
958
  */
956
959
  Ed25519 = 0,
957
- /**
958
- * For MultiEd25519PublicKey
959
- */
960
- MultiEd25519 = 1,
961
960
  /**
962
961
  * For Secp256k1Ecdsa
963
962
  */
@@ -990,6 +989,9 @@ export enum DeriveScheme {
990
989
  DeriveResourceAccountAddress = 255,
991
990
  }
992
991
 
992
+ /**
993
+ * Option properties to pass for waitForTransaction() function
994
+ */
993
995
  export type WaitForTransactionOptions = {
994
996
  timeoutSecs?: number;
995
997
  checkSuccess?: boolean;
@@ -1002,7 +1004,7 @@ export type WaitForTransactionOptions = {
1002
1004
  * In this case `legacy` is always true
1003
1005
  */
1004
1006
  export type GenerateAccountWithLegacyKey = {
1005
- scheme?: SigningSchemeInput.Ed25519 | SigningSchemeInput.MultiEd25519;
1007
+ scheme?: SigningSchemeInput.Ed25519;
1006
1008
  legacy: true;
1007
1009
  };
1008
1010