@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.
- package/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/browser/index.global.js +410 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/cjs/index.d.ts +4965 -0
- package/dist/cjs/index.js +4762 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.ts +4965 -0
- package/dist/esm/index.mjs +4645 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +1247 -0
- package/dist/types/index.js +151 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +79 -0
- package/src/api/account.ts +360 -0
- package/src/api/aptos.ts +103 -0
- package/src/api/aptosConfig.ts +77 -0
- package/src/api/coin.ts +39 -0
- package/src/api/digitalAsset.ts +192 -0
- package/src/api/event.ts +78 -0
- package/src/api/faucet.ts +30 -0
- package/src/api/fungibleAsset.ts +82 -0
- package/src/api/general.ts +188 -0
- package/src/api/index.ts +5 -0
- package/src/api/staking.ts +58 -0
- package/src/api/transaction.ts +135 -0
- package/src/api/transactionSubmission.ts +168 -0
- package/src/bcs/consts.ts +12 -0
- package/src/bcs/deserializer.ts +248 -0
- package/src/bcs/index.ts +9 -0
- package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
- package/src/bcs/serializable/fixedBytes.ts +65 -0
- package/src/bcs/serializable/movePrimitives.ts +211 -0
- package/src/bcs/serializable/moveStructs.ts +462 -0
- package/src/bcs/serializer.ts +353 -0
- package/src/client/core.ts +106 -0
- package/src/client/get.ts +109 -0
- package/src/client/index.ts +7 -0
- package/src/client/post.ts +90 -0
- package/src/client/types.ts +58 -0
- package/src/core/account.ts +180 -0
- package/src/core/accountAddress.ts +407 -0
- package/src/core/authenticationKey.ts +102 -0
- package/src/core/common.ts +40 -0
- package/src/core/crypto/asymmetricCrypto.ts +77 -0
- package/src/core/crypto/ed25519.ts +224 -0
- package/src/core/crypto/index.ts +7 -0
- package/src/core/crypto/multiEd25519.ts +251 -0
- package/src/core/crypto/secp256k1.ts +227 -0
- package/src/core/hex.ts +177 -0
- package/src/core/index.ts +9 -0
- package/src/index.ts +12 -0
- package/src/internal/account.ts +484 -0
- package/src/internal/coin.ts +32 -0
- package/src/internal/digitalAsset.ts +302 -0
- package/src/internal/event.ts +88 -0
- package/src/internal/faucet.ts +41 -0
- package/src/internal/fungibleAsset.ts +114 -0
- package/src/internal/general.ts +160 -0
- package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
- package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
- package/src/internal/queries/getAccountCoinCount.graphql +7 -0
- package/src/internal/queries/getAccountCoinsData.graphql +32 -0
- package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
- package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
- package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
- package/src/internal/queries/getAccountTokensCount.graphql +7 -0
- package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
- package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
- package/src/internal/queries/getCollectionData.graphql +20 -0
- package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
- package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
- package/src/internal/queries/getEvents.graphql +12 -0
- package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
- package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
- package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
- package/src/internal/queries/getProcessorStatus.graphql +7 -0
- package/src/internal/queries/getTokenActivity.graphql +11 -0
- package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
- package/src/internal/queries/getTokenData.graphql +38 -0
- package/src/internal/staking.ts +68 -0
- package/src/internal/transaction.ts +245 -0
- package/src/internal/transactionSubmission.ts +162 -0
- package/src/transactions/authenticator/account.ts +121 -0
- package/src/transactions/authenticator/transaction.ts +222 -0
- package/src/transactions/instances/chainId.ts +26 -0
- package/src/transactions/instances/identifier.ts +28 -0
- package/src/transactions/instances/index.ts +9 -0
- package/src/transactions/instances/moduleId.ts +53 -0
- package/src/transactions/instances/rawTransaction.ts +199 -0
- package/src/transactions/instances/signedTransaction.ts +43 -0
- package/src/transactions/instances/transactionArgument.ts +37 -0
- package/src/transactions/instances/transactionPayload.ts +407 -0
- package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
- package/src/transactions/typeTag/typeTag.ts +487 -0
- package/src/transactions/types.ts +262 -0
- package/src/types/codegen.yaml +33 -0
- package/src/types/generated/operations.ts +623 -0
- package/src/types/generated/queries.ts +737 -0
- package/src/types/generated/types.ts +10387 -0
- package/src/types/index.ts +944 -0
- package/src/types/indexer.ts +93 -0
- package/src/utils/apiEndpoints.ts +36 -0
- package/src/utils/const.ts +51 -0
- package/src/utils/hdKey.ts +113 -0
- package/src/utils/helpers.ts +12 -0
- package/src/utils/memoize.ts +68 -0
- package/src/version.ts +9 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
|
|
6
|
+
import { AccountAuthenticator } from "./account";
|
|
7
|
+
import { Deserializer, Serializer } from "../../bcs";
|
|
8
|
+
import { AccountAddress } from "../../core";
|
|
9
|
+
import { Ed25519PublicKey, Ed25519Signature } from "../../core/crypto/ed25519";
|
|
10
|
+
import { MultiEd25519PublicKey, MultiEd25519Signature } from "../../core/crypto/multiEd25519";
|
|
11
|
+
import { Secp256k1PublicKey, Secp256k1Signature } from "../../core/crypto/secp256k1";
|
|
12
|
+
import { TransactionAuthenticatorVariant } from "../../types";
|
|
13
|
+
|
|
14
|
+
export abstract class TransactionAuthenticator {
|
|
15
|
+
abstract serialize(serializer: Serializer): void;
|
|
16
|
+
|
|
17
|
+
static deserialize(deserializer: Deserializer): TransactionAuthenticator {
|
|
18
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
19
|
+
switch (index) {
|
|
20
|
+
case TransactionAuthenticatorVariant.Ed25519:
|
|
21
|
+
return TransactionAuthenticatorEd25519.load(deserializer);
|
|
22
|
+
case TransactionAuthenticatorVariant.MultiEd25519:
|
|
23
|
+
return TransactionAuthenticatorMultiEd25519.load(deserializer);
|
|
24
|
+
case TransactionAuthenticatorVariant.MultiAgent:
|
|
25
|
+
return TransactionAuthenticatorMultiAgent.load(deserializer);
|
|
26
|
+
case TransactionAuthenticatorVariant.FeePayer:
|
|
27
|
+
return TransactionAuthenticatorFeePayer.load(deserializer);
|
|
28
|
+
case TransactionAuthenticatorVariant.Secp256k1Ecdsa:
|
|
29
|
+
return TransactionAuthenticatorSecp256k1.load(deserializer);
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`Unknown variant index for TransactionAuthenticator: ${index}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Transaction authenticator Ed25519 for a single signer transaction
|
|
38
|
+
*
|
|
39
|
+
* @param public_key Client's public key.
|
|
40
|
+
* @param signature Ed25519 signature of a raw transaction.
|
|
41
|
+
* @see {@link https://aptos.dev/integration/creating-a-signed-transaction | Creating a Signed Transaction}
|
|
42
|
+
* for details about generating a signature.
|
|
43
|
+
*/
|
|
44
|
+
export class TransactionAuthenticatorEd25519 extends TransactionAuthenticator {
|
|
45
|
+
public readonly public_key: Ed25519PublicKey;
|
|
46
|
+
|
|
47
|
+
public readonly signature: Ed25519Signature;
|
|
48
|
+
|
|
49
|
+
constructor(public_key: Ed25519PublicKey, signature: Ed25519Signature) {
|
|
50
|
+
super();
|
|
51
|
+
this.public_key = public_key;
|
|
52
|
+
this.signature = signature;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
serialize(serializer: Serializer): void {
|
|
56
|
+
serializer.serializeU32AsUleb128(TransactionAuthenticatorVariant.Ed25519);
|
|
57
|
+
this.public_key.serialize(serializer);
|
|
58
|
+
this.signature.serialize(serializer);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static load(deserializer: Deserializer): TransactionAuthenticatorEd25519 {
|
|
62
|
+
const public_key = Ed25519PublicKey.deserialize(deserializer);
|
|
63
|
+
const signature = Ed25519Signature.deserialize(deserializer);
|
|
64
|
+
return new TransactionAuthenticatorEd25519(public_key, signature);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Transaction authenticator Ed25519 for a multi signers transaction
|
|
70
|
+
*
|
|
71
|
+
* @param public_key Client's public key.
|
|
72
|
+
* @param signature Multi Ed25519 signature of a raw transaction.
|
|
73
|
+
*
|
|
74
|
+
*/
|
|
75
|
+
export class TransactionAuthenticatorMultiEd25519 extends TransactionAuthenticator {
|
|
76
|
+
public readonly public_key: MultiEd25519PublicKey;
|
|
77
|
+
|
|
78
|
+
public readonly signature: MultiEd25519Signature;
|
|
79
|
+
|
|
80
|
+
constructor(public_key: MultiEd25519PublicKey, signature: MultiEd25519Signature) {
|
|
81
|
+
super();
|
|
82
|
+
this.public_key = public_key;
|
|
83
|
+
this.signature = signature;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
serialize(serializer: Serializer): void {
|
|
87
|
+
serializer.serializeU32AsUleb128(TransactionAuthenticatorVariant.MultiEd25519);
|
|
88
|
+
this.public_key.serialize(serializer);
|
|
89
|
+
this.signature.serialize(serializer);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
static load(deserializer: Deserializer): TransactionAuthenticatorMultiEd25519 {
|
|
93
|
+
const public_key = MultiEd25519PublicKey.deserialize(deserializer);
|
|
94
|
+
const signature = MultiEd25519Signature.deserialize(deserializer);
|
|
95
|
+
return new TransactionAuthenticatorMultiEd25519(public_key, signature);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Transaction authenticator for a multi-agent transaction
|
|
101
|
+
*
|
|
102
|
+
* @param sender Sender account authenticator
|
|
103
|
+
* @param secondary_signer_addresses Secondary signers address
|
|
104
|
+
* @param secondary_signers Secondary signers account authenticators
|
|
105
|
+
*
|
|
106
|
+
*/
|
|
107
|
+
export class TransactionAuthenticatorMultiAgent extends TransactionAuthenticator {
|
|
108
|
+
public readonly sender: AccountAuthenticator;
|
|
109
|
+
|
|
110
|
+
public readonly secondary_signer_addresses: Array<AccountAddress>;
|
|
111
|
+
|
|
112
|
+
public readonly secondary_signers: Array<AccountAuthenticator>;
|
|
113
|
+
|
|
114
|
+
constructor(
|
|
115
|
+
sender: AccountAuthenticator,
|
|
116
|
+
secondary_signer_addresses: Array<AccountAddress>,
|
|
117
|
+
secondary_signers: Array<AccountAuthenticator>,
|
|
118
|
+
) {
|
|
119
|
+
super();
|
|
120
|
+
this.sender = sender;
|
|
121
|
+
this.secondary_signer_addresses = secondary_signer_addresses;
|
|
122
|
+
this.secondary_signers = secondary_signers;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
serialize(serializer: Serializer): void {
|
|
126
|
+
serializer.serializeU32AsUleb128(TransactionAuthenticatorVariant.MultiAgent);
|
|
127
|
+
this.sender.serialize(serializer);
|
|
128
|
+
serializer.serializeVector<AccountAddress>(this.secondary_signer_addresses);
|
|
129
|
+
serializer.serializeVector<AccountAuthenticator>(this.secondary_signers);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static load(deserializer: Deserializer): TransactionAuthenticatorMultiAgent {
|
|
133
|
+
const sender = AccountAuthenticator.deserialize(deserializer);
|
|
134
|
+
const secondary_signer_addresses = deserializer.deserializeVector(AccountAddress);
|
|
135
|
+
const secondary_signers = deserializer.deserializeVector(AccountAuthenticator);
|
|
136
|
+
return new TransactionAuthenticatorMultiAgent(sender, secondary_signer_addresses, secondary_signers);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Transaction authenticator for a fee payer transaction
|
|
142
|
+
*
|
|
143
|
+
* @param sender Sender account authenticator
|
|
144
|
+
* @param secondary_signer_addresses Secondary signers address
|
|
145
|
+
* @param secondary_signers Secondary signers account authenticators
|
|
146
|
+
* @param fee_payer Object of the fee payer account address and the fee payer authentication
|
|
147
|
+
*
|
|
148
|
+
*/
|
|
149
|
+
export class TransactionAuthenticatorFeePayer extends TransactionAuthenticator {
|
|
150
|
+
public readonly sender: AccountAuthenticator;
|
|
151
|
+
|
|
152
|
+
public readonly secondary_signer_addresses: Array<AccountAddress>;
|
|
153
|
+
|
|
154
|
+
public readonly secondary_signers: Array<AccountAuthenticator>;
|
|
155
|
+
|
|
156
|
+
public readonly fee_payer: {
|
|
157
|
+
address: AccountAddress;
|
|
158
|
+
authenticator: AccountAuthenticator;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
constructor(
|
|
162
|
+
sender: AccountAuthenticator,
|
|
163
|
+
secondary_signer_addresses: Array<AccountAddress>,
|
|
164
|
+
secondary_signers: Array<AccountAuthenticator>,
|
|
165
|
+
fee_payer: { address: AccountAddress; authenticator: AccountAuthenticator },
|
|
166
|
+
) {
|
|
167
|
+
super();
|
|
168
|
+
this.sender = sender;
|
|
169
|
+
this.secondary_signer_addresses = secondary_signer_addresses;
|
|
170
|
+
this.secondary_signers = secondary_signers;
|
|
171
|
+
this.fee_payer = fee_payer;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
serialize(serializer: Serializer): void {
|
|
175
|
+
serializer.serializeU32AsUleb128(TransactionAuthenticatorVariant.FeePayer);
|
|
176
|
+
this.sender.serialize(serializer);
|
|
177
|
+
serializer.serializeVector<AccountAddress>(this.secondary_signer_addresses);
|
|
178
|
+
serializer.serializeVector<AccountAuthenticator>(this.secondary_signers);
|
|
179
|
+
this.fee_payer.address.serialize(serializer);
|
|
180
|
+
this.fee_payer.authenticator.serialize(serializer);
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
static load(deserializer: Deserializer): TransactionAuthenticatorMultiAgent {
|
|
184
|
+
const sender = AccountAuthenticator.deserialize(deserializer);
|
|
185
|
+
const secondary_signer_addresses = deserializer.deserializeVector(AccountAddress);
|
|
186
|
+
const secondary_signers = deserializer.deserializeVector(AccountAuthenticator);
|
|
187
|
+
const address = AccountAddress.deserialize(deserializer);
|
|
188
|
+
const authenticator = AccountAuthenticator.deserialize(deserializer);
|
|
189
|
+
const fee_payer = { address, authenticator };
|
|
190
|
+
return new TransactionAuthenticatorFeePayer(sender, secondary_signer_addresses, secondary_signers, fee_payer);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Transaction authenticator Secp256k1 for a single signer transaction
|
|
196
|
+
*
|
|
197
|
+
* @param public_key Client's public key
|
|
198
|
+
* @param signature Secp256k1 signature of a `RawTransaction`
|
|
199
|
+
*/
|
|
200
|
+
export class TransactionAuthenticatorSecp256k1 extends TransactionAuthenticator {
|
|
201
|
+
public readonly public_key: Secp256k1PublicKey;
|
|
202
|
+
|
|
203
|
+
public readonly signature: Secp256k1Signature;
|
|
204
|
+
|
|
205
|
+
constructor(public_key: Secp256k1PublicKey, signature: Secp256k1Signature) {
|
|
206
|
+
super();
|
|
207
|
+
this.public_key = public_key;
|
|
208
|
+
this.signature = signature;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
serialize(serializer: Serializer): void {
|
|
212
|
+
serializer.serializeU32AsUleb128(TransactionAuthenticatorVariant.Secp256k1Ecdsa);
|
|
213
|
+
this.public_key.serialize(serializer);
|
|
214
|
+
this.signature.serialize(serializer);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
static load(deserializer: Deserializer): TransactionAuthenticatorSecp256k1 {
|
|
218
|
+
const public_key = Secp256k1PublicKey.deserialize(deserializer);
|
|
219
|
+
const signature = Secp256k1Signature.deserialize(deserializer);
|
|
220
|
+
return new TransactionAuthenticatorSecp256k1(public_key, signature);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Serializer, Serializable } from "../../bcs/serializer";
|
|
5
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Representation of a ChainId that can serialized and deserialized
|
|
9
|
+
*/
|
|
10
|
+
export class ChainId extends Serializable {
|
|
11
|
+
public readonly chainId: number;
|
|
12
|
+
|
|
13
|
+
constructor(chainId: number) {
|
|
14
|
+
super();
|
|
15
|
+
this.chainId = chainId;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
serialize(serializer: Serializer): void {
|
|
19
|
+
serializer.serializeU8(this.chainId);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static deserialize(deserializer: Deserializer): ChainId {
|
|
23
|
+
const chainId = deserializer.deserializeU8();
|
|
24
|
+
return new ChainId(chainId);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
5
|
+
import { Serializable, Serializer } from "../../bcs/serializer";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Representation of an Identifier that can serialized and deserialized.
|
|
9
|
+
* We use Identifier to represent the module "name" in "ModuleId" and
|
|
10
|
+
* the "function name" in "EntryFunction"
|
|
11
|
+
*/
|
|
12
|
+
export class Identifier extends Serializable {
|
|
13
|
+
public identifier: string;
|
|
14
|
+
|
|
15
|
+
constructor(identifier: string) {
|
|
16
|
+
super();
|
|
17
|
+
this.identifier = identifier;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public serialize(serializer: Serializer): void {
|
|
21
|
+
serializer.serializeStr(this.identifier);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static deserialize(deserializer: Deserializer): Identifier {
|
|
25
|
+
const identifier = deserializer.deserializeStr();
|
|
26
|
+
return new Identifier(identifier);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export * from "./chainId";
|
|
5
|
+
export * from "./identifier";
|
|
6
|
+
export * from "./moduleId";
|
|
7
|
+
export * from "./rawTransaction";
|
|
8
|
+
export * from "./transactionArgument";
|
|
9
|
+
export * from "./transactionPayload";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Serializable, Serializer } from "../../bcs/serializer";
|
|
5
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
6
|
+
import { AccountAddress } from "../../core";
|
|
7
|
+
import { Identifier } from "./identifier";
|
|
8
|
+
import { MoveModuleId } from "../../types";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Representation of a ModuleId that can serialized and deserialized
|
|
12
|
+
* ModuleId means the module address (e.g "0x1") and the module name (e.g "coin")
|
|
13
|
+
*/
|
|
14
|
+
export class ModuleId extends Serializable {
|
|
15
|
+
public readonly address: AccountAddress;
|
|
16
|
+
|
|
17
|
+
public readonly name: Identifier;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Full name of a module.
|
|
21
|
+
* @param address The account address. e.g "0x1"
|
|
22
|
+
* @param name The module name under the "address". e.g "coin"
|
|
23
|
+
*/
|
|
24
|
+
constructor(address: AccountAddress, name: Identifier) {
|
|
25
|
+
super();
|
|
26
|
+
this.address = address;
|
|
27
|
+
this.name = name;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Converts a string literal to a ModuleId
|
|
32
|
+
* @param moduleId String literal in format "account_address::module_name", e.g. "0x1::coin"
|
|
33
|
+
* @returns ModuleId
|
|
34
|
+
*/
|
|
35
|
+
static fromStr(moduleId: MoveModuleId): ModuleId {
|
|
36
|
+
const parts = moduleId.split("::");
|
|
37
|
+
if (parts.length !== 2) {
|
|
38
|
+
throw new Error("Invalid module id.");
|
|
39
|
+
}
|
|
40
|
+
return new ModuleId(AccountAddress.fromString(parts[0]), new Identifier(parts[1]));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
serialize(serializer: Serializer): void {
|
|
44
|
+
this.address.serialize(serializer);
|
|
45
|
+
this.name.serialize(serializer);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
static deserialize(deserializer: Deserializer): ModuleId {
|
|
49
|
+
const address = AccountAddress.deserialize(deserializer);
|
|
50
|
+
const name = Identifier.deserialize(deserializer);
|
|
51
|
+
return new ModuleId(address, name);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
|
|
6
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
7
|
+
import { Serializable, Serializer } from "../../bcs/serializer";
|
|
8
|
+
import { ChainId } from "./chainId";
|
|
9
|
+
import { AccountAddress } from "../../core";
|
|
10
|
+
import { TransactionPayload } from "./transactionPayload";
|
|
11
|
+
import { TransactionVariants } from "../../types";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Representation of a Raw Transaction that can serialized and deserialized
|
|
15
|
+
*/
|
|
16
|
+
export class RawTransaction extends Serializable {
|
|
17
|
+
public readonly sender: AccountAddress;
|
|
18
|
+
|
|
19
|
+
public readonly sequence_number: bigint;
|
|
20
|
+
|
|
21
|
+
public readonly payload: TransactionPayload;
|
|
22
|
+
|
|
23
|
+
public readonly max_gas_amount: bigint;
|
|
24
|
+
|
|
25
|
+
public readonly gas_unit_price: bigint;
|
|
26
|
+
|
|
27
|
+
public readonly expiration_timestamp_secs: bigint;
|
|
28
|
+
|
|
29
|
+
public readonly chain_id: ChainId;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* RawTransactions contain the metadata and payloads that can be submitted to Aptos chain for execution.
|
|
33
|
+
* RawTransactions must be signed before Aptos chain can execute them.
|
|
34
|
+
*
|
|
35
|
+
* @param sender The sender Account Address
|
|
36
|
+
* @param sequence_number Sequence number of this transaction. This must match the sequence number stored in
|
|
37
|
+
* the sender's account at the time the transaction executes.
|
|
38
|
+
* @param payload Instructions for the Aptos Blockchain, including publishing a module,
|
|
39
|
+
* execute an entry function or execute a script payload.
|
|
40
|
+
* @param max_gas_amount Maximum total gas to spend for this transaction. The account must have more
|
|
41
|
+
* than this gas or the transaction will be discarded during validation.
|
|
42
|
+
* @param gas_unit_price Price to be paid per gas unit.
|
|
43
|
+
* @param expiration_timestamp_secs The blockchain timestamp at which the blockchain would discard this transaction.
|
|
44
|
+
* @param chain_id The chain ID of the blockchain that this transaction is intended to be run on.
|
|
45
|
+
*/
|
|
46
|
+
constructor(
|
|
47
|
+
sender: AccountAddress,
|
|
48
|
+
sequence_number: bigint,
|
|
49
|
+
payload: TransactionPayload,
|
|
50
|
+
max_gas_amount: bigint,
|
|
51
|
+
gas_unit_price: bigint,
|
|
52
|
+
expiration_timestamp_secs: bigint,
|
|
53
|
+
chain_id: ChainId,
|
|
54
|
+
) {
|
|
55
|
+
super();
|
|
56
|
+
this.sender = sender;
|
|
57
|
+
this.sequence_number = sequence_number;
|
|
58
|
+
this.payload = payload;
|
|
59
|
+
this.max_gas_amount = max_gas_amount;
|
|
60
|
+
this.gas_unit_price = gas_unit_price;
|
|
61
|
+
this.expiration_timestamp_secs = expiration_timestamp_secs;
|
|
62
|
+
this.chain_id = chain_id;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
serialize(serializer: Serializer): void {
|
|
66
|
+
this.sender.serialize(serializer);
|
|
67
|
+
serializer.serializeU64(this.sequence_number);
|
|
68
|
+
this.payload.serialize(serializer);
|
|
69
|
+
serializer.serializeU64(this.max_gas_amount);
|
|
70
|
+
serializer.serializeU64(this.gas_unit_price);
|
|
71
|
+
serializer.serializeU64(this.expiration_timestamp_secs);
|
|
72
|
+
this.chain_id.serialize(serializer);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
static deserialize(deserializer: Deserializer): RawTransaction {
|
|
76
|
+
const sender = AccountAddress.deserialize(deserializer);
|
|
77
|
+
const sequence_number = deserializer.deserializeU64();
|
|
78
|
+
const payload = TransactionPayload.deserialize(deserializer);
|
|
79
|
+
const max_gas_amount = deserializer.deserializeU64();
|
|
80
|
+
const gas_unit_price = deserializer.deserializeU64();
|
|
81
|
+
const expiration_timestamp_secs = deserializer.deserializeU64();
|
|
82
|
+
const chain_id = ChainId.deserialize(deserializer);
|
|
83
|
+
return new RawTransaction(
|
|
84
|
+
sender,
|
|
85
|
+
sequence_number,
|
|
86
|
+
payload,
|
|
87
|
+
max_gas_amount,
|
|
88
|
+
gas_unit_price,
|
|
89
|
+
expiration_timestamp_secs,
|
|
90
|
+
chain_id,
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Representation of a Raw Transaction With Data that can serialized and deserialized
|
|
97
|
+
*/
|
|
98
|
+
export abstract class RawTransactionWithData extends Serializable {
|
|
99
|
+
/**
|
|
100
|
+
* Serialize a Raw Transaction With Data
|
|
101
|
+
*/
|
|
102
|
+
abstract serialize(serializer: Serializer): void;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Deserialize a Raw Transaction With Data
|
|
106
|
+
*/
|
|
107
|
+
static deserialize(deserializer: Deserializer): RawTransactionWithData {
|
|
108
|
+
// index enum variant
|
|
109
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
110
|
+
switch (index) {
|
|
111
|
+
case TransactionVariants.MultiAgentTransaction:
|
|
112
|
+
return MultiAgentRawTransaction.load(deserializer);
|
|
113
|
+
case TransactionVariants.FeePayerTransaction:
|
|
114
|
+
return FeePayerRawTransaction.load(deserializer);
|
|
115
|
+
default:
|
|
116
|
+
throw new Error(`Unknown variant index for RawTransactionWithData: ${index}`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Representation of a Multi Agent Transaction that can serialized and deserialized
|
|
123
|
+
*/
|
|
124
|
+
export class MultiAgentRawTransaction extends RawTransactionWithData {
|
|
125
|
+
/**
|
|
126
|
+
* The raw transaction
|
|
127
|
+
*/
|
|
128
|
+
public readonly raw_txn: RawTransaction;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* The secondary signers on this transaction
|
|
132
|
+
*/
|
|
133
|
+
public readonly secondary_signer_addresses: Array<AccountAddress>;
|
|
134
|
+
|
|
135
|
+
constructor(raw_txn: RawTransaction, secondary_signer_addresses: Array<AccountAddress>) {
|
|
136
|
+
super();
|
|
137
|
+
this.raw_txn = raw_txn;
|
|
138
|
+
this.secondary_signer_addresses = secondary_signer_addresses;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
serialize(serializer: Serializer): void {
|
|
142
|
+
serializer.serializeU32AsUleb128(TransactionVariants.MultiAgentTransaction);
|
|
143
|
+
this.raw_txn.serialize(serializer);
|
|
144
|
+
serializer.serializeVector(this.secondary_signer_addresses);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
static load(deserializer: Deserializer): MultiAgentRawTransaction {
|
|
148
|
+
const rawTxn = RawTransaction.deserialize(deserializer);
|
|
149
|
+
const secondarySignerAddresses = deserializer.deserializeVector(AccountAddress);
|
|
150
|
+
|
|
151
|
+
return new MultiAgentRawTransaction(rawTxn, secondarySignerAddresses);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Representation of a Fee Payer Transaction that can serialized and deserialized
|
|
157
|
+
*/
|
|
158
|
+
export class FeePayerRawTransaction extends RawTransactionWithData {
|
|
159
|
+
/**
|
|
160
|
+
* The raw transaction
|
|
161
|
+
*/
|
|
162
|
+
public readonly raw_txn: RawTransaction;
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* The secondary signers on this transaction - optional and can be empty
|
|
166
|
+
*/
|
|
167
|
+
public readonly secondary_signer_addresses: Array<AccountAddress>;
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* The fee payer account address
|
|
171
|
+
*/
|
|
172
|
+
public readonly fee_payer_address: AccountAddress;
|
|
173
|
+
|
|
174
|
+
constructor(
|
|
175
|
+
raw_txn: RawTransaction,
|
|
176
|
+
secondary_signer_addresses: Array<AccountAddress>,
|
|
177
|
+
fee_payer_address: AccountAddress,
|
|
178
|
+
) {
|
|
179
|
+
super();
|
|
180
|
+
this.raw_txn = raw_txn;
|
|
181
|
+
this.secondary_signer_addresses = secondary_signer_addresses;
|
|
182
|
+
this.fee_payer_address = fee_payer_address;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
serialize(serializer: Serializer): void {
|
|
186
|
+
serializer.serializeU32AsUleb128(TransactionVariants.FeePayerTransaction);
|
|
187
|
+
this.raw_txn.serialize(serializer);
|
|
188
|
+
serializer.serializeVector(this.secondary_signer_addresses);
|
|
189
|
+
this.fee_payer_address.serialize(serializer);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static load(deserializer: Deserializer): FeePayerRawTransaction {
|
|
193
|
+
const rawTxn = RawTransaction.deserialize(deserializer);
|
|
194
|
+
const secondarySignerAddresses = deserializer.deserializeVector(AccountAddress);
|
|
195
|
+
const feePayerAddress = AccountAddress.deserialize(deserializer);
|
|
196
|
+
|
|
197
|
+
return new FeePayerRawTransaction(rawTxn, secondarySignerAddresses, feePayerAddress);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
5
|
+
|
|
6
|
+
import { TransactionAuthenticator } from "../authenticator/transaction";
|
|
7
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
8
|
+
import { Serializable, Serializer } from "../../bcs/serializer";
|
|
9
|
+
import { RawTransaction } from "./rawTransaction";
|
|
10
|
+
|
|
11
|
+
export class SignedTransaction extends Serializable {
|
|
12
|
+
public readonly raw_txn: RawTransaction;
|
|
13
|
+
|
|
14
|
+
public readonly authenticator: TransactionAuthenticator;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A SignedTransaction consists of a raw transaction and an authenticator. The authenticator
|
|
18
|
+
* contains a client's public key and the signature of the raw transaction.
|
|
19
|
+
*
|
|
20
|
+
* @see {@link https://aptos.dev/integration/creating-a-signed-transaction | Creating a Signed Transaction}
|
|
21
|
+
*
|
|
22
|
+
* @param raw_txn
|
|
23
|
+
* @param authenticator Contains a client's public key and the signature of the raw transaction.
|
|
24
|
+
* Authenticator has 3 flavors: single signature, multi-signature and multi-agent.
|
|
25
|
+
* @see {@link https://github.com/aptos-labs/aptos-core/blob/main/types/src/transaction/authenticator.rs} for details.
|
|
26
|
+
*/
|
|
27
|
+
constructor(raw_txn: RawTransaction, authenticator: TransactionAuthenticator) {
|
|
28
|
+
super();
|
|
29
|
+
this.raw_txn = raw_txn;
|
|
30
|
+
this.authenticator = authenticator;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
serialize(serializer: Serializer): void {
|
|
34
|
+
this.raw_txn.serialize(serializer);
|
|
35
|
+
this.authenticator.serialize(serializer);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static deserialize(deserializer: Deserializer): SignedTransaction {
|
|
39
|
+
const raw_txn = RawTransaction.deserialize(deserializer);
|
|
40
|
+
const authenticator = TransactionAuthenticator.deserialize(deserializer);
|
|
41
|
+
return new SignedTransaction(raw_txn, authenticator);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { Serializer } from "../../bcs/serializer";
|
|
5
|
+
import { Hex } from "../../core/hex";
|
|
6
|
+
|
|
7
|
+
export interface TransactionArgument extends EntryFunctionArgument, ScriptFunctionArgument {}
|
|
8
|
+
|
|
9
|
+
export interface EntryFunctionArgument {
|
|
10
|
+
/**
|
|
11
|
+
* Serialize an argument to BCS-serialized bytes.
|
|
12
|
+
*/
|
|
13
|
+
serialize(serializer: Serializer): void;
|
|
14
|
+
/**
|
|
15
|
+
* Serialize an argument as a type-agnostic, fixed byte sequence. The byte sequence contains
|
|
16
|
+
* the number of the following bytes followed by the BCS-serialized bytes for a typed argument.
|
|
17
|
+
*/
|
|
18
|
+
serializeForEntryFunction(serializer: Serializer): void;
|
|
19
|
+
|
|
20
|
+
bcsToBytes(): Uint8Array;
|
|
21
|
+
bcsToHex(): Hex;
|
|
22
|
+
}
|
|
23
|
+
export interface ScriptFunctionArgument {
|
|
24
|
+
/**
|
|
25
|
+
* Serialize an argument to BCS-serialized bytes.
|
|
26
|
+
*/
|
|
27
|
+
serialize(serializer: Serializer): void;
|
|
28
|
+
/**
|
|
29
|
+
* Serialize an argument to BCS-serialized bytes as a type aware byte sequence.
|
|
30
|
+
* The byte sequence contains an enum variant index followed by the BCS-serialized
|
|
31
|
+
* bytes for a typed argument.
|
|
32
|
+
*/
|
|
33
|
+
serializeForScriptFunction(serializer: Serializer): void;
|
|
34
|
+
|
|
35
|
+
bcsToBytes(): Uint8Array;
|
|
36
|
+
bcsToHex(): Hex;
|
|
37
|
+
}
|