@aptos-labs/ts-sdk 0.0.1 → 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.
- package/README.md +32 -24
- package/dist/browser/index.global.js +25 -25
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.d.ts +809 -184
- package/dist/cjs/index.js +1458 -616
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +809 -184
- package/dist/esm/index.mjs +1388 -614
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +72 -25
- package/dist/types/index.js +28 -3
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/account.ts +2 -2
- package/src/api/coin.ts +5 -5
- package/src/api/digitalAsset.ts +5 -5
- package/src/api/event.ts +2 -2
- package/src/api/faucet.ts +7 -3
- package/src/api/transactionSubmission.ts +24 -24
- package/src/bcs/serializable/fixedBytes.ts +1 -1
- package/src/bcs/serializable/moveStructs.ts +16 -36
- package/src/core/account.ts +12 -8
- package/src/core/accountAddress.ts +4 -2
- package/src/core/authenticationKey.ts +24 -2
- package/src/core/crypto/anyPublicKey.ts +14 -18
- package/src/core/crypto/ed25519.ts +6 -0
- package/src/core/crypto/index.ts +1 -0
- package/src/core/crypto/multiKey.ts +122 -0
- package/src/core/crypto/secp256k1.ts +2 -0
- package/src/index.ts +1 -2
- package/src/internal/account.ts +5 -5
- package/src/internal/coin.ts +8 -8
- package/src/internal/digitalAsset.ts +7 -7
- package/src/internal/event.ts +2 -2
- package/src/internal/faucet.ts +9 -5
- package/src/internal/transactionSubmission.ts +40 -15
- package/src/transactions/authenticator/account.ts +39 -0
- package/src/transactions/authenticator/index.ts +5 -0
- package/src/transactions/authenticator/transaction.ts +6 -6
- package/src/transactions/index.ts +9 -0
- package/src/transactions/instances/index.ts +1 -0
- package/src/transactions/instances/transactionPayload.ts +13 -8
- package/src/transactions/transactionBuilder/helpers.ts +99 -0
- package/src/transactions/transactionBuilder/index.ts +6 -0
- package/src/transactions/transactionBuilder/remoteAbi.ts +339 -0
- package/src/transactions/{transaction_builder/transaction_builder.ts → transactionBuilder/transactionBuilder.ts} +149 -68
- package/src/transactions/typeTag/index.ts +385 -0
- package/src/transactions/typeTag/parser.ts +21 -8
- package/src/transactions/types.ts +87 -46
- package/src/types/index.ts +18 -16
- package/src/transactions/typeTag/typeTag.ts +0 -487
package/dist/esm/index.mjs
CHANGED
|
@@ -24,7 +24,7 @@ var AptosApiError = class extends Error {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
// src/version.ts
|
|
27
|
-
var VERSION = "
|
|
27
|
+
var VERSION = "2.0.0";
|
|
28
28
|
|
|
29
29
|
// src/types/index.ts
|
|
30
30
|
var MimeType = /* @__PURE__ */ ((MimeType2) => {
|
|
@@ -45,6 +45,8 @@ var TypeTagVariants = /* @__PURE__ */ ((TypeTagVariants2) => {
|
|
|
45
45
|
TypeTagVariants2[TypeTagVariants2["U16"] = 8] = "U16";
|
|
46
46
|
TypeTagVariants2[TypeTagVariants2["U32"] = 9] = "U32";
|
|
47
47
|
TypeTagVariants2[TypeTagVariants2["U256"] = 10] = "U256";
|
|
48
|
+
TypeTagVariants2[TypeTagVariants2["Reference"] = 254] = "Reference";
|
|
49
|
+
TypeTagVariants2[TypeTagVariants2["Generic"] = 255] = "Generic";
|
|
48
50
|
return TypeTagVariants2;
|
|
49
51
|
})(TypeTagVariants || {});
|
|
50
52
|
var ScriptTransactionArgumentVariants = /* @__PURE__ */ ((ScriptTransactionArgumentVariants2) => {
|
|
@@ -75,15 +77,26 @@ var TransactionAuthenticatorVariant = /* @__PURE__ */ ((TransactionAuthenticator
|
|
|
75
77
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
76
78
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiAgent"] = 2] = "MultiAgent";
|
|
77
79
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["FeePayer"] = 3] = "FeePayer";
|
|
78
|
-
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["
|
|
80
|
+
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["SingleSender"] = 4] = "SingleSender";
|
|
79
81
|
return TransactionAuthenticatorVariant2;
|
|
80
82
|
})(TransactionAuthenticatorVariant || {});
|
|
81
83
|
var AccountAuthenticatorVariant = /* @__PURE__ */ ((AccountAuthenticatorVariant2) => {
|
|
82
84
|
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Ed25519"] = 0] = "Ed25519";
|
|
83
85
|
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
84
|
-
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["
|
|
86
|
+
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["SingleKey"] = 2] = "SingleKey";
|
|
87
|
+
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiKey"] = 3] = "MultiKey";
|
|
85
88
|
return AccountAuthenticatorVariant2;
|
|
86
89
|
})(AccountAuthenticatorVariant || {});
|
|
90
|
+
var AnyPublicKeyVariant = /* @__PURE__ */ ((AnyPublicKeyVariant2) => {
|
|
91
|
+
AnyPublicKeyVariant2[AnyPublicKeyVariant2["Ed25519"] = 0] = "Ed25519";
|
|
92
|
+
AnyPublicKeyVariant2[AnyPublicKeyVariant2["Secp256k1"] = 1] = "Secp256k1";
|
|
93
|
+
return AnyPublicKeyVariant2;
|
|
94
|
+
})(AnyPublicKeyVariant || {});
|
|
95
|
+
var AnySignatureVariant = /* @__PURE__ */ ((AnySignatureVariant2) => {
|
|
96
|
+
AnySignatureVariant2[AnySignatureVariant2["Ed25519"] = 0] = "Ed25519";
|
|
97
|
+
AnySignatureVariant2[AnySignatureVariant2["Secp256k1"] = 1] = "Secp256k1";
|
|
98
|
+
return AnySignatureVariant2;
|
|
99
|
+
})(AnySignatureVariant || {});
|
|
87
100
|
var TransactionResponseType = /* @__PURE__ */ ((TransactionResponseType2) => {
|
|
88
101
|
TransactionResponseType2["Pending"] = "pending_transaction";
|
|
89
102
|
TransactionResponseType2["User"] = "user_transaction";
|
|
@@ -113,9 +126,15 @@ var RoleType = /* @__PURE__ */ ((RoleType2) => {
|
|
|
113
126
|
var SigningScheme = /* @__PURE__ */ ((SigningScheme2) => {
|
|
114
127
|
SigningScheme2[SigningScheme2["Ed25519"] = 0] = "Ed25519";
|
|
115
128
|
SigningScheme2[SigningScheme2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
116
|
-
SigningScheme2[SigningScheme2["
|
|
129
|
+
SigningScheme2[SigningScheme2["SingleKey"] = 2] = "SingleKey";
|
|
130
|
+
SigningScheme2[SigningScheme2["MultiKey"] = 3] = "MultiKey";
|
|
117
131
|
return SigningScheme2;
|
|
118
132
|
})(SigningScheme || {});
|
|
133
|
+
var SigningSchemeInput = /* @__PURE__ */ ((SigningSchemeInput2) => {
|
|
134
|
+
SigningSchemeInput2[SigningSchemeInput2["Ed25519"] = 0] = "Ed25519";
|
|
135
|
+
SigningSchemeInput2[SigningSchemeInput2["Secp256k1Ecdsa"] = 2] = "Secp256k1Ecdsa";
|
|
136
|
+
return SigningSchemeInput2;
|
|
137
|
+
})(SigningSchemeInput || {});
|
|
119
138
|
var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
|
|
120
139
|
DeriveScheme2[DeriveScheme2["DeriveAuid"] = 251] = "DeriveAuid";
|
|
121
140
|
DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromObject"] = 252] = "DeriveObjectAddressFromObject";
|
|
@@ -170,14 +189,15 @@ async function aptosRequest(options, aptosConfig) {
|
|
|
170
189
|
url: fullUrl
|
|
171
190
|
};
|
|
172
191
|
if (aptosConfig.isIndexerRequest(url)) {
|
|
173
|
-
|
|
192
|
+
const indexerResponse = result.data;
|
|
193
|
+
if (indexerResponse.errors) {
|
|
174
194
|
throw new AptosApiError(
|
|
175
195
|
options,
|
|
176
196
|
result,
|
|
177
|
-
(_a =
|
|
197
|
+
(_a = indexerResponse.errors[0].message) != null ? _a : `Unhandled Error ${response.status} : ${response.statusText}`
|
|
178
198
|
);
|
|
179
199
|
}
|
|
180
|
-
result.data =
|
|
200
|
+
result.data = indexerResponse.data;
|
|
181
201
|
}
|
|
182
202
|
if (result.status >= 200 && result.status < 300) {
|
|
183
203
|
return result;
|
|
@@ -245,7 +265,7 @@ async function get(options) {
|
|
|
245
265
|
acceptType: acceptType == null ? void 0 : acceptType.valueOf(),
|
|
246
266
|
params,
|
|
247
267
|
overrides: {
|
|
248
|
-
...aptosConfig,
|
|
268
|
+
...aptosConfig.clientConfig,
|
|
249
269
|
...overrides
|
|
250
270
|
}
|
|
251
271
|
},
|
|
@@ -293,7 +313,7 @@ async function post(options) {
|
|
|
293
313
|
acceptType: acceptType == null ? void 0 : acceptType.valueOf(),
|
|
294
314
|
params,
|
|
295
315
|
overrides: {
|
|
296
|
-
...aptosConfig,
|
|
316
|
+
...aptosConfig.clientConfig,
|
|
297
317
|
...overrides
|
|
298
318
|
}
|
|
299
319
|
},
|
|
@@ -692,6 +712,7 @@ var _AccountAddress = class extends Serializable {
|
|
|
692
712
|
var AccountAddress = _AccountAddress;
|
|
693
713
|
AccountAddress.LENGTH = 32;
|
|
694
714
|
AccountAddress.LONG_STRING_LENGTH = 64;
|
|
715
|
+
AccountAddress.ZERO = _AccountAddress.fromString("0x0");
|
|
695
716
|
AccountAddress.ONE = _AccountAddress.fromString("0x1");
|
|
696
717
|
AccountAddress.TWO = _AccountAddress.fromString("0x2");
|
|
697
718
|
AccountAddress.THREE = _AccountAddress.fromString("0x3");
|
|
@@ -1120,29 +1141,6 @@ var MoveOption = class extends Serializable {
|
|
|
1120
1141
|
return new MoveOption(vector.values[0]);
|
|
1121
1142
|
}
|
|
1122
1143
|
};
|
|
1123
|
-
var MoveObject = class extends Serializable {
|
|
1124
|
-
constructor(value) {
|
|
1125
|
-
super();
|
|
1126
|
-
if (value instanceof AccountAddress) {
|
|
1127
|
-
this.value = value;
|
|
1128
|
-
} else {
|
|
1129
|
-
this.value = AccountAddress.fromHexInputRelaxed(value);
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
serialize(serializer) {
|
|
1133
|
-
serializer.serialize(this.value);
|
|
1134
|
-
}
|
|
1135
|
-
serializeForEntryFunction(serializer) {
|
|
1136
|
-
this.value.serializeForEntryFunction(serializer);
|
|
1137
|
-
}
|
|
1138
|
-
serializeForScriptFunction(serializer) {
|
|
1139
|
-
this.value.serializeForScriptFunction(serializer);
|
|
1140
|
-
}
|
|
1141
|
-
static deserialize(deserializer) {
|
|
1142
|
-
const address = deserializer.deserialize(AccountAddress);
|
|
1143
|
-
return new MoveObject(address);
|
|
1144
|
-
}
|
|
1145
|
-
};
|
|
1146
1144
|
|
|
1147
1145
|
// src/core/crypto/asymmetricCrypto.ts
|
|
1148
1146
|
var PublicKey = class extends Serializable {
|
|
@@ -1181,6 +1179,10 @@ var _Ed25519PublicKey = class extends PublicKey {
|
|
|
1181
1179
|
const bytes = deserializer.deserializeBytes();
|
|
1182
1180
|
return new _Ed25519PublicKey(bytes);
|
|
1183
1181
|
}
|
|
1182
|
+
static load(deserializer) {
|
|
1183
|
+
const bytes = deserializer.deserializeBytes();
|
|
1184
|
+
return new _Ed25519PublicKey(bytes);
|
|
1185
|
+
}
|
|
1184
1186
|
};
|
|
1185
1187
|
var Ed25519PublicKey = _Ed25519PublicKey;
|
|
1186
1188
|
Ed25519PublicKey.LENGTH = 32;
|
|
@@ -1244,6 +1246,10 @@ var _Ed25519Signature = class extends Signature {
|
|
|
1244
1246
|
const bytes = deserializer.deserializeBytes();
|
|
1245
1247
|
return new _Ed25519Signature(bytes);
|
|
1246
1248
|
}
|
|
1249
|
+
static load(deserializer) {
|
|
1250
|
+
const bytes = deserializer.deserializeBytes();
|
|
1251
|
+
return new _Ed25519Signature(bytes);
|
|
1252
|
+
}
|
|
1247
1253
|
};
|
|
1248
1254
|
var Ed25519Signature = _Ed25519Signature;
|
|
1249
1255
|
Ed25519Signature.LENGTH = 64;
|
|
@@ -1394,6 +1400,10 @@ var _Secp256k1PublicKey = class extends PublicKey {
|
|
|
1394
1400
|
const bytes = deserializer.deserializeBytes();
|
|
1395
1401
|
return new _Secp256k1PublicKey(bytes);
|
|
1396
1402
|
}
|
|
1403
|
+
static load(deserializer) {
|
|
1404
|
+
const bytes = deserializer.deserializeBytes();
|
|
1405
|
+
return new _Secp256k1PublicKey(bytes);
|
|
1406
|
+
}
|
|
1397
1407
|
};
|
|
1398
1408
|
var Secp256k1PublicKey = _Secp256k1PublicKey;
|
|
1399
1409
|
Secp256k1PublicKey.LENGTH = 65;
|
|
@@ -1441,7 +1451,7 @@ var _Secp256k1Signature = class extends Signature {
|
|
|
1441
1451
|
super();
|
|
1442
1452
|
const hex = Hex.fromHexInput(hexInput);
|
|
1443
1453
|
if (hex.toUint8Array().length !== _Secp256k1Signature.LENGTH) {
|
|
1444
|
-
throw new Error(`Signature length should be ${_Secp256k1Signature.LENGTH}`);
|
|
1454
|
+
throw new Error(`Signature length should be ${_Secp256k1Signature.LENGTH}, recieved ${hex.toUint8Array().length}`);
|
|
1445
1455
|
}
|
|
1446
1456
|
this.data = hex;
|
|
1447
1457
|
}
|
|
@@ -1458,13 +1468,122 @@ var _Secp256k1Signature = class extends Signature {
|
|
|
1458
1468
|
const hex = deserializer.deserializeBytes();
|
|
1459
1469
|
return new _Secp256k1Signature(hex);
|
|
1460
1470
|
}
|
|
1471
|
+
static load(deserializer) {
|
|
1472
|
+
const bytes = deserializer.deserializeBytes();
|
|
1473
|
+
return new _Secp256k1Signature(bytes);
|
|
1474
|
+
}
|
|
1461
1475
|
};
|
|
1462
1476
|
var Secp256k1Signature = _Secp256k1Signature;
|
|
1463
1477
|
Secp256k1Signature.LENGTH = 64;
|
|
1464
1478
|
|
|
1479
|
+
// src/core/crypto/anyPublicKey.ts
|
|
1480
|
+
var AnyPublicKey = class extends PublicKey {
|
|
1481
|
+
constructor(publicKey) {
|
|
1482
|
+
super();
|
|
1483
|
+
this.publicKey = publicKey;
|
|
1484
|
+
}
|
|
1485
|
+
toUint8Array() {
|
|
1486
|
+
return this.publicKey.toUint8Array();
|
|
1487
|
+
}
|
|
1488
|
+
toString() {
|
|
1489
|
+
return this.publicKey.toString();
|
|
1490
|
+
}
|
|
1491
|
+
verifySignature(args) {
|
|
1492
|
+
const { message, signature } = args;
|
|
1493
|
+
return this.publicKey.verifySignature({ message, signature });
|
|
1494
|
+
}
|
|
1495
|
+
serialize(serializer) {
|
|
1496
|
+
if (this.publicKey instanceof Ed25519PublicKey) {
|
|
1497
|
+
serializer.serializeU32AsUleb128(0 /* Ed25519 */);
|
|
1498
|
+
this.publicKey.serialize(serializer);
|
|
1499
|
+
} else if (this.publicKey instanceof Secp256k1PublicKey) {
|
|
1500
|
+
serializer.serializeU32AsUleb128(1 /* Secp256k1 */);
|
|
1501
|
+
this.publicKey.serialize(serializer);
|
|
1502
|
+
} else {
|
|
1503
|
+
throw new Error("Unknown public key type");
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
static deserialize(deserializer) {
|
|
1507
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
1508
|
+
switch (index) {
|
|
1509
|
+
case 0 /* Ed25519 */:
|
|
1510
|
+
return new AnyPublicKey(Ed25519PublicKey.load(deserializer));
|
|
1511
|
+
case 1 /* Secp256k1 */:
|
|
1512
|
+
return new AnyPublicKey(Secp256k1PublicKey.load(deserializer));
|
|
1513
|
+
default:
|
|
1514
|
+
throw new Error(`Unknown variant index for AnyPublicKey: ${index}`);
|
|
1515
|
+
}
|
|
1516
|
+
}
|
|
1517
|
+
};
|
|
1518
|
+
|
|
1519
|
+
// src/core/crypto/multiKey.ts
|
|
1520
|
+
var MultiKey = class extends PublicKey {
|
|
1521
|
+
constructor(args) {
|
|
1522
|
+
super();
|
|
1523
|
+
const { publicKeys, signaturesRequired } = args;
|
|
1524
|
+
if (signaturesRequired < 1) {
|
|
1525
|
+
throw new Error("The number of required signatures needs to be greater then 0");
|
|
1526
|
+
}
|
|
1527
|
+
if (publicKeys.length < signaturesRequired) {
|
|
1528
|
+
throw new Error(
|
|
1529
|
+
`Provided ${publicKeys.length} public keys is smaller than the ${signaturesRequired} required signatures`
|
|
1530
|
+
);
|
|
1531
|
+
}
|
|
1532
|
+
const keys = [];
|
|
1533
|
+
publicKeys.forEach((publicKey) => {
|
|
1534
|
+
if (publicKey instanceof AnyPublicKey) {
|
|
1535
|
+
keys.push(publicKey);
|
|
1536
|
+
} else {
|
|
1537
|
+
keys.push(new AnyPublicKey(publicKey));
|
|
1538
|
+
}
|
|
1539
|
+
});
|
|
1540
|
+
this.publicKeys = keys;
|
|
1541
|
+
this.signaturesRequired = signaturesRequired;
|
|
1542
|
+
}
|
|
1543
|
+
toUint8Array() {
|
|
1544
|
+
return this.bcsToBytes();
|
|
1545
|
+
}
|
|
1546
|
+
createBitmap(args) {
|
|
1547
|
+
const { bits } = args;
|
|
1548
|
+
const firstBitInByte = 128;
|
|
1549
|
+
const bitmap = new Uint8Array([0, 0, 0, 0]);
|
|
1550
|
+
const dupCheckSet = /* @__PURE__ */ new Set();
|
|
1551
|
+
bits.forEach((bit, idx) => {
|
|
1552
|
+
if (idx + 1 > this.publicKeys.length) {
|
|
1553
|
+
throw new Error(`Signature index ${idx + 1} is out of public keys range, ${this.publicKeys.length}.`);
|
|
1554
|
+
}
|
|
1555
|
+
if (dupCheckSet.has(bit)) {
|
|
1556
|
+
throw new Error(`Duplicate bit ${bit} detected.`);
|
|
1557
|
+
}
|
|
1558
|
+
dupCheckSet.add(bit);
|
|
1559
|
+
const byteOffset = Math.floor(bit / 8);
|
|
1560
|
+
let byte = bitmap[byteOffset];
|
|
1561
|
+
byte |= firstBitInByte >> bit % 8;
|
|
1562
|
+
bitmap[byteOffset] = byte;
|
|
1563
|
+
});
|
|
1564
|
+
return bitmap;
|
|
1565
|
+
}
|
|
1566
|
+
toString() {
|
|
1567
|
+
return Hex.fromHexInput(this.toUint8Array()).toString();
|
|
1568
|
+
}
|
|
1569
|
+
verifySignature(args) {
|
|
1570
|
+
throw new Error("not implemented");
|
|
1571
|
+
}
|
|
1572
|
+
serialize(serializer) {
|
|
1573
|
+
serializer.serializeVector(this.publicKeys);
|
|
1574
|
+
serializer.serializeU8(this.signaturesRequired);
|
|
1575
|
+
}
|
|
1576
|
+
static deserialize(deserializer) {
|
|
1577
|
+
const keys = deserializer.deserializeVector(AnyPublicKey);
|
|
1578
|
+
const signaturesRequired = deserializer.deserializeU8();
|
|
1579
|
+
return new MultiKey({ publicKeys: keys, signaturesRequired });
|
|
1580
|
+
}
|
|
1581
|
+
};
|
|
1582
|
+
|
|
1465
1583
|
// src/core/authenticationKey.ts
|
|
1466
|
-
var _AuthenticationKey = class {
|
|
1584
|
+
var _AuthenticationKey = class extends Serializable {
|
|
1467
1585
|
constructor(args) {
|
|
1586
|
+
super();
|
|
1468
1587
|
const { data } = args;
|
|
1469
1588
|
const hex = Hex.fromHexInput(data);
|
|
1470
1589
|
if (hex.toUint8Array().length !== _AuthenticationKey.LENGTH) {
|
|
@@ -1472,21 +1591,43 @@ var _AuthenticationKey = class {
|
|
|
1472
1591
|
}
|
|
1473
1592
|
this.data = hex;
|
|
1474
1593
|
}
|
|
1594
|
+
serialize(serializer) {
|
|
1595
|
+
serializer.serializeFixedBytes(this.data.toUint8Array());
|
|
1596
|
+
}
|
|
1597
|
+
static deserialize(deserializer) {
|
|
1598
|
+
const bytes = deserializer.deserializeFixedBytes(_AuthenticationKey.LENGTH);
|
|
1599
|
+
return new _AuthenticationKey({ data: bytes });
|
|
1600
|
+
}
|
|
1475
1601
|
toString() {
|
|
1476
1602
|
return this.data.toString();
|
|
1477
1603
|
}
|
|
1478
1604
|
toUint8Array() {
|
|
1479
1605
|
return this.data.toUint8Array();
|
|
1480
1606
|
}
|
|
1481
|
-
static
|
|
1482
|
-
const {
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1607
|
+
static fromPublicKeyAndScheme(args) {
|
|
1608
|
+
const { publicKey, scheme } = args;
|
|
1609
|
+
let authKeyBytes;
|
|
1610
|
+
switch (scheme) {
|
|
1611
|
+
case 3 /* MultiKey */:
|
|
1612
|
+
case 2 /* SingleKey */: {
|
|
1613
|
+
const singleKeyBytes = publicKey.bcsToBytes();
|
|
1614
|
+
authKeyBytes = new Uint8Array([...singleKeyBytes, scheme]);
|
|
1615
|
+
break;
|
|
1616
|
+
}
|
|
1617
|
+
case 0 /* Ed25519 */:
|
|
1618
|
+
case 1 /* MultiEd25519 */: {
|
|
1619
|
+
const ed25519PublicKeyBytes = publicKey.toUint8Array();
|
|
1620
|
+
const inputBytes = Hex.fromHexInput(ed25519PublicKeyBytes).toUint8Array();
|
|
1621
|
+
authKeyBytes = new Uint8Array([...inputBytes, scheme]);
|
|
1622
|
+
break;
|
|
1623
|
+
}
|
|
1624
|
+
default:
|
|
1625
|
+
throw new Error(`Scheme ${scheme} is not supported`);
|
|
1626
|
+
}
|
|
1487
1627
|
const hash = sha3Hash.create();
|
|
1488
1628
|
hash.update(authKeyBytes);
|
|
1489
|
-
|
|
1629
|
+
const hashDigest = hash.digest();
|
|
1630
|
+
return new _AuthenticationKey({ data: hashDigest });
|
|
1490
1631
|
}
|
|
1491
1632
|
static fromPublicKey(args) {
|
|
1492
1633
|
const { publicKey } = args;
|
|
@@ -1495,13 +1636,14 @@ var _AuthenticationKey = class {
|
|
|
1495
1636
|
scheme = 0 /* Ed25519 */.valueOf();
|
|
1496
1637
|
} else if (publicKey instanceof MultiEd25519PublicKey) {
|
|
1497
1638
|
scheme = 1 /* MultiEd25519 */.valueOf();
|
|
1498
|
-
} else if (publicKey instanceof
|
|
1499
|
-
scheme = 2 /*
|
|
1639
|
+
} else if (publicKey instanceof AnyPublicKey) {
|
|
1640
|
+
scheme = 2 /* SingleKey */.valueOf();
|
|
1641
|
+
} else if (publicKey instanceof MultiKey) {
|
|
1642
|
+
scheme = 3 /* MultiKey */.valueOf();
|
|
1500
1643
|
} else {
|
|
1501
1644
|
throw new Error("No supported authentication scheme for public key");
|
|
1502
1645
|
}
|
|
1503
|
-
|
|
1504
|
-
return _AuthenticationKey.fromBytesAndScheme({ bytes: pubKeyBytes, scheme });
|
|
1646
|
+
return _AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme });
|
|
1505
1647
|
}
|
|
1506
1648
|
derivedAddress() {
|
|
1507
1649
|
return new AccountAddress({ data: this.data.toUint8Array() });
|
|
@@ -1559,50 +1701,58 @@ var derivePrivateKeyFromMnemonic = (keyType, path, seedPhrase, offset = HARDENED
|
|
|
1559
1701
|
// src/core/account.ts
|
|
1560
1702
|
var Account = class {
|
|
1561
1703
|
constructor(args) {
|
|
1562
|
-
const { privateKey, address } = args;
|
|
1704
|
+
const { privateKey, address, legacy } = args;
|
|
1563
1705
|
this.publicKey = privateKey.publicKey();
|
|
1564
1706
|
if (this.publicKey instanceof Ed25519PublicKey) {
|
|
1565
|
-
|
|
1707
|
+
if (legacy) {
|
|
1708
|
+
this.signingScheme = 0 /* Ed25519 */;
|
|
1709
|
+
} else {
|
|
1710
|
+
this.publicKey = new AnyPublicKey(this.publicKey);
|
|
1711
|
+
this.signingScheme = 2 /* SingleKey */;
|
|
1712
|
+
}
|
|
1566
1713
|
} else if (this.publicKey instanceof MultiEd25519PublicKey) {
|
|
1567
1714
|
this.signingScheme = 1 /* MultiEd25519 */;
|
|
1568
1715
|
} else if (this.publicKey instanceof Secp256k1PublicKey) {
|
|
1569
|
-
this.
|
|
1716
|
+
this.publicKey = new AnyPublicKey(this.publicKey);
|
|
1717
|
+
this.signingScheme = 2 /* SingleKey */;
|
|
1570
1718
|
} else {
|
|
1571
1719
|
throw new Error("Can not create new Account, unsupported public key type");
|
|
1572
1720
|
}
|
|
1573
1721
|
this.privateKey = privateKey;
|
|
1574
1722
|
this.accountAddress = address;
|
|
1575
1723
|
}
|
|
1576
|
-
static generate(
|
|
1724
|
+
static generate(args) {
|
|
1577
1725
|
let privateKey;
|
|
1578
|
-
switch (scheme) {
|
|
1726
|
+
switch (args == null ? void 0 : args.scheme) {
|
|
1579
1727
|
case 2 /* Secp256k1Ecdsa */:
|
|
1580
1728
|
privateKey = Secp256k1PrivateKey.generate();
|
|
1581
1729
|
break;
|
|
1582
1730
|
default:
|
|
1583
1731
|
privateKey = Ed25519PrivateKey.generate();
|
|
1584
1732
|
}
|
|
1733
|
+
let publicKey = privateKey.publicKey();
|
|
1734
|
+
if (!(args == null ? void 0 : args.legacy)) {
|
|
1735
|
+
publicKey = new AnyPublicKey(privateKey.publicKey());
|
|
1736
|
+
}
|
|
1585
1737
|
const address = new AccountAddress({
|
|
1586
1738
|
data: Account.authKey({
|
|
1587
|
-
publicKey
|
|
1739
|
+
publicKey
|
|
1588
1740
|
}).toUint8Array()
|
|
1589
1741
|
});
|
|
1590
|
-
return new Account({ privateKey, address });
|
|
1591
|
-
}
|
|
1592
|
-
static fromPrivateKey(privateKey) {
|
|
1593
|
-
const publicKey = privateKey.publicKey();
|
|
1594
|
-
const authKey = Account.authKey({ publicKey });
|
|
1595
|
-
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
1596
|
-
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
1742
|
+
return new Account({ privateKey, address, legacy: args == null ? void 0 : args.legacy });
|
|
1597
1743
|
}
|
|
1598
1744
|
static fromPrivateKeyAndAddress(args) {
|
|
1599
|
-
|
|
1745
|
+
const { privateKey, address, legacy } = args;
|
|
1746
|
+
return new Account({ privateKey, address, legacy });
|
|
1600
1747
|
}
|
|
1601
1748
|
static fromDerivationPath(args) {
|
|
1602
1749
|
const { path, mnemonic } = args;
|
|
1603
1750
|
const { key } = derivePrivateKeyFromMnemonic("ed25519 seed" /* ED25519 */, path, mnemonic);
|
|
1604
1751
|
const privateKey = new Ed25519PrivateKey(key);
|
|
1605
|
-
|
|
1752
|
+
const publicKey = privateKey.publicKey();
|
|
1753
|
+
const authKey = Account.authKey({ publicKey });
|
|
1754
|
+
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
1755
|
+
return new Account({ privateKey, address, legacy: true });
|
|
1606
1756
|
}
|
|
1607
1757
|
static authKey(args) {
|
|
1608
1758
|
const { publicKey } = args;
|
|
@@ -2099,7 +2249,7 @@ async function view(args) {
|
|
|
2099
2249
|
body: {
|
|
2100
2250
|
function: payload.function,
|
|
2101
2251
|
type_arguments: (_a = payload.typeArguments) != null ? _a : [],
|
|
2102
|
-
arguments: (_b = payload.
|
|
2252
|
+
arguments: (_b = payload.functionArguments) != null ? _b : []
|
|
2103
2253
|
}
|
|
2104
2254
|
});
|
|
2105
2255
|
return data;
|
|
@@ -2237,7 +2387,7 @@ async function getResource(args) {
|
|
|
2237
2387
|
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/resource/${resourceType}`,
|
|
2238
2388
|
params: { ledger_version: options == null ? void 0 : options.ledgerVersion }
|
|
2239
2389
|
});
|
|
2240
|
-
return data;
|
|
2390
|
+
return data.data;
|
|
2241
2391
|
}
|
|
2242
2392
|
async function lookupOriginalAccountAddress(args) {
|
|
2243
2393
|
const { aptosConfig, authenticationKey, options } = args;
|
|
@@ -2249,7 +2399,7 @@ async function lookupOriginalAccountAddress(args) {
|
|
|
2249
2399
|
});
|
|
2250
2400
|
const {
|
|
2251
2401
|
address_map: { handle }
|
|
2252
|
-
} = resource
|
|
2402
|
+
} = resource;
|
|
2253
2403
|
try {
|
|
2254
2404
|
const originalAddress = await getTableItem({
|
|
2255
2405
|
aptosConfig,
|
|
@@ -2455,6 +2605,55 @@ async function getAccountOwnedObjects(args) {
|
|
|
2455
2605
|
});
|
|
2456
2606
|
return data.current_objects;
|
|
2457
2607
|
}
|
|
2608
|
+
async function deriveAccountFromPrivateKey(args) {
|
|
2609
|
+
const { aptosConfig, privateKey } = args;
|
|
2610
|
+
const publicKey = new AnyPublicKey(privateKey.publicKey());
|
|
2611
|
+
if (privateKey instanceof Secp256k1PrivateKey) {
|
|
2612
|
+
const authKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: 2 /* SingleKey */ });
|
|
2613
|
+
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
2614
|
+
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
2615
|
+
}
|
|
2616
|
+
if (privateKey instanceof Ed25519PrivateKey) {
|
|
2617
|
+
const SingleSenderTransactionAuthenticatorAuthKey = AuthenticationKey.fromPublicKeyAndScheme({
|
|
2618
|
+
publicKey,
|
|
2619
|
+
scheme: 2 /* SingleKey */
|
|
2620
|
+
});
|
|
2621
|
+
const isSingleSenderTransactionAuthenticator = await isAccountExist({
|
|
2622
|
+
authKey: SingleSenderTransactionAuthenticatorAuthKey,
|
|
2623
|
+
aptosConfig
|
|
2624
|
+
});
|
|
2625
|
+
if (isSingleSenderTransactionAuthenticator) {
|
|
2626
|
+
const address = new AccountAddress({ data: SingleSenderTransactionAuthenticatorAuthKey.toUint8Array() });
|
|
2627
|
+
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
2628
|
+
}
|
|
2629
|
+
const legacyAuthKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: 0 /* Ed25519 */ });
|
|
2630
|
+
const isLegacyEd25519 = await isAccountExist({ authKey: legacyAuthKey, aptosConfig });
|
|
2631
|
+
if (isLegacyEd25519) {
|
|
2632
|
+
const address = new AccountAddress({ data: legacyAuthKey.toUint8Array() });
|
|
2633
|
+
return Account.fromPrivateKeyAndAddress({ privateKey, address, legacy: true });
|
|
2634
|
+
}
|
|
2635
|
+
}
|
|
2636
|
+
throw new Error(`Can't derive account from private key ${privateKey}`);
|
|
2637
|
+
}
|
|
2638
|
+
async function isAccountExist(args) {
|
|
2639
|
+
const { aptosConfig, authKey } = args;
|
|
2640
|
+
const accountAddress = await lookupOriginalAccountAddress({
|
|
2641
|
+
aptosConfig,
|
|
2642
|
+
authenticationKey: authKey.toString()
|
|
2643
|
+
});
|
|
2644
|
+
try {
|
|
2645
|
+
await getInfo({
|
|
2646
|
+
aptosConfig,
|
|
2647
|
+
accountAddress: accountAddress.toString()
|
|
2648
|
+
});
|
|
2649
|
+
return true;
|
|
2650
|
+
} catch (error) {
|
|
2651
|
+
if (error.status === 404) {
|
|
2652
|
+
return false;
|
|
2653
|
+
}
|
|
2654
|
+
throw new Error(`Error while looking for an account info ${accountAddress.toString()}`);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2458
2657
|
|
|
2459
2658
|
// src/api/account.ts
|
|
2460
2659
|
var Account2 = class {
|
|
@@ -2530,6 +2729,9 @@ var Account2 = class {
|
|
|
2530
2729
|
...args
|
|
2531
2730
|
});
|
|
2532
2731
|
}
|
|
2732
|
+
async deriveAccountFromPrivateKey(args) {
|
|
2733
|
+
return deriveAccountFromPrivateKey({ aptosConfig: this.config, ...args });
|
|
2734
|
+
}
|
|
2533
2735
|
};
|
|
2534
2736
|
|
|
2535
2737
|
// src/api/aptosConfig.ts
|
|
@@ -2573,445 +2775,105 @@ var AptosConfig = class {
|
|
|
2573
2775
|
}
|
|
2574
2776
|
};
|
|
2575
2777
|
|
|
2576
|
-
// src/transactions/
|
|
2577
|
-
|
|
2578
|
-
|
|
2778
|
+
// src/transactions/transactionBuilder/transactionBuilder.ts
|
|
2779
|
+
import { sha3_256 as sha3Hash2 } from "@noble/hashes/sha3";
|
|
2780
|
+
|
|
2781
|
+
// src/core/crypto/anySignature.ts
|
|
2782
|
+
var AnySignature = class extends Signature {
|
|
2783
|
+
constructor(signature) {
|
|
2579
2784
|
super();
|
|
2580
|
-
this.
|
|
2785
|
+
this.signature = signature;
|
|
2581
2786
|
}
|
|
2582
|
-
|
|
2583
|
-
|
|
2787
|
+
toUint8Array() {
|
|
2788
|
+
return this.signature.toUint8Array();
|
|
2584
2789
|
}
|
|
2585
|
-
|
|
2586
|
-
|
|
2587
|
-
|
|
2790
|
+
toString() {
|
|
2791
|
+
return this.signature.toString();
|
|
2792
|
+
}
|
|
2793
|
+
serialize(serializer) {
|
|
2794
|
+
if (this.signature instanceof Ed25519Signature) {
|
|
2795
|
+
serializer.serializeU32AsUleb128(0 /* Ed25519 */);
|
|
2796
|
+
this.signature.serialize(serializer);
|
|
2797
|
+
} else if (this.signature instanceof Secp256k1Signature) {
|
|
2798
|
+
serializer.serializeU32AsUleb128(1 /* Secp256k1 */);
|
|
2799
|
+
this.signature.serialize(serializer);
|
|
2800
|
+
} else {
|
|
2801
|
+
throw new Error("Unknown signature type");
|
|
2802
|
+
}
|
|
2588
2803
|
}
|
|
2589
|
-
};
|
|
2590
|
-
|
|
2591
|
-
// src/transactions/typeTag/typeTag.ts
|
|
2592
|
-
var TypeTag = class extends Serializable {
|
|
2593
2804
|
static deserialize(deserializer) {
|
|
2594
2805
|
const index = deserializer.deserializeUleb128AsU32();
|
|
2595
2806
|
switch (index) {
|
|
2596
|
-
case 0 /*
|
|
2597
|
-
return
|
|
2598
|
-
case 1 /*
|
|
2599
|
-
return
|
|
2600
|
-
case 2 /* U64 */:
|
|
2601
|
-
return TypeTagU64.load(deserializer);
|
|
2602
|
-
case 3 /* U128 */:
|
|
2603
|
-
return TypeTagU128.load(deserializer);
|
|
2604
|
-
case 4 /* Address */:
|
|
2605
|
-
return TypeTagAddress.load(deserializer);
|
|
2606
|
-
case 5 /* Signer */:
|
|
2607
|
-
return TypeTagSigner.load(deserializer);
|
|
2608
|
-
case 6 /* Vector */:
|
|
2609
|
-
return TypeTagVector.load(deserializer);
|
|
2610
|
-
case 7 /* Struct */:
|
|
2611
|
-
return TypeTagStruct.load(deserializer);
|
|
2612
|
-
case 8 /* U16 */:
|
|
2613
|
-
return TypeTagU16.load(deserializer);
|
|
2614
|
-
case 9 /* U32 */:
|
|
2615
|
-
return TypeTagU32.load(deserializer);
|
|
2616
|
-
case 10 /* U256 */:
|
|
2617
|
-
return TypeTagU256.load(deserializer);
|
|
2807
|
+
case 0 /* Ed25519 */:
|
|
2808
|
+
return new AnySignature(Ed25519Signature.load(deserializer));
|
|
2809
|
+
case 1 /* Secp256k1 */:
|
|
2810
|
+
return new AnySignature(Secp256k1Signature.load(deserializer));
|
|
2618
2811
|
default:
|
|
2619
|
-
throw new Error(`Unknown variant index for
|
|
2812
|
+
throw new Error(`Unknown variant index for AnySignature: ${index}`);
|
|
2620
2813
|
}
|
|
2621
2814
|
}
|
|
2622
2815
|
};
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
}
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
}
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
}
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
};
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
}
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2679
|
-
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
return new TypeTagAddress();
|
|
2685
|
-
}
|
|
2686
|
-
};
|
|
2687
|
-
var TypeTagSigner = class extends TypeTag {
|
|
2688
|
-
serialize(serializer) {
|
|
2689
|
-
serializer.serializeU32AsUleb128(5 /* Signer */);
|
|
2690
|
-
}
|
|
2691
|
-
static load(_deserializer) {
|
|
2692
|
-
return new TypeTagSigner();
|
|
2693
|
-
}
|
|
2694
|
-
};
|
|
2695
|
-
var TypeTagVector = class extends TypeTag {
|
|
2696
|
-
constructor(value) {
|
|
2697
|
-
super();
|
|
2698
|
-
this.value = value;
|
|
2699
|
-
}
|
|
2700
|
-
serialize(serializer) {
|
|
2701
|
-
serializer.serializeU32AsUleb128(6 /* Vector */);
|
|
2702
|
-
this.value.serialize(serializer);
|
|
2703
|
-
}
|
|
2704
|
-
static load(deserializer) {
|
|
2705
|
-
const value = TypeTag.deserialize(deserializer);
|
|
2706
|
-
return new TypeTagVector(value);
|
|
2707
|
-
}
|
|
2708
|
-
};
|
|
2709
|
-
var TypeTagStruct = class extends TypeTag {
|
|
2710
|
-
constructor(value) {
|
|
2711
|
-
super();
|
|
2712
|
-
this.value = value;
|
|
2713
|
-
}
|
|
2714
|
-
serialize(serializer) {
|
|
2715
|
-
serializer.serializeU32AsUleb128(7 /* Struct */);
|
|
2716
|
-
this.value.serialize(serializer);
|
|
2717
|
-
}
|
|
2718
|
-
static load(deserializer) {
|
|
2719
|
-
const value = StructTag.deserialize(deserializer);
|
|
2720
|
-
return new TypeTagStruct(value);
|
|
2721
|
-
}
|
|
2722
|
-
isStringTypeTag() {
|
|
2723
|
-
return this.value.module_name.identifier === "string" && this.value.name.identifier === "String" && this.value.address.toString() === AccountAddress.ONE.toString();
|
|
2724
|
-
}
|
|
2725
|
-
};
|
|
2726
|
-
var StructTag = class extends Serializable {
|
|
2727
|
-
constructor(address, module_name, name, type_args) {
|
|
2728
|
-
super();
|
|
2729
|
-
this.address = address;
|
|
2730
|
-
this.module_name = module_name;
|
|
2731
|
-
this.name = name;
|
|
2732
|
-
this.type_args = type_args;
|
|
2733
|
-
}
|
|
2734
|
-
static fromString(structTag) {
|
|
2735
|
-
const typeTagStruct = new TypeTagParser(structTag).parseTypeTag();
|
|
2736
|
-
return new StructTag(
|
|
2737
|
-
typeTagStruct.value.address,
|
|
2738
|
-
typeTagStruct.value.module_name,
|
|
2739
|
-
typeTagStruct.value.name,
|
|
2740
|
-
typeTagStruct.value.type_args
|
|
2741
|
-
);
|
|
2742
|
-
}
|
|
2743
|
-
serialize(serializer) {
|
|
2744
|
-
serializer.serialize(this.address);
|
|
2745
|
-
serializer.serialize(this.module_name);
|
|
2746
|
-
serializer.serialize(this.name);
|
|
2747
|
-
serializer.serializeVector(this.type_args);
|
|
2748
|
-
}
|
|
2749
|
-
static deserialize(deserializer) {
|
|
2750
|
-
const address = AccountAddress.deserialize(deserializer);
|
|
2751
|
-
const moduleName = Identifier.deserialize(deserializer);
|
|
2752
|
-
const name = Identifier.deserialize(deserializer);
|
|
2753
|
-
const typeArgs = deserializer.deserializeVector(TypeTag);
|
|
2754
|
-
return new StructTag(address, moduleName, name, typeArgs);
|
|
2755
|
-
}
|
|
2756
|
-
};
|
|
2757
|
-
var stringStructTag = () => new StructTag(AccountAddress.ONE, new Identifier("string"), new Identifier("String"), []);
|
|
2758
|
-
function optionStructTag(typeArg) {
|
|
2759
|
-
return new StructTag(AccountAddress.ONE, new Identifier("option"), new Identifier("Option"), [typeArg]);
|
|
2760
|
-
}
|
|
2761
|
-
function objectStructTag(typeArg) {
|
|
2762
|
-
return new StructTag(AccountAddress.ONE, new Identifier("object"), new Identifier("Object"), [typeArg]);
|
|
2763
|
-
}
|
|
2764
|
-
var TypeTagParser = class {
|
|
2765
|
-
constructor(tagStr, typeTags) {
|
|
2766
|
-
this.typeTags = [];
|
|
2767
|
-
this.tokens = tokenize(tagStr);
|
|
2768
|
-
this.typeTags = typeTags || [];
|
|
2769
|
-
}
|
|
2770
|
-
consume(targetToken) {
|
|
2771
|
-
const token = this.tokens.shift();
|
|
2772
|
-
if (!token || token[1] !== targetToken) {
|
|
2773
|
-
bail("Invalid type tag.");
|
|
2774
|
-
}
|
|
2775
|
-
}
|
|
2776
|
-
consumeWholeGeneric() {
|
|
2777
|
-
this.consume("<");
|
|
2778
|
-
while (this.tokens[0][1] !== ">") {
|
|
2779
|
-
if (this.tokens[0][1] === "<") {
|
|
2780
|
-
this.consumeWholeGeneric();
|
|
2781
|
-
} else {
|
|
2782
|
-
this.tokens.shift();
|
|
2783
|
-
}
|
|
2784
|
-
}
|
|
2785
|
-
this.consume(">");
|
|
2786
|
-
}
|
|
2787
|
-
parseCommaList(endToken, allowTrailingComma) {
|
|
2788
|
-
const res = [];
|
|
2789
|
-
if (this.tokens.length <= 0) {
|
|
2790
|
-
bail("Invalid type tag.");
|
|
2791
|
-
}
|
|
2792
|
-
while (this.tokens[0][1] !== endToken) {
|
|
2793
|
-
res.push(this.parseTypeTag());
|
|
2794
|
-
if (this.tokens.length > 0 && this.tokens[0][1] === endToken) {
|
|
2795
|
-
break;
|
|
2796
|
-
}
|
|
2797
|
-
this.consume(",");
|
|
2798
|
-
if (this.tokens.length > 0 && this.tokens[0][1] === endToken && allowTrailingComma) {
|
|
2799
|
-
break;
|
|
2800
|
-
}
|
|
2801
|
-
if (this.tokens.length <= 0) {
|
|
2802
|
-
bail("Invalid type tag.");
|
|
2803
|
-
}
|
|
2804
|
-
}
|
|
2805
|
-
return res;
|
|
2806
|
-
}
|
|
2807
|
-
parseTypeTag() {
|
|
2808
|
-
if (this.tokens.length === 0) {
|
|
2809
|
-
bail("Invalid type tag.");
|
|
2810
|
-
}
|
|
2811
|
-
const [tokenTy, tokenVal] = this.tokens.shift();
|
|
2812
|
-
if (tokenVal === "u8") {
|
|
2813
|
-
return new TypeTagU8();
|
|
2814
|
-
}
|
|
2815
|
-
if (tokenVal === "u16") {
|
|
2816
|
-
return new TypeTagU16();
|
|
2817
|
-
}
|
|
2818
|
-
if (tokenVal === "u32") {
|
|
2819
|
-
return new TypeTagU32();
|
|
2820
|
-
}
|
|
2821
|
-
if (tokenVal === "u64") {
|
|
2822
|
-
return new TypeTagU64();
|
|
2823
|
-
}
|
|
2824
|
-
if (tokenVal === "u128") {
|
|
2825
|
-
return new TypeTagU128();
|
|
2826
|
-
}
|
|
2827
|
-
if (tokenVal === "u256") {
|
|
2828
|
-
return new TypeTagU256();
|
|
2829
|
-
}
|
|
2830
|
-
if (tokenVal === "bool") {
|
|
2831
|
-
return new TypeTagBool();
|
|
2832
|
-
}
|
|
2833
|
-
if (tokenVal === "address") {
|
|
2834
|
-
return new TypeTagAddress();
|
|
2835
|
-
}
|
|
2836
|
-
if (tokenVal === "vector") {
|
|
2837
|
-
this.consume("<");
|
|
2838
|
-
const res = this.parseTypeTag();
|
|
2839
|
-
this.consume(">");
|
|
2840
|
-
return new TypeTagVector(res);
|
|
2841
|
-
}
|
|
2842
|
-
if (tokenVal === "string") {
|
|
2843
|
-
return new TypeTagStruct(stringStructTag());
|
|
2844
|
-
}
|
|
2845
|
-
if (tokenTy === "IDENT" && (tokenVal.startsWith("0x") || tokenVal.startsWith("0X"))) {
|
|
2846
|
-
const address = AccountAddress.fromHexInput(tokenVal);
|
|
2847
|
-
this.consume("::");
|
|
2848
|
-
const [moduleTokenTy, module] = this.tokens.shift();
|
|
2849
|
-
if (moduleTokenTy !== "IDENT") {
|
|
2850
|
-
bail("Invalid type tag.");
|
|
2851
|
-
}
|
|
2852
|
-
this.consume("::");
|
|
2853
|
-
const [nameTokenTy, name] = this.tokens.shift();
|
|
2854
|
-
if (nameTokenTy !== "IDENT") {
|
|
2855
|
-
bail("Invalid type tag.");
|
|
2856
|
-
}
|
|
2857
|
-
if (AccountAddress.ONE.toString() === address.toString() && module === "object" && name === "Object") {
|
|
2858
|
-
this.consumeWholeGeneric();
|
|
2859
|
-
return new TypeTagAddress();
|
|
2860
|
-
}
|
|
2861
|
-
let tyTags = [];
|
|
2862
|
-
if (this.tokens.length > 0 && this.tokens[0][1] === "<") {
|
|
2863
|
-
this.consume("<");
|
|
2864
|
-
tyTags = this.parseCommaList(">", true);
|
|
2865
|
-
this.consume(">");
|
|
2866
|
-
}
|
|
2867
|
-
const structTag = new StructTag(address, new Identifier(module), new Identifier(name), tyTags);
|
|
2868
|
-
return new TypeTagStruct(structTag);
|
|
2869
|
-
}
|
|
2870
|
-
if (tokenTy === "GENERIC") {
|
|
2871
|
-
if (this.typeTags.length === 0) {
|
|
2872
|
-
bail("Can't convert generic type since no typeTags were specified.");
|
|
2873
|
-
}
|
|
2874
|
-
const idx = parseInt(tokenVal.substring(1), 10);
|
|
2875
|
-
return new TypeTagParser(this.typeTags[idx]).parseTypeTag();
|
|
2876
|
-
}
|
|
2877
|
-
throw new Error("Invalid type tag.");
|
|
2878
|
-
}
|
|
2879
|
-
};
|
|
2880
|
-
var TypeTagParserError = class extends Error {
|
|
2881
|
-
constructor(message) {
|
|
2882
|
-
super(message);
|
|
2883
|
-
this.name = "TypeTagParserError";
|
|
2884
|
-
}
|
|
2885
|
-
};
|
|
2886
|
-
function tokenize(tagStr) {
|
|
2887
|
-
let pos = 0;
|
|
2888
|
-
const tokens = [];
|
|
2889
|
-
while (pos < tagStr.length) {
|
|
2890
|
-
const [token, size] = nextToken(tagStr, pos);
|
|
2891
|
-
if (token[0] !== "SPACE") {
|
|
2892
|
-
tokens.push(token);
|
|
2893
|
-
}
|
|
2894
|
-
pos += size;
|
|
2895
|
-
}
|
|
2896
|
-
return tokens;
|
|
2897
|
-
}
|
|
2898
|
-
function bail(message) {
|
|
2899
|
-
throw new TypeTagParserError(message);
|
|
2900
|
-
}
|
|
2901
|
-
function isWhiteSpace(c) {
|
|
2902
|
-
return !!c.match(/\s/);
|
|
2903
|
-
}
|
|
2904
|
-
function isValidAlphabetic(c) {
|
|
2905
|
-
return !!c.match(/[_A-Za-z0-9]/g);
|
|
2906
|
-
}
|
|
2907
|
-
function isGeneric(c) {
|
|
2908
|
-
return !!c.match(/T\d+/g);
|
|
2909
|
-
}
|
|
2910
|
-
function nextToken(tagStr, pos) {
|
|
2911
|
-
const c = tagStr[pos];
|
|
2912
|
-
if (c === ":") {
|
|
2913
|
-
if (tagStr.slice(pos, pos + 2) === "::") {
|
|
2914
|
-
return [["COLON", "::"], 2];
|
|
2915
|
-
}
|
|
2916
|
-
bail("Unrecognized token.");
|
|
2917
|
-
} else if (c === "<") {
|
|
2918
|
-
return [["LT", "<"], 1];
|
|
2919
|
-
} else if (c === ">") {
|
|
2920
|
-
return [["GT", ">"], 1];
|
|
2921
|
-
} else if (c === ",") {
|
|
2922
|
-
return [["COMMA", ","], 1];
|
|
2923
|
-
} else if (isWhiteSpace(c)) {
|
|
2924
|
-
let res = "";
|
|
2925
|
-
for (let i = pos; i < tagStr.length; i += 1) {
|
|
2926
|
-
const char = tagStr[i];
|
|
2927
|
-
if (isWhiteSpace(char)) {
|
|
2928
|
-
res = `${res}${char}`;
|
|
2929
|
-
} else {
|
|
2930
|
-
break;
|
|
2931
|
-
}
|
|
2932
|
-
}
|
|
2933
|
-
return [["SPACE", res], res.length];
|
|
2934
|
-
} else if (isValidAlphabetic(c)) {
|
|
2935
|
-
let res = "";
|
|
2936
|
-
for (let i = pos; i < tagStr.length; i += 1) {
|
|
2937
|
-
const char = tagStr[i];
|
|
2938
|
-
if (isValidAlphabetic(char)) {
|
|
2939
|
-
res = `${res}${char}`;
|
|
2940
|
-
} else {
|
|
2941
|
-
break;
|
|
2942
|
-
}
|
|
2943
|
-
}
|
|
2944
|
-
if (isGeneric(res)) {
|
|
2945
|
-
return [["GENERIC", res], res.length];
|
|
2946
|
-
}
|
|
2947
|
-
return [["IDENT", res], res.length];
|
|
2948
|
-
}
|
|
2949
|
-
throw new Error("Unrecognized token.");
|
|
2950
|
-
}
|
|
2951
|
-
|
|
2952
|
-
// src/transactions/transaction_builder/transaction_builder.ts
|
|
2953
|
-
import { sha3_256 as sha3Hash2 } from "@noble/hashes/sha3";
|
|
2954
|
-
|
|
2955
|
-
// src/utils/helpers.ts
|
|
2956
|
-
async function sleep(timeMs) {
|
|
2957
|
-
return new Promise((resolve) => {
|
|
2958
|
-
setTimeout(resolve, timeMs);
|
|
2959
|
-
});
|
|
2960
|
-
}
|
|
2961
|
-
|
|
2962
|
-
// src/internal/transaction.ts
|
|
2963
|
-
async function getTransactions2(args) {
|
|
2964
|
-
const { aptosConfig, options } = args;
|
|
2965
|
-
return paginateWithCursor({
|
|
2966
|
-
aptosConfig,
|
|
2967
|
-
originMethod: "getTransactions",
|
|
2968
|
-
path: "transactions",
|
|
2969
|
-
params: { start: options == null ? void 0 : options.offset, limit: options == null ? void 0 : options.limit }
|
|
2970
|
-
});
|
|
2971
|
-
}
|
|
2972
|
-
async function getGasPriceEstimation(args) {
|
|
2973
|
-
const { aptosConfig } = args;
|
|
2974
|
-
return memoizeAsync(
|
|
2975
|
-
async () => {
|
|
2976
|
-
const { data } = await getAptosFullNode({
|
|
2977
|
-
aptosConfig,
|
|
2978
|
-
originMethod: "getGasPriceEstimation",
|
|
2979
|
-
path: "estimate_gas_price"
|
|
2980
|
-
});
|
|
2981
|
-
return data;
|
|
2982
|
-
},
|
|
2983
|
-
`gas-price-${aptosConfig.network}`,
|
|
2984
|
-
1e3 * 60 * 5
|
|
2985
|
-
)();
|
|
2986
|
-
}
|
|
2987
|
-
async function getTransactionByVersion(args) {
|
|
2988
|
-
const { aptosConfig, ledgerVersion } = args;
|
|
2989
|
-
const { data } = await getAptosFullNode({
|
|
2990
|
-
aptosConfig,
|
|
2991
|
-
originMethod: "getTransactionByVersion",
|
|
2992
|
-
path: `transactions/by_version/${ledgerVersion}`
|
|
2993
|
-
});
|
|
2994
|
-
return data;
|
|
2995
|
-
}
|
|
2996
|
-
async function getTransactionByHash(args) {
|
|
2997
|
-
const { aptosConfig, transactionHash } = args;
|
|
2998
|
-
const { data } = await getAptosFullNode({
|
|
2999
|
-
aptosConfig,
|
|
3000
|
-
path: `transactions/by_hash/${transactionHash}`,
|
|
3001
|
-
originMethod: "getTransactionByHash"
|
|
3002
|
-
});
|
|
3003
|
-
return data;
|
|
3004
|
-
}
|
|
3005
|
-
async function isTransactionPending(args) {
|
|
3006
|
-
const { aptosConfig, transactionHash } = args;
|
|
3007
|
-
try {
|
|
3008
|
-
const transaction = await getTransactionByHash({ aptosConfig, transactionHash });
|
|
3009
|
-
return transaction.type === "pending_transaction" /* Pending */;
|
|
3010
|
-
} catch (e) {
|
|
3011
|
-
if ((e == null ? void 0 : e.status) === 404) {
|
|
3012
|
-
return true;
|
|
3013
|
-
}
|
|
3014
|
-
throw e;
|
|
2816
|
+
|
|
2817
|
+
// src/utils/helpers.ts
|
|
2818
|
+
async function sleep(timeMs) {
|
|
2819
|
+
return new Promise((resolve) => {
|
|
2820
|
+
setTimeout(resolve, timeMs);
|
|
2821
|
+
});
|
|
2822
|
+
}
|
|
2823
|
+
|
|
2824
|
+
// src/internal/transaction.ts
|
|
2825
|
+
async function getTransactions2(args) {
|
|
2826
|
+
const { aptosConfig, options } = args;
|
|
2827
|
+
return paginateWithCursor({
|
|
2828
|
+
aptosConfig,
|
|
2829
|
+
originMethod: "getTransactions",
|
|
2830
|
+
path: "transactions",
|
|
2831
|
+
params: { start: options == null ? void 0 : options.offset, limit: options == null ? void 0 : options.limit }
|
|
2832
|
+
});
|
|
2833
|
+
}
|
|
2834
|
+
async function getGasPriceEstimation(args) {
|
|
2835
|
+
const { aptosConfig } = args;
|
|
2836
|
+
return memoizeAsync(
|
|
2837
|
+
async () => {
|
|
2838
|
+
const { data } = await getAptosFullNode({
|
|
2839
|
+
aptosConfig,
|
|
2840
|
+
originMethod: "getGasPriceEstimation",
|
|
2841
|
+
path: "estimate_gas_price"
|
|
2842
|
+
});
|
|
2843
|
+
return data;
|
|
2844
|
+
},
|
|
2845
|
+
`gas-price-${aptosConfig.network}`,
|
|
2846
|
+
1e3 * 60 * 5
|
|
2847
|
+
)();
|
|
2848
|
+
}
|
|
2849
|
+
async function getTransactionByVersion(args) {
|
|
2850
|
+
const { aptosConfig, ledgerVersion } = args;
|
|
2851
|
+
const { data } = await getAptosFullNode({
|
|
2852
|
+
aptosConfig,
|
|
2853
|
+
originMethod: "getTransactionByVersion",
|
|
2854
|
+
path: `transactions/by_version/${ledgerVersion}`
|
|
2855
|
+
});
|
|
2856
|
+
return data;
|
|
2857
|
+
}
|
|
2858
|
+
async function getTransactionByHash(args) {
|
|
2859
|
+
const { aptosConfig, transactionHash } = args;
|
|
2860
|
+
const { data } = await getAptosFullNode({
|
|
2861
|
+
aptosConfig,
|
|
2862
|
+
path: `transactions/by_hash/${transactionHash}`,
|
|
2863
|
+
originMethod: "getTransactionByHash"
|
|
2864
|
+
});
|
|
2865
|
+
return data;
|
|
2866
|
+
}
|
|
2867
|
+
async function isTransactionPending(args) {
|
|
2868
|
+
const { aptosConfig, transactionHash } = args;
|
|
2869
|
+
try {
|
|
2870
|
+
const transaction = await getTransactionByHash({ aptosConfig, transactionHash });
|
|
2871
|
+
return transaction.type === "pending_transaction" /* Pending */;
|
|
2872
|
+
} catch (e) {
|
|
2873
|
+
if ((e == null ? void 0 : e.status) === 404) {
|
|
2874
|
+
return true;
|
|
2875
|
+
}
|
|
2876
|
+
throw e;
|
|
3015
2877
|
}
|
|
3016
2878
|
}
|
|
3017
2879
|
async function waitForTransaction(args) {
|
|
@@ -3126,8 +2988,10 @@ var AccountAuthenticator = class extends Serializable {
|
|
|
3126
2988
|
return AccountAuthenticatorEd25519.load(deserializer);
|
|
3127
2989
|
case 1 /* MultiEd25519 */:
|
|
3128
2990
|
return AccountAuthenticatorMultiEd25519.load(deserializer);
|
|
3129
|
-
case 2 /*
|
|
3130
|
-
return
|
|
2991
|
+
case 2 /* SingleKey */:
|
|
2992
|
+
return AccountAuthenticatorSingleKey.load(deserializer);
|
|
2993
|
+
case 3 /* MultiKey */:
|
|
2994
|
+
return AccountAuthenticatorMultiKey.load(deserializer);
|
|
3131
2995
|
default:
|
|
3132
2996
|
throw new Error(`Unknown variant index for AccountAuthenticator: ${index}`);
|
|
3133
2997
|
}
|
|
@@ -3167,26 +3031,46 @@ var AccountAuthenticatorMultiEd25519 = class extends AccountAuthenticator {
|
|
|
3167
3031
|
return new AccountAuthenticatorMultiEd25519(public_key, signature);
|
|
3168
3032
|
}
|
|
3169
3033
|
};
|
|
3170
|
-
var
|
|
3034
|
+
var AccountAuthenticatorSingleKey = class extends AccountAuthenticator {
|
|
3171
3035
|
constructor(public_key, signature) {
|
|
3172
3036
|
super();
|
|
3173
3037
|
this.public_key = public_key;
|
|
3174
3038
|
this.signature = signature;
|
|
3175
3039
|
}
|
|
3176
3040
|
serialize(serializer) {
|
|
3177
|
-
serializer.serializeU32AsUleb128(2 /*
|
|
3041
|
+
serializer.serializeU32AsUleb128(2 /* SingleKey */);
|
|
3178
3042
|
this.public_key.serialize(serializer);
|
|
3179
3043
|
this.signature.serialize(serializer);
|
|
3180
3044
|
}
|
|
3181
3045
|
static load(deserializer) {
|
|
3182
|
-
const public_key =
|
|
3183
|
-
const signature =
|
|
3184
|
-
return new
|
|
3046
|
+
const public_key = AnyPublicKey.deserialize(deserializer);
|
|
3047
|
+
const signature = AnySignature.deserialize(deserializer);
|
|
3048
|
+
return new AccountAuthenticatorSingleKey(public_key, signature);
|
|
3049
|
+
}
|
|
3050
|
+
};
|
|
3051
|
+
var AccountAuthenticatorMultiKey = class extends AccountAuthenticator {
|
|
3052
|
+
constructor(public_keys, signatures, signatures_bitmap) {
|
|
3053
|
+
super();
|
|
3054
|
+
this.public_keys = public_keys;
|
|
3055
|
+
this.signatures = signatures;
|
|
3056
|
+
this.signatures_bitmap = signatures_bitmap;
|
|
3057
|
+
}
|
|
3058
|
+
serialize(serializer) {
|
|
3059
|
+
serializer.serializeU32AsUleb128(3 /* MultiKey */);
|
|
3060
|
+
this.public_keys.serialize(serializer);
|
|
3061
|
+
serializer.serializeVector(this.signatures);
|
|
3062
|
+
serializer.serializeBytes(this.signatures_bitmap);
|
|
3063
|
+
}
|
|
3064
|
+
static load(deserializer) {
|
|
3065
|
+
const public_keys = MultiKey.deserialize(deserializer);
|
|
3066
|
+
const signatures = deserializer.deserializeVector(AnySignature);
|
|
3067
|
+
const signatures_bitmap = deserializer.deserializeBytes();
|
|
3068
|
+
return new AccountAuthenticatorMultiKey(public_keys, signatures, signatures_bitmap);
|
|
3185
3069
|
}
|
|
3186
3070
|
};
|
|
3187
3071
|
|
|
3188
3072
|
// src/transactions/authenticator/transaction.ts
|
|
3189
|
-
var TransactionAuthenticator = class {
|
|
3073
|
+
var TransactionAuthenticator = class extends Serializable {
|
|
3190
3074
|
static deserialize(deserializer) {
|
|
3191
3075
|
const index = deserializer.deserializeUleb128AsU32();
|
|
3192
3076
|
switch (index) {
|
|
@@ -3198,8 +3082,8 @@ var TransactionAuthenticator = class {
|
|
|
3198
3082
|
return TransactionAuthenticatorMultiAgent.load(deserializer);
|
|
3199
3083
|
case 3 /* FeePayer */:
|
|
3200
3084
|
return TransactionAuthenticatorFeePayer.load(deserializer);
|
|
3201
|
-
case 4 /*
|
|
3202
|
-
return
|
|
3085
|
+
case 4 /* SingleSender */:
|
|
3086
|
+
return TransactionAuthenticatorSingleSender.load(deserializer);
|
|
3203
3087
|
default:
|
|
3204
3088
|
throw new Error(`Unknown variant index for TransactionAuthenticator: ${index}`);
|
|
3205
3089
|
}
|
|
@@ -3285,63 +3169,362 @@ var TransactionAuthenticatorFeePayer = class extends TransactionAuthenticator {
|
|
|
3285
3169
|
return new TransactionAuthenticatorFeePayer(sender, secondary_signer_addresses, secondary_signers, fee_payer);
|
|
3286
3170
|
}
|
|
3287
3171
|
};
|
|
3288
|
-
var
|
|
3289
|
-
constructor(
|
|
3172
|
+
var TransactionAuthenticatorSingleSender = class extends TransactionAuthenticator {
|
|
3173
|
+
constructor(sender) {
|
|
3174
|
+
super();
|
|
3175
|
+
this.sender = sender;
|
|
3176
|
+
}
|
|
3177
|
+
serialize(serializer) {
|
|
3178
|
+
serializer.serializeU32AsUleb128(4 /* SingleSender */);
|
|
3179
|
+
this.sender.serialize(serializer);
|
|
3180
|
+
}
|
|
3181
|
+
static load(deserializer) {
|
|
3182
|
+
const sender = AccountAuthenticator.deserialize(deserializer);
|
|
3183
|
+
return new TransactionAuthenticatorSingleSender(sender);
|
|
3184
|
+
}
|
|
3185
|
+
};
|
|
3186
|
+
|
|
3187
|
+
// src/transactions/instances/chainId.ts
|
|
3188
|
+
var ChainId = class extends Serializable {
|
|
3189
|
+
constructor(chainId) {
|
|
3190
|
+
super();
|
|
3191
|
+
this.chainId = chainId;
|
|
3192
|
+
}
|
|
3193
|
+
serialize(serializer) {
|
|
3194
|
+
serializer.serializeU8(this.chainId);
|
|
3195
|
+
}
|
|
3196
|
+
static deserialize(deserializer) {
|
|
3197
|
+
const chainId = deserializer.deserializeU8();
|
|
3198
|
+
return new ChainId(chainId);
|
|
3199
|
+
}
|
|
3200
|
+
};
|
|
3201
|
+
|
|
3202
|
+
// src/transactions/instances/identifier.ts
|
|
3203
|
+
var Identifier = class extends Serializable {
|
|
3204
|
+
constructor(identifier) {
|
|
3205
|
+
super();
|
|
3206
|
+
this.identifier = identifier;
|
|
3207
|
+
}
|
|
3208
|
+
serialize(serializer) {
|
|
3209
|
+
serializer.serializeStr(this.identifier);
|
|
3210
|
+
}
|
|
3211
|
+
static deserialize(deserializer) {
|
|
3212
|
+
const identifier = deserializer.deserializeStr();
|
|
3213
|
+
return new Identifier(identifier);
|
|
3214
|
+
}
|
|
3215
|
+
};
|
|
3216
|
+
|
|
3217
|
+
// src/transactions/instances/moduleId.ts
|
|
3218
|
+
var ModuleId = class extends Serializable {
|
|
3219
|
+
constructor(address, name) {
|
|
3220
|
+
super();
|
|
3221
|
+
this.address = address;
|
|
3222
|
+
this.name = name;
|
|
3223
|
+
}
|
|
3224
|
+
static fromStr(moduleId) {
|
|
3225
|
+
const parts = moduleId.split("::");
|
|
3226
|
+
if (parts.length !== 2) {
|
|
3227
|
+
throw new Error("Invalid module id.");
|
|
3228
|
+
}
|
|
3229
|
+
return new ModuleId(AccountAddress.fromString(parts[0]), new Identifier(parts[1]));
|
|
3230
|
+
}
|
|
3231
|
+
serialize(serializer) {
|
|
3232
|
+
this.address.serialize(serializer);
|
|
3233
|
+
this.name.serialize(serializer);
|
|
3234
|
+
}
|
|
3235
|
+
static deserialize(deserializer) {
|
|
3236
|
+
const address = AccountAddress.deserialize(deserializer);
|
|
3237
|
+
const name = Identifier.deserialize(deserializer);
|
|
3238
|
+
return new ModuleId(address, name);
|
|
3239
|
+
}
|
|
3240
|
+
};
|
|
3241
|
+
|
|
3242
|
+
// src/transactions/typeTag/index.ts
|
|
3243
|
+
var TypeTag = class extends Serializable {
|
|
3244
|
+
static deserialize(deserializer) {
|
|
3245
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
3246
|
+
switch (index) {
|
|
3247
|
+
case 0 /* Bool */:
|
|
3248
|
+
return TypeTagBool.load(deserializer);
|
|
3249
|
+
case 1 /* U8 */:
|
|
3250
|
+
return TypeTagU8.load(deserializer);
|
|
3251
|
+
case 2 /* U64 */:
|
|
3252
|
+
return TypeTagU64.load(deserializer);
|
|
3253
|
+
case 3 /* U128 */:
|
|
3254
|
+
return TypeTagU128.load(deserializer);
|
|
3255
|
+
case 4 /* Address */:
|
|
3256
|
+
return TypeTagAddress.load(deserializer);
|
|
3257
|
+
case 5 /* Signer */:
|
|
3258
|
+
return TypeTagSigner.load(deserializer);
|
|
3259
|
+
case 6 /* Vector */:
|
|
3260
|
+
return TypeTagVector.load(deserializer);
|
|
3261
|
+
case 7 /* Struct */:
|
|
3262
|
+
return TypeTagStruct.load(deserializer);
|
|
3263
|
+
case 8 /* U16 */:
|
|
3264
|
+
return TypeTagU16.load(deserializer);
|
|
3265
|
+
case 9 /* U32 */:
|
|
3266
|
+
return TypeTagU32.load(deserializer);
|
|
3267
|
+
case 10 /* U256 */:
|
|
3268
|
+
return TypeTagU256.load(deserializer);
|
|
3269
|
+
case 255 /* Generic */:
|
|
3270
|
+
return TypeTagGeneric.load(deserializer);
|
|
3271
|
+
default:
|
|
3272
|
+
throw new Error(`Unknown variant index for TypeTag: ${index}`);
|
|
3273
|
+
}
|
|
3274
|
+
}
|
|
3275
|
+
isBool() {
|
|
3276
|
+
return this instanceof TypeTagBool;
|
|
3277
|
+
}
|
|
3278
|
+
isAddress() {
|
|
3279
|
+
return this instanceof TypeTagAddress;
|
|
3280
|
+
}
|
|
3281
|
+
isGeneric() {
|
|
3282
|
+
return this instanceof TypeTagGeneric;
|
|
3283
|
+
}
|
|
3284
|
+
isSigner() {
|
|
3285
|
+
return this instanceof TypeTagSigner;
|
|
3286
|
+
}
|
|
3287
|
+
isVector() {
|
|
3288
|
+
return this instanceof TypeTagVector;
|
|
3289
|
+
}
|
|
3290
|
+
isStruct() {
|
|
3291
|
+
return this instanceof TypeTagStruct;
|
|
3292
|
+
}
|
|
3293
|
+
isU8() {
|
|
3294
|
+
return this instanceof TypeTagU8;
|
|
3295
|
+
}
|
|
3296
|
+
isU16() {
|
|
3297
|
+
return this instanceof TypeTagU16;
|
|
3298
|
+
}
|
|
3299
|
+
isU32() {
|
|
3300
|
+
return this instanceof TypeTagU32;
|
|
3301
|
+
}
|
|
3302
|
+
isU64() {
|
|
3303
|
+
return this instanceof TypeTagU64;
|
|
3304
|
+
}
|
|
3305
|
+
isU128() {
|
|
3306
|
+
return this instanceof TypeTagU128;
|
|
3307
|
+
}
|
|
3308
|
+
isU256() {
|
|
3309
|
+
return this instanceof TypeTagU256;
|
|
3310
|
+
}
|
|
3311
|
+
};
|
|
3312
|
+
var TypeTagBool = class extends TypeTag {
|
|
3313
|
+
toString() {
|
|
3314
|
+
return "bool";
|
|
3315
|
+
}
|
|
3316
|
+
serialize(serializer) {
|
|
3317
|
+
serializer.serializeU32AsUleb128(0 /* Bool */);
|
|
3318
|
+
}
|
|
3319
|
+
static load(_deserializer) {
|
|
3320
|
+
return new TypeTagBool();
|
|
3321
|
+
}
|
|
3322
|
+
};
|
|
3323
|
+
var TypeTagU8 = class extends TypeTag {
|
|
3324
|
+
toString() {
|
|
3325
|
+
return "u8";
|
|
3326
|
+
}
|
|
3327
|
+
serialize(serializer) {
|
|
3328
|
+
serializer.serializeU32AsUleb128(1 /* U8 */);
|
|
3329
|
+
}
|
|
3330
|
+
static load(_deserializer) {
|
|
3331
|
+
return new TypeTagU8();
|
|
3332
|
+
}
|
|
3333
|
+
};
|
|
3334
|
+
var TypeTagU16 = class extends TypeTag {
|
|
3335
|
+
toString() {
|
|
3336
|
+
return "u16";
|
|
3337
|
+
}
|
|
3338
|
+
serialize(serializer) {
|
|
3339
|
+
serializer.serializeU32AsUleb128(8 /* U16 */);
|
|
3340
|
+
}
|
|
3341
|
+
static load(_deserializer) {
|
|
3342
|
+
return new TypeTagU16();
|
|
3343
|
+
}
|
|
3344
|
+
};
|
|
3345
|
+
var TypeTagU32 = class extends TypeTag {
|
|
3346
|
+
toString() {
|
|
3347
|
+
return "u32";
|
|
3348
|
+
}
|
|
3349
|
+
serialize(serializer) {
|
|
3350
|
+
serializer.serializeU32AsUleb128(9 /* U32 */);
|
|
3351
|
+
}
|
|
3352
|
+
static load(_deserializer) {
|
|
3353
|
+
return new TypeTagU32();
|
|
3354
|
+
}
|
|
3355
|
+
};
|
|
3356
|
+
var TypeTagU64 = class extends TypeTag {
|
|
3357
|
+
toString() {
|
|
3358
|
+
return "u64";
|
|
3359
|
+
}
|
|
3360
|
+
serialize(serializer) {
|
|
3361
|
+
serializer.serializeU32AsUleb128(2 /* U64 */);
|
|
3362
|
+
}
|
|
3363
|
+
static load(_deserializer) {
|
|
3364
|
+
return new TypeTagU64();
|
|
3365
|
+
}
|
|
3366
|
+
};
|
|
3367
|
+
var TypeTagU128 = class extends TypeTag {
|
|
3368
|
+
toString() {
|
|
3369
|
+
return "u128";
|
|
3370
|
+
}
|
|
3371
|
+
serialize(serializer) {
|
|
3372
|
+
serializer.serializeU32AsUleb128(3 /* U128 */);
|
|
3373
|
+
}
|
|
3374
|
+
static load(_deserializer) {
|
|
3375
|
+
return new TypeTagU128();
|
|
3376
|
+
}
|
|
3377
|
+
};
|
|
3378
|
+
var TypeTagU256 = class extends TypeTag {
|
|
3379
|
+
toString() {
|
|
3380
|
+
return "u256";
|
|
3381
|
+
}
|
|
3382
|
+
serialize(serializer) {
|
|
3383
|
+
serializer.serializeU32AsUleb128(10 /* U256 */);
|
|
3384
|
+
}
|
|
3385
|
+
static load(_deserializer) {
|
|
3386
|
+
return new TypeTagU256();
|
|
3387
|
+
}
|
|
3388
|
+
};
|
|
3389
|
+
var TypeTagAddress = class extends TypeTag {
|
|
3390
|
+
toString() {
|
|
3391
|
+
return "address";
|
|
3392
|
+
}
|
|
3393
|
+
serialize(serializer) {
|
|
3394
|
+
serializer.serializeU32AsUleb128(4 /* Address */);
|
|
3395
|
+
}
|
|
3396
|
+
static load(_deserializer) {
|
|
3397
|
+
return new TypeTagAddress();
|
|
3398
|
+
}
|
|
3399
|
+
};
|
|
3400
|
+
var TypeTagSigner = class extends TypeTag {
|
|
3401
|
+
toString() {
|
|
3402
|
+
return "signer";
|
|
3403
|
+
}
|
|
3404
|
+
serialize(serializer) {
|
|
3405
|
+
serializer.serializeU32AsUleb128(5 /* Signer */);
|
|
3406
|
+
}
|
|
3407
|
+
static load(_deserializer) {
|
|
3408
|
+
return new TypeTagSigner();
|
|
3409
|
+
}
|
|
3410
|
+
};
|
|
3411
|
+
var TypeTagReference = class extends TypeTag {
|
|
3412
|
+
constructor(value) {
|
|
3413
|
+
super();
|
|
3414
|
+
this.value = value;
|
|
3415
|
+
}
|
|
3416
|
+
toString() {
|
|
3417
|
+
return `&${this.value.toString()}`;
|
|
3418
|
+
}
|
|
3419
|
+
serialize(serializer) {
|
|
3420
|
+
serializer.serializeU32AsUleb128(254 /* Reference */);
|
|
3421
|
+
}
|
|
3422
|
+
static load(deserializer) {
|
|
3423
|
+
const value = TypeTag.deserialize(deserializer);
|
|
3424
|
+
return new TypeTagReference(value);
|
|
3425
|
+
}
|
|
3426
|
+
};
|
|
3427
|
+
var TypeTagGeneric = class extends TypeTag {
|
|
3428
|
+
constructor(value) {
|
|
3429
|
+
super();
|
|
3430
|
+
this.value = value;
|
|
3431
|
+
}
|
|
3432
|
+
toString() {
|
|
3433
|
+
return `T${this.value}`;
|
|
3434
|
+
}
|
|
3435
|
+
serialize(serializer) {
|
|
3436
|
+
serializer.serializeU32AsUleb128(255 /* Generic */);
|
|
3437
|
+
serializer.serializeU32(this.value);
|
|
3438
|
+
}
|
|
3439
|
+
static load(deserializer) {
|
|
3440
|
+
const value = deserializer.deserializeU32();
|
|
3441
|
+
return new TypeTagGeneric(value);
|
|
3442
|
+
}
|
|
3443
|
+
};
|
|
3444
|
+
var TypeTagVector = class extends TypeTag {
|
|
3445
|
+
constructor(value) {
|
|
3446
|
+
super();
|
|
3447
|
+
this.value = value;
|
|
3448
|
+
}
|
|
3449
|
+
toString() {
|
|
3450
|
+
return `vector<${this.value.toString()}>`;
|
|
3451
|
+
}
|
|
3452
|
+
serialize(serializer) {
|
|
3453
|
+
serializer.serializeU32AsUleb128(6 /* Vector */);
|
|
3454
|
+
this.value.serialize(serializer);
|
|
3455
|
+
}
|
|
3456
|
+
static load(deserializer) {
|
|
3457
|
+
const value = TypeTag.deserialize(deserializer);
|
|
3458
|
+
return new TypeTagVector(value);
|
|
3459
|
+
}
|
|
3460
|
+
};
|
|
3461
|
+
var TypeTagStruct = class extends TypeTag {
|
|
3462
|
+
constructor(value) {
|
|
3290
3463
|
super();
|
|
3291
|
-
this.
|
|
3292
|
-
|
|
3464
|
+
this.value = value;
|
|
3465
|
+
}
|
|
3466
|
+
toString() {
|
|
3467
|
+
let typePredicate = "";
|
|
3468
|
+
if (this.value.type_args.length > 0) {
|
|
3469
|
+
typePredicate = `<${this.value.type_args.map((typeArg) => typeArg.toString()).join(", ")}>`;
|
|
3470
|
+
}
|
|
3471
|
+
return `${this.value.address.toString()}::${this.value.module_name.identifier}::${this.value.name.identifier}${typePredicate}`;
|
|
3293
3472
|
}
|
|
3294
3473
|
serialize(serializer) {
|
|
3295
|
-
serializer.serializeU32AsUleb128(
|
|
3296
|
-
this.
|
|
3297
|
-
this.signature.serialize(serializer);
|
|
3474
|
+
serializer.serializeU32AsUleb128(7 /* Struct */);
|
|
3475
|
+
this.value.serialize(serializer);
|
|
3298
3476
|
}
|
|
3299
3477
|
static load(deserializer) {
|
|
3300
|
-
const
|
|
3301
|
-
|
|
3302
|
-
return new TransactionAuthenticatorSecp256k1(public_key, signature);
|
|
3478
|
+
const value = StructTag.deserialize(deserializer);
|
|
3479
|
+
return new TypeTagStruct(value);
|
|
3303
3480
|
}
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
// src/transactions/instances/chainId.ts
|
|
3307
|
-
var ChainId = class extends Serializable {
|
|
3308
|
-
constructor(chainId) {
|
|
3309
|
-
super();
|
|
3310
|
-
this.chainId = chainId;
|
|
3481
|
+
isTypeTag(address, moduleName, structName) {
|
|
3482
|
+
return this.value.module_name.identifier === moduleName && this.value.name.identifier === structName && this.value.address.equals(address);
|
|
3311
3483
|
}
|
|
3312
|
-
|
|
3313
|
-
|
|
3484
|
+
isString() {
|
|
3485
|
+
return this.isTypeTag(AccountAddress.ONE, "string", "String");
|
|
3314
3486
|
}
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3487
|
+
isOption() {
|
|
3488
|
+
return this.isTypeTag(AccountAddress.ONE, "option", "Option");
|
|
3489
|
+
}
|
|
3490
|
+
isObject() {
|
|
3491
|
+
return this.isTypeTag(AccountAddress.ONE, "object", "Object");
|
|
3318
3492
|
}
|
|
3319
3493
|
};
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
var ModuleId = class extends Serializable {
|
|
3323
|
-
constructor(address, name) {
|
|
3494
|
+
var StructTag = class extends Serializable {
|
|
3495
|
+
constructor(address, module_name, name, type_args) {
|
|
3324
3496
|
super();
|
|
3325
3497
|
this.address = address;
|
|
3498
|
+
this.module_name = module_name;
|
|
3326
3499
|
this.name = name;
|
|
3327
|
-
|
|
3328
|
-
static fromStr(moduleId) {
|
|
3329
|
-
const parts = moduleId.split("::");
|
|
3330
|
-
if (parts.length !== 2) {
|
|
3331
|
-
throw new Error("Invalid module id.");
|
|
3332
|
-
}
|
|
3333
|
-
return new ModuleId(AccountAddress.fromString(parts[0]), new Identifier(parts[1]));
|
|
3500
|
+
this.type_args = type_args;
|
|
3334
3501
|
}
|
|
3335
3502
|
serialize(serializer) {
|
|
3336
|
-
this.address
|
|
3337
|
-
|
|
3503
|
+
serializer.serialize(this.address);
|
|
3504
|
+
serializer.serialize(this.module_name);
|
|
3505
|
+
serializer.serialize(this.name);
|
|
3506
|
+
serializer.serializeVector(this.type_args);
|
|
3338
3507
|
}
|
|
3339
3508
|
static deserialize(deserializer) {
|
|
3340
3509
|
const address = AccountAddress.deserialize(deserializer);
|
|
3510
|
+
const moduleName = Identifier.deserialize(deserializer);
|
|
3341
3511
|
const name = Identifier.deserialize(deserializer);
|
|
3342
|
-
|
|
3512
|
+
const typeArgs = deserializer.deserializeVector(TypeTag);
|
|
3513
|
+
return new StructTag(address, moduleName, name, typeArgs);
|
|
3343
3514
|
}
|
|
3344
3515
|
};
|
|
3516
|
+
function aptosCoinStructTag() {
|
|
3517
|
+
return new StructTag(AccountAddress.ONE, new Identifier("aptos_coin"), new Identifier("AptosCoin"), []);
|
|
3518
|
+
}
|
|
3519
|
+
function stringStructTag() {
|
|
3520
|
+
return new StructTag(AccountAddress.ONE, new Identifier("string"), new Identifier("String"), []);
|
|
3521
|
+
}
|
|
3522
|
+
function optionStructTag(typeArg) {
|
|
3523
|
+
return new StructTag(AccountAddress.ONE, new Identifier("option"), new Identifier("Option"), [typeArg]);
|
|
3524
|
+
}
|
|
3525
|
+
function objectStructTag(typeArg) {
|
|
3526
|
+
return new StructTag(AccountAddress.ONE, new Identifier("object"), new Identifier("Object"), [typeArg]);
|
|
3527
|
+
}
|
|
3345
3528
|
|
|
3346
3529
|
// src/transactions/instances/transactionPayload.ts
|
|
3347
3530
|
function deserializeFromScriptArgument(deserializer) {
|
|
@@ -3504,12 +3687,12 @@ var MultiSig = class {
|
|
|
3504
3687
|
const payloadPresent = deserializer.deserializeBool();
|
|
3505
3688
|
let transaction_payload;
|
|
3506
3689
|
if (payloadPresent) {
|
|
3507
|
-
transaction_payload =
|
|
3690
|
+
transaction_payload = MultisigTransactionPayload.deserialize(deserializer);
|
|
3508
3691
|
}
|
|
3509
3692
|
return new MultiSig(multisig_address, transaction_payload);
|
|
3510
3693
|
}
|
|
3511
3694
|
};
|
|
3512
|
-
var
|
|
3695
|
+
var MultisigTransactionPayload = class {
|
|
3513
3696
|
constructor(transaction_payload) {
|
|
3514
3697
|
this.transaction_payload = transaction_payload;
|
|
3515
3698
|
}
|
|
@@ -3519,7 +3702,7 @@ var MultiSigTransactionPayload = class {
|
|
|
3519
3702
|
}
|
|
3520
3703
|
static deserialize(deserializer) {
|
|
3521
3704
|
deserializer.deserializeUleb128AsU32();
|
|
3522
|
-
return new
|
|
3705
|
+
return new MultisigTransactionPayload(EntryFunction.deserialize(deserializer));
|
|
3523
3706
|
}
|
|
3524
3707
|
};
|
|
3525
3708
|
|
|
@@ -3632,38 +3815,535 @@ var SignedTransaction = class extends Serializable {
|
|
|
3632
3815
|
}
|
|
3633
3816
|
};
|
|
3634
3817
|
|
|
3635
|
-
// src/transactions/
|
|
3636
|
-
function
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3818
|
+
// src/transactions/typeTag/parser.ts
|
|
3819
|
+
function isValidIdentifier(str) {
|
|
3820
|
+
return !!str.match(/^[_a-zA-Z0-9]+$/);
|
|
3821
|
+
}
|
|
3822
|
+
function isValidWhitespaceCharacter(char) {
|
|
3823
|
+
return !!char.match(/\s/);
|
|
3824
|
+
}
|
|
3825
|
+
function consumeWhitespace(tagStr, pos) {
|
|
3826
|
+
let i = pos;
|
|
3827
|
+
for (; i < tagStr.length; i += 1) {
|
|
3828
|
+
const innerChar = tagStr[i];
|
|
3829
|
+
if (!isValidWhitespaceCharacter(innerChar)) {
|
|
3830
|
+
break;
|
|
3831
|
+
}
|
|
3832
|
+
}
|
|
3833
|
+
return i;
|
|
3834
|
+
}
|
|
3835
|
+
var TypeTagParserErrorType = /* @__PURE__ */ ((TypeTagParserErrorType2) => {
|
|
3836
|
+
TypeTagParserErrorType2["InvalidTypeTag"] = "unknown type";
|
|
3837
|
+
TypeTagParserErrorType2["UnexpectedTypeArgumentClose"] = "unexpected '>'";
|
|
3838
|
+
TypeTagParserErrorType2["UnexpectedWhitespaceCharacter"] = "unexpected whitespace character";
|
|
3839
|
+
TypeTagParserErrorType2["UnexpectedComma"] = "unexpected ','";
|
|
3840
|
+
TypeTagParserErrorType2["TypeArgumentCountMismatch"] = "type argument count doesn't match expected amount";
|
|
3841
|
+
TypeTagParserErrorType2["MissingTypeArgumentClose"] = "no matching '>' for '<'";
|
|
3842
|
+
TypeTagParserErrorType2["UnexpectedPrimitiveTypeArguments"] = "primitive types not expected to have type arguments";
|
|
3843
|
+
TypeTagParserErrorType2["UnexpectedVectorTypeArgumentCount"] = "vector type expected to have exactly one type argument";
|
|
3844
|
+
TypeTagParserErrorType2["UnexpectedStructFormat"] = "unexpected struct format, must be of the form 0xaddress::module_name::struct_name";
|
|
3845
|
+
TypeTagParserErrorType2["InvalidModuleNameCharacter"] = "module name must only contain alphanumeric or '_' characters";
|
|
3846
|
+
TypeTagParserErrorType2["InvalidStructNameCharacter"] = "struct name must only contain alphanumeric or '_' characters";
|
|
3847
|
+
return TypeTagParserErrorType2;
|
|
3848
|
+
})(TypeTagParserErrorType || {});
|
|
3849
|
+
var TypeTagParserError = class extends Error {
|
|
3850
|
+
constructor(typeTagStr, invalidReason) {
|
|
3851
|
+
super(`Failed to parse typeTag '${typeTagStr}', ${invalidReason}`);
|
|
3852
|
+
}
|
|
3853
|
+
};
|
|
3854
|
+
function parseTypeTag(typeStr, options) {
|
|
3855
|
+
var _a;
|
|
3856
|
+
const allowGenerics = (_a = options == null ? void 0 : options.allowGenerics) != null ? _a : false;
|
|
3857
|
+
const saved = [];
|
|
3858
|
+
let innerTypes = [];
|
|
3859
|
+
let curTypes = [];
|
|
3860
|
+
let cur = 0;
|
|
3861
|
+
let currentStr = "";
|
|
3862
|
+
let expectedTypes = 1;
|
|
3863
|
+
while (cur < typeStr.length) {
|
|
3864
|
+
const char = typeStr[cur];
|
|
3865
|
+
if (char === "<") {
|
|
3866
|
+
saved.push({
|
|
3867
|
+
savedExpectedTypes: expectedTypes,
|
|
3868
|
+
savedStr: currentStr,
|
|
3869
|
+
savedTypes: curTypes
|
|
3870
|
+
});
|
|
3871
|
+
currentStr = "";
|
|
3872
|
+
curTypes = [];
|
|
3873
|
+
expectedTypes = 1;
|
|
3874
|
+
} else if (char === ">") {
|
|
3875
|
+
if (currentStr !== "") {
|
|
3876
|
+
const newType = parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
3877
|
+
curTypes.push(newType);
|
|
3878
|
+
}
|
|
3879
|
+
const savedPop = saved.pop();
|
|
3880
|
+
if (savedPop === void 0) {
|
|
3881
|
+
throw new TypeTagParserError(typeStr, "unexpected '>'" /* UnexpectedTypeArgumentClose */);
|
|
3882
|
+
}
|
|
3883
|
+
if (expectedTypes !== curTypes.length) {
|
|
3884
|
+
throw new TypeTagParserError(typeStr, "type argument count doesn't match expected amount" /* TypeArgumentCountMismatch */);
|
|
3885
|
+
}
|
|
3886
|
+
const { savedStr, savedTypes, savedExpectedTypes } = savedPop;
|
|
3887
|
+
innerTypes = curTypes;
|
|
3888
|
+
curTypes = savedTypes;
|
|
3889
|
+
currentStr = savedStr;
|
|
3890
|
+
expectedTypes = savedExpectedTypes;
|
|
3891
|
+
} else if (char === ",") {
|
|
3892
|
+
if (currentStr.length !== 0) {
|
|
3893
|
+
const newType = parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
3894
|
+
innerTypes = [];
|
|
3895
|
+
curTypes.push(newType);
|
|
3896
|
+
currentStr = "";
|
|
3897
|
+
expectedTypes += 1;
|
|
3898
|
+
}
|
|
3899
|
+
} else if (isValidWhitespaceCharacter(char)) {
|
|
3900
|
+
let parsedTypeTag = false;
|
|
3901
|
+
if (currentStr.length !== 0) {
|
|
3902
|
+
const newType = parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
3903
|
+
innerTypes = [];
|
|
3904
|
+
curTypes.push(newType);
|
|
3905
|
+
currentStr = "";
|
|
3906
|
+
parsedTypeTag = true;
|
|
3907
|
+
}
|
|
3908
|
+
cur = consumeWhitespace(typeStr, cur);
|
|
3909
|
+
const nextChar = typeStr[cur];
|
|
3910
|
+
if (cur < typeStr.length && parsedTypeTag && nextChar !== "," && nextChar !== ">") {
|
|
3911
|
+
throw new TypeTagParserError(typeStr, "unexpected whitespace character" /* UnexpectedWhitespaceCharacter */);
|
|
3912
|
+
}
|
|
3913
|
+
continue;
|
|
3914
|
+
} else {
|
|
3915
|
+
currentStr += char;
|
|
3916
|
+
}
|
|
3917
|
+
cur += 1;
|
|
3918
|
+
}
|
|
3919
|
+
if (saved.length > 0) {
|
|
3920
|
+
throw new TypeTagParserError(typeStr, "no matching '>' for '<'" /* MissingTypeArgumentClose */);
|
|
3921
|
+
}
|
|
3922
|
+
switch (curTypes.length) {
|
|
3923
|
+
case 0:
|
|
3924
|
+
return parseTypeTagInner(currentStr, innerTypes, allowGenerics);
|
|
3925
|
+
case 1:
|
|
3926
|
+
if (currentStr === "") {
|
|
3927
|
+
return curTypes[0];
|
|
3928
|
+
}
|
|
3929
|
+
throw new TypeTagParserError(typeStr, "unexpected ','" /* UnexpectedComma */);
|
|
3930
|
+
default:
|
|
3931
|
+
throw new TypeTagParserError(typeStr, "unexpected whitespace character" /* UnexpectedWhitespaceCharacter */);
|
|
3932
|
+
}
|
|
3933
|
+
}
|
|
3934
|
+
function parseTypeTagInner(str, types, allowGenerics) {
|
|
3935
|
+
switch (str) {
|
|
3936
|
+
case "&signer":
|
|
3937
|
+
if (types.length > 0) {
|
|
3938
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3939
|
+
}
|
|
3940
|
+
return new TypeTagReference(new TypeTagSigner());
|
|
3941
|
+
case "signer":
|
|
3942
|
+
if (types.length > 0) {
|
|
3943
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3944
|
+
}
|
|
3945
|
+
return new TypeTagSigner();
|
|
3946
|
+
case "bool":
|
|
3947
|
+
if (types.length > 0) {
|
|
3948
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3949
|
+
}
|
|
3950
|
+
return new TypeTagBool();
|
|
3951
|
+
case "address":
|
|
3952
|
+
if (types.length > 0) {
|
|
3953
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3954
|
+
}
|
|
3955
|
+
return new TypeTagAddress();
|
|
3956
|
+
case "u8":
|
|
3957
|
+
if (types.length > 0) {
|
|
3958
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3959
|
+
}
|
|
3960
|
+
return new TypeTagU8();
|
|
3961
|
+
case "u16":
|
|
3962
|
+
if (types.length > 0) {
|
|
3963
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3964
|
+
}
|
|
3965
|
+
return new TypeTagU16();
|
|
3966
|
+
case "u32":
|
|
3967
|
+
if (types.length > 0) {
|
|
3968
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3969
|
+
}
|
|
3970
|
+
return new TypeTagU32();
|
|
3971
|
+
case "u64":
|
|
3972
|
+
if (types.length > 0) {
|
|
3973
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3974
|
+
}
|
|
3975
|
+
return new TypeTagU64();
|
|
3976
|
+
case "u128":
|
|
3977
|
+
if (types.length > 0) {
|
|
3978
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3979
|
+
}
|
|
3980
|
+
return new TypeTagU128();
|
|
3981
|
+
case "u256":
|
|
3982
|
+
if (types.length > 0) {
|
|
3983
|
+
throw new TypeTagParserError(str, "primitive types not expected to have type arguments" /* UnexpectedPrimitiveTypeArguments */);
|
|
3984
|
+
}
|
|
3985
|
+
return new TypeTagU256();
|
|
3986
|
+
case "vector":
|
|
3987
|
+
if (types.length !== 1) {
|
|
3988
|
+
throw new TypeTagParserError(str, "vector type expected to have exactly one type argument" /* UnexpectedVectorTypeArgumentCount */);
|
|
3989
|
+
}
|
|
3990
|
+
return new TypeTagVector(types[0]);
|
|
3991
|
+
default:
|
|
3992
|
+
if (allowGenerics && str.match(/^T[0-9]+$/)) {
|
|
3993
|
+
return new TypeTagGeneric(Number(str.split("T")[1]));
|
|
3994
|
+
}
|
|
3995
|
+
if (!str.match(/.*:.*/)) {
|
|
3996
|
+
throw new TypeTagParserError(str, "unknown type" /* InvalidTypeTag */);
|
|
3997
|
+
}
|
|
3998
|
+
const structParts = str.split("::");
|
|
3999
|
+
if (structParts.length !== 3) {
|
|
4000
|
+
throw new TypeTagParserError(str, "unexpected struct format, must be of the form 0xaddress::module_name::struct_name" /* UnexpectedStructFormat */);
|
|
4001
|
+
}
|
|
4002
|
+
if (!isValidIdentifier(structParts[1])) {
|
|
4003
|
+
throw new TypeTagParserError(str, "module name must only contain alphanumeric or '_' characters" /* InvalidModuleNameCharacter */);
|
|
4004
|
+
}
|
|
4005
|
+
if (!isValidIdentifier(structParts[2])) {
|
|
4006
|
+
throw new TypeTagParserError(str, "struct name must only contain alphanumeric or '_' characters" /* InvalidStructNameCharacter */);
|
|
4007
|
+
}
|
|
4008
|
+
return new TypeTagStruct(
|
|
4009
|
+
new StructTag(
|
|
4010
|
+
AccountAddress.fromString(structParts[0]),
|
|
4011
|
+
new Identifier(structParts[1]),
|
|
4012
|
+
new Identifier(structParts[2]),
|
|
4013
|
+
types
|
|
4014
|
+
)
|
|
4015
|
+
);
|
|
4016
|
+
}
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
// src/transactions/transactionBuilder/helpers.ts
|
|
4020
|
+
function isBool(arg) {
|
|
4021
|
+
return typeof arg === "boolean";
|
|
4022
|
+
}
|
|
4023
|
+
function isString(arg) {
|
|
4024
|
+
return typeof arg === "string";
|
|
4025
|
+
}
|
|
4026
|
+
function isNumber(arg) {
|
|
4027
|
+
return typeof arg === "number";
|
|
4028
|
+
}
|
|
4029
|
+
function isLargeNumber(arg) {
|
|
4030
|
+
return typeof arg === "number" || typeof arg === "bigint" || typeof arg === "string";
|
|
4031
|
+
}
|
|
4032
|
+
function isNull(arg) {
|
|
4033
|
+
return arg === null || arg === void 0;
|
|
4034
|
+
}
|
|
4035
|
+
function isBcsBool(arg) {
|
|
4036
|
+
return arg instanceof Bool;
|
|
4037
|
+
}
|
|
4038
|
+
function isBcsAddress(arg) {
|
|
4039
|
+
return arg instanceof AccountAddress;
|
|
4040
|
+
}
|
|
4041
|
+
function isBcsString(arg) {
|
|
4042
|
+
return arg instanceof MoveString;
|
|
4043
|
+
}
|
|
4044
|
+
function isBcsFixedBytes(arg) {
|
|
4045
|
+
return arg instanceof FixedBytes;
|
|
4046
|
+
}
|
|
4047
|
+
function isBcsU8(arg) {
|
|
4048
|
+
return arg instanceof U8;
|
|
4049
|
+
}
|
|
4050
|
+
function isBcsU16(arg) {
|
|
4051
|
+
return arg instanceof U16;
|
|
4052
|
+
}
|
|
4053
|
+
function isBcsU32(arg) {
|
|
4054
|
+
return arg instanceof U32;
|
|
4055
|
+
}
|
|
4056
|
+
function isBcsU64(arg) {
|
|
4057
|
+
return arg instanceof U64;
|
|
4058
|
+
}
|
|
4059
|
+
function isBcsU128(arg) {
|
|
4060
|
+
return arg instanceof U128;
|
|
4061
|
+
}
|
|
4062
|
+
function isBcsU256(arg) {
|
|
4063
|
+
return arg instanceof U256;
|
|
4064
|
+
}
|
|
4065
|
+
function isScriptDataInput(arg) {
|
|
4066
|
+
return "bytecode" in arg;
|
|
4067
|
+
}
|
|
4068
|
+
function throwTypeMismatch(expectedType, position) {
|
|
4069
|
+
throw new Error(`Type mismatch for argument ${position}, expected '${expectedType}'`);
|
|
4070
|
+
}
|
|
4071
|
+
function findFirstNonSignerArg(functionAbi) {
|
|
4072
|
+
return functionAbi.params.findIndex((param) => param !== "signer" && param !== "&signer");
|
|
4073
|
+
}
|
|
4074
|
+
function getFunctionParts(functionArg) {
|
|
4075
|
+
const funcNameParts = functionArg.split("::");
|
|
4076
|
+
if (funcNameParts.length !== 3) {
|
|
4077
|
+
throw new Error(`Invalid function ${functionArg}`);
|
|
4078
|
+
}
|
|
4079
|
+
const moduleAddress = funcNameParts[0];
|
|
4080
|
+
const moduleName = funcNameParts[1];
|
|
4081
|
+
const functionName = funcNameParts[2];
|
|
4082
|
+
return { moduleAddress, moduleName, functionName };
|
|
4083
|
+
}
|
|
4084
|
+
|
|
4085
|
+
// src/transactions/transactionBuilder/remoteAbi.ts
|
|
4086
|
+
function standardizeTypeTags(typeArguments) {
|
|
4087
|
+
var _a;
|
|
4088
|
+
return (_a = typeArguments == null ? void 0 : typeArguments.map((typeArg) => {
|
|
4089
|
+
if (isString(typeArg)) {
|
|
4090
|
+
return parseTypeTag(typeArg);
|
|
4091
|
+
}
|
|
4092
|
+
return typeArg;
|
|
4093
|
+
})) != null ? _a : [];
|
|
4094
|
+
}
|
|
4095
|
+
async function fetchEntryFunctionAbi(moduleAddress, moduleName, functionName, aptosConfig) {
|
|
4096
|
+
var _a;
|
|
4097
|
+
const module = await getModule({ aptosConfig, accountAddress: moduleAddress, moduleName });
|
|
4098
|
+
const functionAbi = (_a = module.abi) == null ? void 0 : _a.exposed_functions.find((func) => func.name === functionName);
|
|
4099
|
+
if (!functionAbi) {
|
|
4100
|
+
throw new Error(`Could not find entry function ABI for '${moduleAddress}::${moduleName}::${functionName}'`);
|
|
4101
|
+
}
|
|
4102
|
+
if (!functionAbi.is_entry) {
|
|
4103
|
+
throw new Error(`'${moduleAddress}::${moduleName}::${functionName}' is not an entry function`);
|
|
4104
|
+
}
|
|
4105
|
+
const first = findFirstNonSignerArg(functionAbi);
|
|
4106
|
+
const params = [];
|
|
4107
|
+
for (let i = first; i < functionAbi.params.length; i += 1) {
|
|
4108
|
+
params.push(parseTypeTag(functionAbi.params[i], { allowGenerics: true }));
|
|
4109
|
+
}
|
|
4110
|
+
return {
|
|
4111
|
+
typeParameters: functionAbi.generic_type_params,
|
|
4112
|
+
parameters: params
|
|
4113
|
+
};
|
|
4114
|
+
}
|
|
4115
|
+
function convertArgument(functionName, functionAbi, arg, position, genericTypeParams) {
|
|
4116
|
+
if (position >= functionAbi.parameters.length) {
|
|
4117
|
+
throw new Error(`Too many arguments for '${functionName}', expected ${functionAbi.parameters.length}`);
|
|
4118
|
+
}
|
|
4119
|
+
if (isBcsBool(arg) || isBcsU8(arg) || isBcsU16(arg) || isBcsU32(arg) || isBcsU64(arg) || isBcsU128(arg) || isBcsU256(arg) || isBcsAddress(arg) || isBcsString(arg) || isBcsFixedBytes(arg) || arg instanceof MoveVector || arg instanceof MoveOption) {
|
|
4120
|
+
checkType(functionAbi, arg, position);
|
|
4121
|
+
return arg;
|
|
4122
|
+
}
|
|
4123
|
+
return parseArg(arg, functionAbi.parameters[position], position, genericTypeParams);
|
|
4124
|
+
}
|
|
4125
|
+
function parseArg(arg, param, position, genericTypeParams) {
|
|
4126
|
+
if (param.isBool()) {
|
|
4127
|
+
if (isBool(arg)) {
|
|
4128
|
+
return new Bool(arg);
|
|
4129
|
+
}
|
|
4130
|
+
throwTypeMismatch("boolean", position);
|
|
4131
|
+
}
|
|
4132
|
+
if (param.isAddress()) {
|
|
4133
|
+
if (isString(arg)) {
|
|
4134
|
+
return AccountAddress.fromString(arg);
|
|
4135
|
+
}
|
|
4136
|
+
throwTypeMismatch("string", position);
|
|
4137
|
+
}
|
|
4138
|
+
if (param.isU8()) {
|
|
4139
|
+
if (isNumber(arg)) {
|
|
4140
|
+
return new U8(arg);
|
|
4141
|
+
}
|
|
4142
|
+
throwTypeMismatch("number", position);
|
|
4143
|
+
}
|
|
4144
|
+
if (param.isU16()) {
|
|
4145
|
+
if (isNumber(arg)) {
|
|
4146
|
+
return new U16(arg);
|
|
4147
|
+
}
|
|
4148
|
+
throwTypeMismatch("number", position);
|
|
4149
|
+
}
|
|
4150
|
+
if (param.isU32()) {
|
|
4151
|
+
if (isNumber(arg)) {
|
|
4152
|
+
return new U32(arg);
|
|
4153
|
+
}
|
|
4154
|
+
throwTypeMismatch("number", position);
|
|
4155
|
+
}
|
|
4156
|
+
if (param.isU64()) {
|
|
4157
|
+
if (isLargeNumber(arg)) {
|
|
4158
|
+
return new U64(BigInt(arg));
|
|
4159
|
+
}
|
|
4160
|
+
throwTypeMismatch("bigint | number | string", position);
|
|
4161
|
+
}
|
|
4162
|
+
if (param.isU128()) {
|
|
4163
|
+
if (isLargeNumber(arg)) {
|
|
4164
|
+
return new U128(BigInt(arg));
|
|
4165
|
+
}
|
|
4166
|
+
throwTypeMismatch("bigint | number | string", position);
|
|
4167
|
+
}
|
|
4168
|
+
if (param.isU256()) {
|
|
4169
|
+
if (isLargeNumber(arg)) {
|
|
4170
|
+
return new U256(BigInt(arg));
|
|
4171
|
+
}
|
|
4172
|
+
throwTypeMismatch("bigint | number | string", position);
|
|
4173
|
+
}
|
|
4174
|
+
if (param.isGeneric()) {
|
|
4175
|
+
const genericIndex = param.value;
|
|
4176
|
+
if (genericIndex < 0 || genericIndex >= genericTypeParams.length) {
|
|
4177
|
+
throw new Error(`Generic argument ${param.toString()} is invalid for argument ${position}`);
|
|
4178
|
+
}
|
|
4179
|
+
parseArg(arg, genericTypeParams[genericIndex], position, genericTypeParams);
|
|
4180
|
+
}
|
|
4181
|
+
if (param.isVector()) {
|
|
4182
|
+
if (param.value.isU8() && isString(arg)) {
|
|
4183
|
+
return MoveVector.U8(Hex.fromHexInput(arg).toUint8Array());
|
|
4184
|
+
}
|
|
4185
|
+
if (Array.isArray(arg)) {
|
|
4186
|
+
return new MoveVector(arg.map((item) => parseArg(item, param.value, position, genericTypeParams)));
|
|
4187
|
+
}
|
|
4188
|
+
throw new Error(`Type mismatch for argument ${position}, type '${param.toString()}'`);
|
|
4189
|
+
}
|
|
4190
|
+
if (param.isStruct()) {
|
|
4191
|
+
if (param.isString()) {
|
|
4192
|
+
if (isString(arg)) {
|
|
4193
|
+
return new MoveString(arg);
|
|
4194
|
+
}
|
|
4195
|
+
throwTypeMismatch("string", position);
|
|
4196
|
+
}
|
|
4197
|
+
if (param.isObject()) {
|
|
4198
|
+
if (isString(arg)) {
|
|
4199
|
+
return AccountAddress.fromString(arg);
|
|
4200
|
+
}
|
|
4201
|
+
throwTypeMismatch("string", position);
|
|
4202
|
+
}
|
|
4203
|
+
if (param.isOption()) {
|
|
4204
|
+
if (isNull(arg)) {
|
|
4205
|
+
return new MoveOption(null);
|
|
4206
|
+
}
|
|
4207
|
+
return new MoveOption(parseArg(arg, param.value.type_args[0], position, genericTypeParams));
|
|
4208
|
+
}
|
|
4209
|
+
throw new Error(`Unsupported struct input type for argument ${position}, type '${param.toString()}'`);
|
|
4210
|
+
}
|
|
4211
|
+
throw new Error(`Type mismatch for argument ${position}, type '${param.toString()}'`);
|
|
4212
|
+
}
|
|
4213
|
+
function checkType(functionAbi, arg, position) {
|
|
4214
|
+
const param = functionAbi.parameters[position];
|
|
4215
|
+
if (param.isBool()) {
|
|
4216
|
+
if (isBcsBool(arg)) {
|
|
4217
|
+
return;
|
|
4218
|
+
}
|
|
4219
|
+
throwTypeMismatch("Bool", position);
|
|
4220
|
+
}
|
|
4221
|
+
if (param.isAddress()) {
|
|
4222
|
+
if (isBcsAddress(arg)) {
|
|
4223
|
+
return;
|
|
4224
|
+
}
|
|
4225
|
+
throwTypeMismatch("AccountAddress", position);
|
|
4226
|
+
}
|
|
4227
|
+
if (param.isU8()) {
|
|
4228
|
+
if (isBcsU8(arg)) {
|
|
4229
|
+
return;
|
|
4230
|
+
}
|
|
4231
|
+
throwTypeMismatch("U8", position);
|
|
4232
|
+
}
|
|
4233
|
+
if (param.isU16()) {
|
|
4234
|
+
if (isBcsU16(arg)) {
|
|
4235
|
+
return;
|
|
4236
|
+
}
|
|
4237
|
+
throwTypeMismatch("U16", position);
|
|
4238
|
+
}
|
|
4239
|
+
if (param.isU32()) {
|
|
4240
|
+
if (isBcsU32(arg)) {
|
|
4241
|
+
return;
|
|
4242
|
+
}
|
|
4243
|
+
throwTypeMismatch("U32", position);
|
|
4244
|
+
}
|
|
4245
|
+
if (param.isU64()) {
|
|
4246
|
+
if (isBcsU64(arg)) {
|
|
4247
|
+
return;
|
|
4248
|
+
}
|
|
4249
|
+
throwTypeMismatch("U64", position);
|
|
4250
|
+
}
|
|
4251
|
+
if (param.isU128()) {
|
|
4252
|
+
if (isBcsU128(arg)) {
|
|
4253
|
+
return;
|
|
4254
|
+
}
|
|
4255
|
+
throwTypeMismatch("U128", position);
|
|
4256
|
+
}
|
|
4257
|
+
if (param.isU256()) {
|
|
4258
|
+
if (isBcsU256(arg)) {
|
|
4259
|
+
return;
|
|
4260
|
+
}
|
|
4261
|
+
throwTypeMismatch("U256", position);
|
|
4262
|
+
}
|
|
4263
|
+
if (param.isVector()) {
|
|
4264
|
+
if (arg instanceof MoveVector) {
|
|
4265
|
+
return;
|
|
4266
|
+
}
|
|
4267
|
+
throwTypeMismatch("MoveVector", position);
|
|
4268
|
+
}
|
|
4269
|
+
if (param instanceof TypeTagStruct) {
|
|
4270
|
+
if (param.isString()) {
|
|
4271
|
+
if (isBcsString(arg)) {
|
|
4272
|
+
return;
|
|
4273
|
+
}
|
|
4274
|
+
throwTypeMismatch("MoveString", position);
|
|
4275
|
+
}
|
|
4276
|
+
if (param.isObject()) {
|
|
4277
|
+
if (isBcsAddress(arg)) {
|
|
4278
|
+
return;
|
|
4279
|
+
}
|
|
4280
|
+
throwTypeMismatch("AccountAddress", position);
|
|
4281
|
+
}
|
|
4282
|
+
if (param.isOption()) {
|
|
4283
|
+
if (arg instanceof MoveOption) {
|
|
4284
|
+
return;
|
|
4285
|
+
}
|
|
4286
|
+
throwTypeMismatch("MoveOption", position);
|
|
4287
|
+
}
|
|
4288
|
+
}
|
|
4289
|
+
throw new Error(`Type mismatch for argument ${position}, expected '${param.toString()}'`);
|
|
4290
|
+
}
|
|
4291
|
+
|
|
4292
|
+
// src/transactions/transactionBuilder/transactionBuilder.ts
|
|
4293
|
+
async function generateTransactionPayload(args) {
|
|
4294
|
+
if (isScriptDataInput(args)) {
|
|
4295
|
+
return generateTransactionPayloadScript(args);
|
|
4296
|
+
}
|
|
4297
|
+
const { moduleAddress, moduleName, functionName } = getFunctionParts(args.function);
|
|
4298
|
+
const functionAbi = await memoizeAsync(
|
|
4299
|
+
async () => fetchEntryFunctionAbi(moduleAddress, moduleName, functionName, args.aptosConfig),
|
|
4300
|
+
`entry-function-${args.aptosConfig.network}-${moduleAddress}-${moduleName}-${functionName}`,
|
|
4301
|
+
1e3 * 60 * 5
|
|
4302
|
+
)();
|
|
4303
|
+
return generateTransactionPayloadWithABI(args, functionAbi);
|
|
4304
|
+
}
|
|
4305
|
+
function generateTransactionPayloadWithABI(args, functionAbi) {
|
|
4306
|
+
if (isScriptDataInput(args)) {
|
|
4307
|
+
return generateTransactionPayloadScript(args);
|
|
4308
|
+
}
|
|
4309
|
+
const { moduleAddress, moduleName, functionName } = getFunctionParts(args.function);
|
|
4310
|
+
const typeArguments = standardizeTypeTags(args.typeArguments);
|
|
4311
|
+
if (typeArguments.length !== functionAbi.typeParameters.length) {
|
|
4312
|
+
throw new Error(
|
|
4313
|
+
`Type argument count mismatch, expected ${functionAbi.typeParameters.length}, received ${typeArguments.length}`
|
|
4314
|
+
);
|
|
4315
|
+
}
|
|
4316
|
+
const functionArguments = args.functionArguments.map(
|
|
4317
|
+
(arg, i) => convertArgument(args.function, functionAbi, arg, i, typeArguments)
|
|
4318
|
+
);
|
|
4319
|
+
if (functionArguments.length !== functionAbi.parameters.length) {
|
|
4320
|
+
throw new Error(
|
|
4321
|
+
`Too few arguments for '${moduleAddress}::${moduleName}::${functionName}', expected ${functionAbi.parameters.length} but got ${functionArguments.length}`
|
|
3641
4322
|
);
|
|
3642
4323
|
}
|
|
4324
|
+
const entryFunctionPayload = EntryFunction.build(
|
|
4325
|
+
`${moduleAddress}::${moduleName}`,
|
|
4326
|
+
functionName,
|
|
4327
|
+
typeArguments,
|
|
4328
|
+
functionArguments
|
|
4329
|
+
);
|
|
3643
4330
|
if ("multisigAddress" in args) {
|
|
3644
|
-
|
|
4331
|
+
let multisigAddress;
|
|
4332
|
+
if (typeof args.multisigAddress === "string") {
|
|
4333
|
+
multisigAddress = AccountAddress.fromString(args.multisigAddress);
|
|
4334
|
+
} else {
|
|
4335
|
+
multisigAddress = args.multisigAddress;
|
|
4336
|
+
}
|
|
3645
4337
|
return new TransactionPayloadMultisig(
|
|
3646
|
-
new MultiSig(
|
|
3647
|
-
args.multisigAddress,
|
|
3648
|
-
new MultiSigTransactionPayload(
|
|
3649
|
-
EntryFunction.build(
|
|
3650
|
-
`${funcNameParts2[0]}::${funcNameParts2[1]}`,
|
|
3651
|
-
funcNameParts2[2],
|
|
3652
|
-
(_b = args.typeArguments) != null ? _b : [],
|
|
3653
|
-
args.arguments
|
|
3654
|
-
)
|
|
3655
|
-
)
|
|
3656
|
-
)
|
|
4338
|
+
new MultiSig(multisigAddress, new MultisigTransactionPayload(entryFunctionPayload))
|
|
3657
4339
|
);
|
|
3658
4340
|
}
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
args.arguments
|
|
3666
|
-
)
|
|
4341
|
+
return new TransactionPayloadEntryFunction(entryFunctionPayload);
|
|
4342
|
+
}
|
|
4343
|
+
function generateTransactionPayloadScript(args) {
|
|
4344
|
+
var _a;
|
|
4345
|
+
return new TransactionPayloadScript(
|
|
4346
|
+
new Script(Hex.fromHexInput(args.bytecode).toUint8Array(), (_a = args.typeArguments) != null ? _a : [], args.functionArguments)
|
|
3667
4347
|
);
|
|
3668
4348
|
}
|
|
3669
4349
|
async function generateRawTransaction(args) {
|
|
@@ -3769,26 +4449,25 @@ function generateSignedTransactionForSimulation(args) {
|
|
|
3769
4449
|
accountAuthenticator.public_key,
|
|
3770
4450
|
accountAuthenticator.signature
|
|
3771
4451
|
);
|
|
3772
|
-
} else if (accountAuthenticator instanceof
|
|
3773
|
-
transactionAuthenticator = new
|
|
3774
|
-
accountAuthenticator.public_key,
|
|
3775
|
-
accountAuthenticator.signature
|
|
3776
|
-
);
|
|
4452
|
+
} else if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
|
|
4453
|
+
transactionAuthenticator = new TransactionAuthenticatorSingleSender(accountAuthenticator);
|
|
3777
4454
|
} else {
|
|
3778
4455
|
throw new Error("Invalid public key");
|
|
3779
4456
|
}
|
|
3780
4457
|
return new SignedTransaction(deserializedTransaction, transactionAuthenticator).bcsToBytes();
|
|
3781
4458
|
}
|
|
3782
4459
|
function getAuthenticatorForSimulation(publicKey) {
|
|
3783
|
-
if (publicKey instanceof
|
|
3784
|
-
|
|
3785
|
-
new
|
|
3786
|
-
|
|
3787
|
-
)
|
|
4460
|
+
if (publicKey instanceof AnyPublicKey) {
|
|
4461
|
+
if (publicKey.publicKey instanceof Ed25519PublicKey) {
|
|
4462
|
+
return new AccountAuthenticatorSingleKey(publicKey, new AnySignature(new Ed25519Signature(new Uint8Array(64))));
|
|
4463
|
+
}
|
|
4464
|
+
if (publicKey.publicKey instanceof Secp256k1PublicKey) {
|
|
4465
|
+
return new AccountAuthenticatorSingleKey(publicKey, new AnySignature(new Secp256k1Signature(new Uint8Array(64))));
|
|
4466
|
+
}
|
|
3788
4467
|
}
|
|
3789
|
-
return new
|
|
3790
|
-
new
|
|
3791
|
-
new
|
|
4468
|
+
return new AccountAuthenticatorEd25519(
|
|
4469
|
+
new Ed25519PublicKey(publicKey.toUint8Array()),
|
|
4470
|
+
new Ed25519Signature(new Uint8Array(64))
|
|
3792
4471
|
);
|
|
3793
4472
|
}
|
|
3794
4473
|
function sign(args) {
|
|
@@ -3802,11 +4481,8 @@ function sign(args) {
|
|
|
3802
4481
|
new Ed25519PublicKey(signer.publicKey.toUint8Array()),
|
|
3803
4482
|
new Ed25519Signature(signerSignature.toUint8Array())
|
|
3804
4483
|
);
|
|
3805
|
-
case 2 /*
|
|
3806
|
-
return new
|
|
3807
|
-
new Secp256k1PublicKey(signer.publicKey.toUint8Array()),
|
|
3808
|
-
new Secp256k1Signature(signerSignature.toUint8Array())
|
|
3809
|
-
);
|
|
4484
|
+
case 2 /* SingleKey */:
|
|
4485
|
+
return new AccountAuthenticatorSingleKey(signer.publicKey, new AnySignature(signerSignature));
|
|
3810
4486
|
default:
|
|
3811
4487
|
throw new Error(`Cannot sign transaction, signing scheme ${signer.signingScheme} not supported`);
|
|
3812
4488
|
}
|
|
@@ -3821,24 +4497,19 @@ function generateSignedTransaction(args) {
|
|
|
3821
4497
|
secondarySignerAuthenticators
|
|
3822
4498
|
);
|
|
3823
4499
|
}
|
|
3824
|
-
|
|
3825
|
-
const accountAuthenticator = AccountAuthenticator.deserialize(deserializer);
|
|
3826
|
-
if (accountAuthenticator instanceof AccountAuthenticatorEd25519) {
|
|
4500
|
+
if (senderAuthenticator instanceof AccountAuthenticatorEd25519) {
|
|
3827
4501
|
const transactionAuthenticator = new TransactionAuthenticatorEd25519(
|
|
3828
|
-
|
|
3829
|
-
|
|
4502
|
+
senderAuthenticator.public_key,
|
|
4503
|
+
senderAuthenticator.signature
|
|
3830
4504
|
);
|
|
3831
4505
|
return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
|
|
3832
4506
|
}
|
|
3833
|
-
if (
|
|
3834
|
-
const transactionAuthenticator = new
|
|
3835
|
-
accountAuthenticator.public_key,
|
|
3836
|
-
accountAuthenticator.signature
|
|
3837
|
-
);
|
|
4507
|
+
if (senderAuthenticator instanceof AccountAuthenticatorSingleKey || senderAuthenticator instanceof AccountAuthenticatorMultiKey) {
|
|
4508
|
+
const transactionAuthenticator = new TransactionAuthenticatorSingleSender(senderAuthenticator);
|
|
3838
4509
|
return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
|
|
3839
4510
|
}
|
|
3840
4511
|
throw new Error(
|
|
3841
|
-
`Cannot generate a signed transaction, ${
|
|
4512
|
+
`Cannot generate a signed transaction, ${senderAuthenticator} is not a supported account authentication scheme`
|
|
3842
4513
|
);
|
|
3843
4514
|
}
|
|
3844
4515
|
function deriveTransactionType(transaction) {
|
|
@@ -3914,7 +4585,26 @@ function getSigningMessage(rawTxn) {
|
|
|
3914
4585
|
// src/internal/transactionSubmission.ts
|
|
3915
4586
|
async function generateTransaction(args) {
|
|
3916
4587
|
const { aptosConfig, sender, data, options, secondarySignerAddresses, feePayerAddress } = args;
|
|
3917
|
-
|
|
4588
|
+
let generateTransactionPayloadData;
|
|
4589
|
+
if ("bytecode" in data) {
|
|
4590
|
+
generateTransactionPayloadData = data;
|
|
4591
|
+
} else if ("multisigAddress" in data) {
|
|
4592
|
+
generateTransactionPayloadData = {
|
|
4593
|
+
aptosConfig,
|
|
4594
|
+
multisigAddress: data.multisigAddress,
|
|
4595
|
+
function: data.function,
|
|
4596
|
+
functionArguments: data.functionArguments,
|
|
4597
|
+
typeArguments: data.typeArguments
|
|
4598
|
+
};
|
|
4599
|
+
} else {
|
|
4600
|
+
generateTransactionPayloadData = {
|
|
4601
|
+
aptosConfig,
|
|
4602
|
+
function: data.function,
|
|
4603
|
+
functionArguments: data.functionArguments,
|
|
4604
|
+
typeArguments: data.typeArguments
|
|
4605
|
+
};
|
|
4606
|
+
}
|
|
4607
|
+
const payload = await generateTransactionPayload(generateTransactionPayloadData);
|
|
3918
4608
|
return buildTransaction({
|
|
3919
4609
|
aptosConfig,
|
|
3920
4610
|
sender,
|
|
@@ -3973,14 +4663,15 @@ async function signAndSubmitTransaction(args) {
|
|
|
3973
4663
|
senderAuthenticator: authenticator
|
|
3974
4664
|
});
|
|
3975
4665
|
}
|
|
3976
|
-
async function
|
|
3977
|
-
const { aptosConfig, account, metadataBytes,
|
|
4666
|
+
async function publicPackageTransaction(args) {
|
|
4667
|
+
const { aptosConfig, account, metadataBytes, moduleBytecode, options } = args;
|
|
4668
|
+
const totalByteCode = moduleBytecode.map((bytecode) => MoveVector.U8(bytecode));
|
|
3978
4669
|
const transaction = await generateTransaction({
|
|
3979
4670
|
aptosConfig,
|
|
3980
4671
|
sender: account,
|
|
3981
4672
|
data: {
|
|
3982
4673
|
function: "0x1::code::publish_package_txn",
|
|
3983
|
-
|
|
4674
|
+
functionArguments: [MoveVector.U8(metadataBytes), new MoveVector(totalByteCode)]
|
|
3984
4675
|
},
|
|
3985
4676
|
options
|
|
3986
4677
|
});
|
|
@@ -3996,8 +4687,8 @@ async function transferCoinTransaction(args) {
|
|
|
3996
4687
|
sender: sender.accountAddress.toString(),
|
|
3997
4688
|
data: {
|
|
3998
4689
|
function: "0x1::aptos_account::transfer_coins",
|
|
3999
|
-
typeArguments: [
|
|
4000
|
-
|
|
4690
|
+
typeArguments: [parseTypeTag(coinStructType)],
|
|
4691
|
+
functionArguments: [AccountAddress.fromHexInput(recipient), new U64(amount)]
|
|
4001
4692
|
},
|
|
4002
4693
|
options
|
|
4003
4694
|
});
|
|
@@ -4022,7 +4713,7 @@ async function mintTokenTransaction(args) {
|
|
|
4022
4713
|
sender: creator.accountAddress.toString(),
|
|
4023
4714
|
data: {
|
|
4024
4715
|
function: "0x4::aptos_token::mint",
|
|
4025
|
-
|
|
4716
|
+
functionArguments: [
|
|
4026
4717
|
new MoveString(args.collection),
|
|
4027
4718
|
new MoveString(args.description),
|
|
4028
4719
|
new MoveString(args.name),
|
|
@@ -4124,7 +4815,7 @@ async function createCollectionTransaction(args) {
|
|
|
4124
4815
|
sender: creator.accountAddress.toString(),
|
|
4125
4816
|
data: {
|
|
4126
4817
|
function: "0x4::aptos_token::create_collection",
|
|
4127
|
-
|
|
4818
|
+
functionArguments: [
|
|
4128
4819
|
new MoveString(args.description),
|
|
4129
4820
|
new U64((_a = args.maxSupply) != null ? _a : MAX_U64_BIG_INT),
|
|
4130
4821
|
new MoveString(args.name),
|
|
@@ -4168,9 +4859,6 @@ async function getCollectionData(args) {
|
|
|
4168
4859
|
query: graphqlQuery,
|
|
4169
4860
|
originMethod: "getCollectionData"
|
|
4170
4861
|
});
|
|
4171
|
-
if (data.current_collections_v2.length === 0) {
|
|
4172
|
-
throw Error("Collection not found");
|
|
4173
|
-
}
|
|
4174
4862
|
return data.current_collections_v2[0];
|
|
4175
4863
|
}
|
|
4176
4864
|
async function getCollectionId(args) {
|
|
@@ -4270,9 +4958,8 @@ var Event = class {
|
|
|
4270
4958
|
|
|
4271
4959
|
// src/internal/faucet.ts
|
|
4272
4960
|
async function fundAccount(args) {
|
|
4273
|
-
|
|
4274
|
-
const
|
|
4275
|
-
const timeoutSecs = (_a = args.timeoutSecs) != null ? _a : DEFAULT_TXN_TIMEOUT_SEC;
|
|
4961
|
+
const { aptosConfig, accountAddress, amount, options } = args;
|
|
4962
|
+
const timeout = (options == null ? void 0 : options.timeoutSecs) || DEFAULT_TXN_TIMEOUT_SEC;
|
|
4276
4963
|
const { data } = await postAptosFaucet({
|
|
4277
4964
|
aptosConfig,
|
|
4278
4965
|
path: "fund",
|
|
@@ -4283,7 +4970,15 @@ async function fundAccount(args) {
|
|
|
4283
4970
|
originMethod: "fundAccount"
|
|
4284
4971
|
});
|
|
4285
4972
|
const txnHash = data.txn_hashes[0];
|
|
4286
|
-
await waitForTransaction({
|
|
4973
|
+
await waitForTransaction({
|
|
4974
|
+
aptosConfig,
|
|
4975
|
+
transactionHash: txnHash,
|
|
4976
|
+
options: {
|
|
4977
|
+
timeoutSecs: timeout,
|
|
4978
|
+
checkSuccess: options == null ? void 0 : options.checkSuccess,
|
|
4979
|
+
indexerVersionCheck: options == null ? void 0 : options.indexerVersionCheck
|
|
4980
|
+
}
|
|
4981
|
+
});
|
|
4287
4982
|
return txnHash;
|
|
4288
4983
|
}
|
|
4289
4984
|
|
|
@@ -4361,6 +5056,17 @@ var FungibleAsset = class {
|
|
|
4361
5056
|
async getFungibleAssetMetadata(args) {
|
|
4362
5057
|
return getFungibleAssetMetadata({ aptosConfig: this.config, ...args });
|
|
4363
5058
|
}
|
|
5059
|
+
async getFungibleAssetMetadataByAssetType(assetType) {
|
|
5060
|
+
const data = await getFungibleAssetMetadata({
|
|
5061
|
+
aptosConfig: this.config,
|
|
5062
|
+
options: {
|
|
5063
|
+
where: {
|
|
5064
|
+
asset_type: { _eq: assetType }
|
|
5065
|
+
}
|
|
5066
|
+
}
|
|
5067
|
+
});
|
|
5068
|
+
return data[0];
|
|
5069
|
+
}
|
|
4364
5070
|
async getFungibleAssetActivities(args) {
|
|
4365
5071
|
return getFungibleAssetActivities({ aptosConfig: this.config, ...args });
|
|
4366
5072
|
}
|
|
@@ -4535,8 +5241,8 @@ var TransactionSubmission = class {
|
|
|
4535
5241
|
transaction
|
|
4536
5242
|
});
|
|
4537
5243
|
}
|
|
4538
|
-
async
|
|
4539
|
-
return
|
|
5244
|
+
async publishPackageTransaction(args) {
|
|
5245
|
+
return publicPackageTransaction({ aptosConfig: this.config, ...args });
|
|
4540
5246
|
}
|
|
4541
5247
|
};
|
|
4542
5248
|
|
|
@@ -4581,32 +5287,47 @@ export {
|
|
|
4581
5287
|
APTOS_PATH_REGEX,
|
|
4582
5288
|
Account,
|
|
4583
5289
|
AccountAddress,
|
|
5290
|
+
AccountAuthenticator,
|
|
5291
|
+
AccountAuthenticatorEd25519,
|
|
5292
|
+
AccountAuthenticatorMultiEd25519,
|
|
5293
|
+
AccountAuthenticatorMultiKey,
|
|
5294
|
+
AccountAuthenticatorSingleKey,
|
|
4584
5295
|
AccountAuthenticatorVariant,
|
|
4585
5296
|
AddressInvalidReason,
|
|
5297
|
+
AnyPublicKeyVariant,
|
|
5298
|
+
AnySignatureVariant,
|
|
4586
5299
|
Aptos,
|
|
4587
5300
|
AptosApiError,
|
|
4588
5301
|
AptosConfig,
|
|
4589
5302
|
AuthenticationKey,
|
|
4590
5303
|
Bool,
|
|
5304
|
+
ChainId,
|
|
4591
5305
|
DeriveScheme,
|
|
4592
5306
|
Deserializer,
|
|
4593
5307
|
Ed25519PrivateKey,
|
|
4594
5308
|
Ed25519PublicKey,
|
|
4595
5309
|
Ed25519Signature,
|
|
5310
|
+
EntryFunction,
|
|
4596
5311
|
EntryFunctionBytes,
|
|
5312
|
+
FeePayerRawTransaction,
|
|
4597
5313
|
FixedBytes,
|
|
4598
5314
|
Hex,
|
|
4599
5315
|
HexInvalidReason,
|
|
5316
|
+
Identifier,
|
|
4600
5317
|
KeyType,
|
|
4601
5318
|
MimeType,
|
|
5319
|
+
ModuleId,
|
|
4602
5320
|
MoveAbility,
|
|
4603
5321
|
MoveFunctionVisibility,
|
|
4604
|
-
MoveObject,
|
|
4605
5322
|
MoveOption,
|
|
4606
5323
|
MoveString,
|
|
4607
5324
|
MoveVector,
|
|
5325
|
+
MultiAgentRawTransaction,
|
|
4608
5326
|
MultiEd25519PublicKey,
|
|
4609
5327
|
MultiEd25519Signature,
|
|
5328
|
+
MultiKey,
|
|
5329
|
+
MultiSig,
|
|
5330
|
+
MultisigTransactionPayload,
|
|
4610
5331
|
Network,
|
|
4611
5332
|
NetworkToChainId,
|
|
4612
5333
|
NetworkToFaucetAPI,
|
|
@@ -4615,7 +5336,10 @@ export {
|
|
|
4615
5336
|
ParsingError,
|
|
4616
5337
|
PrivateKey,
|
|
4617
5338
|
PublicKey,
|
|
5339
|
+
RawTransaction,
|
|
5340
|
+
RawTransactionWithData,
|
|
4618
5341
|
RoleType,
|
|
5342
|
+
Script,
|
|
4619
5343
|
ScriptTransactionArgumentVariants,
|
|
4620
5344
|
Secp256k1PrivateKey,
|
|
4621
5345
|
Secp256k1PublicKey,
|
|
@@ -4623,17 +5347,31 @@ export {
|
|
|
4623
5347
|
Serializable,
|
|
4624
5348
|
Serializer,
|
|
4625
5349
|
Signature,
|
|
5350
|
+
SignedTransaction,
|
|
4626
5351
|
SigningScheme,
|
|
5352
|
+
SigningSchemeInput,
|
|
4627
5353
|
StructTag,
|
|
5354
|
+
TransactionAuthenticator,
|
|
5355
|
+
TransactionAuthenticatorEd25519,
|
|
5356
|
+
TransactionAuthenticatorFeePayer,
|
|
5357
|
+
TransactionAuthenticatorMultiAgent,
|
|
5358
|
+
TransactionAuthenticatorMultiEd25519,
|
|
5359
|
+
TransactionAuthenticatorSingleSender,
|
|
4628
5360
|
TransactionAuthenticatorVariant,
|
|
5361
|
+
TransactionPayload,
|
|
5362
|
+
TransactionPayloadEntryFunction,
|
|
5363
|
+
TransactionPayloadMultisig,
|
|
5364
|
+
TransactionPayloadScript,
|
|
4629
5365
|
TransactionPayloadVariants,
|
|
4630
5366
|
TransactionResponseType,
|
|
4631
5367
|
TransactionVariants,
|
|
4632
5368
|
TypeTag,
|
|
4633
5369
|
TypeTagAddress,
|
|
4634
5370
|
TypeTagBool,
|
|
4635
|
-
|
|
5371
|
+
TypeTagGeneric,
|
|
4636
5372
|
TypeTagParserError,
|
|
5373
|
+
TypeTagParserErrorType,
|
|
5374
|
+
TypeTagReference,
|
|
4637
5375
|
TypeTagSigner,
|
|
4638
5376
|
TypeTagStruct,
|
|
4639
5377
|
TypeTagU128,
|
|
@@ -4650,22 +5388,58 @@ export {
|
|
|
4650
5388
|
U32,
|
|
4651
5389
|
U64,
|
|
4652
5390
|
U8,
|
|
5391
|
+
aptosCoinStructTag,
|
|
4653
5392
|
aptosRequest,
|
|
5393
|
+
buildTransaction,
|
|
5394
|
+
convertArgument,
|
|
4654
5395
|
derivePrivateKeyFromMnemonic,
|
|
5396
|
+
deriveTransactionType,
|
|
5397
|
+
deserializeFromScriptArgument,
|
|
4655
5398
|
ensureBoolean,
|
|
5399
|
+
fetchEntryFunctionAbi,
|
|
5400
|
+
findFirstNonSignerArg,
|
|
5401
|
+
generateMultiSignersSignedTransaction,
|
|
5402
|
+
generateRawTransaction,
|
|
5403
|
+
generateSignedTransaction,
|
|
5404
|
+
generateSignedTransactionForSimulation,
|
|
5405
|
+
generateTransactionPayload,
|
|
5406
|
+
generateTransactionPayloadWithABI,
|
|
4656
5407
|
get,
|
|
4657
5408
|
getAptosFullNode,
|
|
5409
|
+
getAuthenticatorForSimulation,
|
|
5410
|
+
getFunctionParts,
|
|
5411
|
+
getSigningMessage,
|
|
5412
|
+
isBcsAddress,
|
|
5413
|
+
isBcsBool,
|
|
5414
|
+
isBcsFixedBytes,
|
|
5415
|
+
isBcsString,
|
|
5416
|
+
isBcsU128,
|
|
5417
|
+
isBcsU16,
|
|
5418
|
+
isBcsU256,
|
|
5419
|
+
isBcsU32,
|
|
5420
|
+
isBcsU64,
|
|
5421
|
+
isBcsU8,
|
|
5422
|
+
isBool,
|
|
5423
|
+
isLargeNumber,
|
|
5424
|
+
isNull,
|
|
5425
|
+
isNumber,
|
|
5426
|
+
isScriptDataInput,
|
|
5427
|
+
isString,
|
|
4658
5428
|
isValidPath,
|
|
4659
5429
|
objectStructTag,
|
|
4660
5430
|
optionStructTag,
|
|
4661
5431
|
outOfRangeErrorMessage,
|
|
4662
5432
|
paginateWithCursor,
|
|
5433
|
+
parseTypeTag,
|
|
4663
5434
|
post,
|
|
4664
5435
|
postAptosFaucet,
|
|
4665
5436
|
postAptosFullNode,
|
|
4666
5437
|
postAptosIndexer,
|
|
4667
5438
|
request,
|
|
5439
|
+
sign,
|
|
5440
|
+
standardizeTypeTags,
|
|
4668
5441
|
stringStructTag,
|
|
5442
|
+
throwTypeMismatch,
|
|
4669
5443
|
validateNumberInRange
|
|
4670
5444
|
};
|
|
4671
5445
|
//# sourceMappingURL=index.mjs.map
|