@aptos-labs/ts-sdk 0.0.0 → 0.0.2
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 +12 -2
- package/dist/browser/index.global.js +25 -25
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.d.ts +209 -45
- package/dist/cjs/index.js +338 -108
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +209 -45
- package/dist/esm/index.mjs +334 -108
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +84 -16
- package/dist/types/index.js +26 -3
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/account.ts +26 -6
- package/src/api/aptosConfig.ts +8 -1
- package/src/api/fungibleAsset.ts +25 -0
- package/src/api/general.ts +2 -2
- package/src/api/transaction.ts +9 -2
- package/src/api/transactionSubmission.ts +34 -10
- package/src/bcs/serializable/fixedBytes.ts +1 -1
- package/src/client/core.ts +15 -17
- package/src/client/get.ts +1 -1
- package/src/client/post.ts +2 -2
- package/src/core/account.ts +74 -33
- package/src/core/authenticationKey.ts +29 -13
- package/src/core/crypto/anyPublicKey.ts +84 -0
- package/src/core/crypto/anySignature.ts +56 -0
- package/src/core/crypto/ed25519.ts +10 -0
- package/src/core/crypto/secp256k1.ts +11 -1
- package/src/internal/account.ts +78 -6
- package/src/internal/coin.ts +1 -1
- package/src/internal/digitalAsset.ts +2 -6
- package/src/internal/faucet.ts +5 -1
- package/src/internal/general.ts +1 -1
- package/src/internal/transaction.ts +2 -1
- package/src/internal/transactionSubmission.ts +47 -6
- package/src/transactions/authenticator/account.ts +16 -15
- package/src/transactions/authenticator/transaction.ts +15 -22
- package/src/transactions/transaction_builder/transaction_builder.ts +27 -28
- package/src/transactions/typeTag/parser.ts +285 -0
- package/src/transactions/types.ts +2 -2
- package/src/types/index.ts +93 -15
- package/src/version.ts +1 -1
package/dist/cjs/index.js
CHANGED
|
@@ -40,6 +40,8 @@ __export(src_exports, {
|
|
|
40
40
|
AccountAddress: () => AccountAddress,
|
|
41
41
|
AccountAuthenticatorVariant: () => AccountAuthenticatorVariant,
|
|
42
42
|
AddressInvalidReason: () => AddressInvalidReason,
|
|
43
|
+
AnyPublicKeyVariant: () => AnyPublicKeyVariant,
|
|
44
|
+
AnySignatureVariant: () => AnySignatureVariant,
|
|
43
45
|
Aptos: () => Aptos,
|
|
44
46
|
AptosApiError: () => AptosApiError,
|
|
45
47
|
AptosConfig: () => AptosConfig,
|
|
@@ -81,6 +83,7 @@ __export(src_exports, {
|
|
|
81
83
|
Serializer: () => Serializer,
|
|
82
84
|
Signature: () => Signature,
|
|
83
85
|
SigningScheme: () => SigningScheme,
|
|
86
|
+
SigningSchemeInput: () => SigningSchemeInput,
|
|
84
87
|
StructTag: () => StructTag,
|
|
85
88
|
TransactionAuthenticatorVariant: () => TransactionAuthenticatorVariant,
|
|
86
89
|
TransactionPayloadVariants: () => TransactionPayloadVariants,
|
|
@@ -121,14 +124,12 @@ __export(src_exports, {
|
|
|
121
124
|
postAptosFaucet: () => postAptosFaucet,
|
|
122
125
|
postAptosFullNode: () => postAptosFullNode,
|
|
123
126
|
postAptosIndexer: () => postAptosIndexer,
|
|
127
|
+
request: () => request,
|
|
124
128
|
stringStructTag: () => stringStructTag,
|
|
125
129
|
validateNumberInRange: () => validateNumberInRange
|
|
126
130
|
});
|
|
127
131
|
module.exports = __toCommonJS(src_exports);
|
|
128
132
|
|
|
129
|
-
// src/client/core.ts
|
|
130
|
-
var import_aptos_client = __toESM(require("@aptos-labs/aptos-client"));
|
|
131
|
-
|
|
132
133
|
// src/client/types.ts
|
|
133
134
|
var AptosApiError = class extends Error {
|
|
134
135
|
constructor(request2, response, message) {
|
|
@@ -142,6 +143,9 @@ var AptosApiError = class extends Error {
|
|
|
142
143
|
}
|
|
143
144
|
};
|
|
144
145
|
|
|
146
|
+
// src/version.ts
|
|
147
|
+
var VERSION = "2.0.0";
|
|
148
|
+
|
|
145
149
|
// src/types/index.ts
|
|
146
150
|
var MimeType = /* @__PURE__ */ ((MimeType2) => {
|
|
147
151
|
MimeType2["JSON"] = "application/json";
|
|
@@ -191,15 +195,26 @@ var TransactionAuthenticatorVariant = /* @__PURE__ */ ((TransactionAuthenticator
|
|
|
191
195
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
192
196
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiAgent"] = 2] = "MultiAgent";
|
|
193
197
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["FeePayer"] = 3] = "FeePayer";
|
|
194
|
-
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["
|
|
198
|
+
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["SingleSenderTransactionAuthenticator"] = 4] = "SingleSenderTransactionAuthenticator";
|
|
195
199
|
return TransactionAuthenticatorVariant2;
|
|
196
200
|
})(TransactionAuthenticatorVariant || {});
|
|
197
201
|
var AccountAuthenticatorVariant = /* @__PURE__ */ ((AccountAuthenticatorVariant2) => {
|
|
198
202
|
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Ed25519"] = 0] = "Ed25519";
|
|
199
203
|
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
200
|
-
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["
|
|
204
|
+
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["SingleKey"] = 2] = "SingleKey";
|
|
205
|
+
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiKey"] = 3] = "MultiKey";
|
|
201
206
|
return AccountAuthenticatorVariant2;
|
|
202
207
|
})(AccountAuthenticatorVariant || {});
|
|
208
|
+
var AnyPublicKeyVariant = /* @__PURE__ */ ((AnyPublicKeyVariant2) => {
|
|
209
|
+
AnyPublicKeyVariant2[AnyPublicKeyVariant2["Ed25519"] = 0] = "Ed25519";
|
|
210
|
+
AnyPublicKeyVariant2[AnyPublicKeyVariant2["Secp256k1"] = 1] = "Secp256k1";
|
|
211
|
+
return AnyPublicKeyVariant2;
|
|
212
|
+
})(AnyPublicKeyVariant || {});
|
|
213
|
+
var AnySignatureVariant = /* @__PURE__ */ ((AnySignatureVariant2) => {
|
|
214
|
+
AnySignatureVariant2[AnySignatureVariant2["Ed25519"] = 0] = "Ed25519";
|
|
215
|
+
AnySignatureVariant2[AnySignatureVariant2["Secp256k1"] = 1] = "Secp256k1";
|
|
216
|
+
return AnySignatureVariant2;
|
|
217
|
+
})(AnySignatureVariant || {});
|
|
203
218
|
var TransactionResponseType = /* @__PURE__ */ ((TransactionResponseType2) => {
|
|
204
219
|
TransactionResponseType2["Pending"] = "pending_transaction";
|
|
205
220
|
TransactionResponseType2["User"] = "user_transaction";
|
|
@@ -229,9 +244,15 @@ var RoleType = /* @__PURE__ */ ((RoleType2) => {
|
|
|
229
244
|
var SigningScheme = /* @__PURE__ */ ((SigningScheme2) => {
|
|
230
245
|
SigningScheme2[SigningScheme2["Ed25519"] = 0] = "Ed25519";
|
|
231
246
|
SigningScheme2[SigningScheme2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
232
|
-
SigningScheme2[SigningScheme2["
|
|
247
|
+
SigningScheme2[SigningScheme2["SingleKey"] = 2] = "SingleKey";
|
|
233
248
|
return SigningScheme2;
|
|
234
249
|
})(SigningScheme || {});
|
|
250
|
+
var SigningSchemeInput = /* @__PURE__ */ ((SigningSchemeInput2) => {
|
|
251
|
+
SigningSchemeInput2[SigningSchemeInput2["Ed25519"] = 0] = "Ed25519";
|
|
252
|
+
SigningSchemeInput2[SigningSchemeInput2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
253
|
+
SigningSchemeInput2[SigningSchemeInput2["Secp256k1Ecdsa"] = 2] = "Secp256k1Ecdsa";
|
|
254
|
+
return SigningSchemeInput2;
|
|
255
|
+
})(SigningSchemeInput || {});
|
|
235
256
|
var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
|
|
236
257
|
DeriveScheme2[DeriveScheme2["DeriveAuid"] = 251] = "DeriveAuid";
|
|
237
258
|
DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromObject"] = 252] = "DeriveObjectAddressFromObject";
|
|
@@ -241,9 +262,6 @@ var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
|
|
|
241
262
|
return DeriveScheme2;
|
|
242
263
|
})(DeriveScheme || {});
|
|
243
264
|
|
|
244
|
-
// src/version.ts
|
|
245
|
-
var VERSION = "0.0.0";
|
|
246
|
-
|
|
247
265
|
// src/client/core.ts
|
|
248
266
|
var errors = {
|
|
249
267
|
400: "Bad Request",
|
|
@@ -255,7 +273,8 @@ var errors = {
|
|
|
255
273
|
502: "Bad Gateway",
|
|
256
274
|
503: "Service Unavailable"
|
|
257
275
|
};
|
|
258
|
-
async function request(
|
|
276
|
+
async function request(options, client) {
|
|
277
|
+
const { url, method, body, contentType, params, overrides } = options;
|
|
259
278
|
const headers = {
|
|
260
279
|
...overrides == null ? void 0 : overrides.HEADERS,
|
|
261
280
|
"x-aptos-client": `aptos-ts-sdk/${VERSION}`,
|
|
@@ -264,7 +283,7 @@ async function request(url, method, body, contentType, params, overrides) {
|
|
|
264
283
|
if (overrides == null ? void 0 : overrides.TOKEN) {
|
|
265
284
|
headers.Authorization = `Bearer ${overrides == null ? void 0 : overrides.TOKEN}`;
|
|
266
285
|
}
|
|
267
|
-
return
|
|
286
|
+
return client.provider({
|
|
268
287
|
url,
|
|
269
288
|
method,
|
|
270
289
|
body,
|
|
@@ -275,26 +294,28 @@ async function request(url, method, body, contentType, params, overrides) {
|
|
|
275
294
|
}
|
|
276
295
|
async function aptosRequest(options, aptosConfig) {
|
|
277
296
|
var _a;
|
|
278
|
-
const { url, path
|
|
297
|
+
const { url, path } = options;
|
|
279
298
|
const fullUrl = `${url}/${path != null ? path : ""}`;
|
|
280
|
-
const response = await request(
|
|
299
|
+
const response = await request({ ...options, url: fullUrl }, aptosConfig.client);
|
|
281
300
|
const result = {
|
|
282
301
|
status: response.status,
|
|
283
302
|
statusText: response.statusText,
|
|
284
303
|
data: response.data,
|
|
285
304
|
headers: response.headers,
|
|
286
305
|
config: response.config,
|
|
306
|
+
request: response.request,
|
|
287
307
|
url: fullUrl
|
|
288
308
|
};
|
|
289
309
|
if (aptosConfig.isIndexerRequest(url)) {
|
|
290
|
-
|
|
310
|
+
const indexerResponse = result.data;
|
|
311
|
+
if (indexerResponse.errors) {
|
|
291
312
|
throw new AptosApiError(
|
|
292
313
|
options,
|
|
293
314
|
result,
|
|
294
|
-
(_a =
|
|
315
|
+
(_a = indexerResponse.errors[0].message) != null ? _a : `Unhandled Error ${response.status} : ${response.statusText}`
|
|
295
316
|
);
|
|
296
317
|
}
|
|
297
|
-
result.data =
|
|
318
|
+
result.data = indexerResponse.data;
|
|
298
319
|
}
|
|
299
320
|
if (result.status >= 200 && result.status < 300) {
|
|
300
321
|
return result;
|
|
@@ -362,7 +383,7 @@ async function get(options) {
|
|
|
362
383
|
acceptType: acceptType == null ? void 0 : acceptType.valueOf(),
|
|
363
384
|
params,
|
|
364
385
|
overrides: {
|
|
365
|
-
...aptosConfig,
|
|
386
|
+
...aptosConfig.clientConfig,
|
|
366
387
|
...overrides
|
|
367
388
|
}
|
|
368
389
|
},
|
|
@@ -410,7 +431,7 @@ async function post(options) {
|
|
|
410
431
|
acceptType: acceptType == null ? void 0 : acceptType.valueOf(),
|
|
411
432
|
params,
|
|
412
433
|
overrides: {
|
|
413
|
-
...aptosConfig,
|
|
434
|
+
...aptosConfig.clientConfig,
|
|
414
435
|
...overrides
|
|
415
436
|
}
|
|
416
437
|
},
|
|
@@ -1298,6 +1319,10 @@ var _Ed25519PublicKey = class extends PublicKey {
|
|
|
1298
1319
|
const bytes = deserializer.deserializeBytes();
|
|
1299
1320
|
return new _Ed25519PublicKey(bytes);
|
|
1300
1321
|
}
|
|
1322
|
+
static load(deserializer) {
|
|
1323
|
+
const bytes = deserializer.deserializeBytes();
|
|
1324
|
+
return new _Ed25519PublicKey(bytes);
|
|
1325
|
+
}
|
|
1301
1326
|
};
|
|
1302
1327
|
var Ed25519PublicKey = _Ed25519PublicKey;
|
|
1303
1328
|
Ed25519PublicKey.LENGTH = 32;
|
|
@@ -1361,6 +1386,10 @@ var _Ed25519Signature = class extends Signature {
|
|
|
1361
1386
|
const bytes = deserializer.deserializeBytes();
|
|
1362
1387
|
return new _Ed25519Signature(bytes);
|
|
1363
1388
|
}
|
|
1389
|
+
static load(deserializer) {
|
|
1390
|
+
const bytes = deserializer.deserializeBytes();
|
|
1391
|
+
return new _Ed25519Signature(bytes);
|
|
1392
|
+
}
|
|
1364
1393
|
};
|
|
1365
1394
|
var Ed25519Signature = _Ed25519Signature;
|
|
1366
1395
|
Ed25519Signature.LENGTH = 64;
|
|
@@ -1511,6 +1540,10 @@ var _Secp256k1PublicKey = class extends PublicKey {
|
|
|
1511
1540
|
const bytes = deserializer.deserializeBytes();
|
|
1512
1541
|
return new _Secp256k1PublicKey(bytes);
|
|
1513
1542
|
}
|
|
1543
|
+
static load(deserializer) {
|
|
1544
|
+
const bytes = deserializer.deserializeBytes();
|
|
1545
|
+
return new _Secp256k1PublicKey(bytes);
|
|
1546
|
+
}
|
|
1514
1547
|
};
|
|
1515
1548
|
var Secp256k1PublicKey = _Secp256k1PublicKey;
|
|
1516
1549
|
Secp256k1PublicKey.LENGTH = 65;
|
|
@@ -1558,7 +1591,7 @@ var _Secp256k1Signature = class extends Signature {
|
|
|
1558
1591
|
super();
|
|
1559
1592
|
const hex = Hex.fromHexInput(hexInput);
|
|
1560
1593
|
if (hex.toUint8Array().length !== _Secp256k1Signature.LENGTH) {
|
|
1561
|
-
throw new Error(`Signature length should be ${_Secp256k1Signature.LENGTH}`);
|
|
1594
|
+
throw new Error(`Signature length should be ${_Secp256k1Signature.LENGTH}, recieved ${hex.toUint8Array().length}`);
|
|
1562
1595
|
}
|
|
1563
1596
|
this.data = hex;
|
|
1564
1597
|
}
|
|
@@ -1575,10 +1608,66 @@ var _Secp256k1Signature = class extends Signature {
|
|
|
1575
1608
|
const hex = deserializer.deserializeBytes();
|
|
1576
1609
|
return new _Secp256k1Signature(hex);
|
|
1577
1610
|
}
|
|
1611
|
+
static load(deserializer) {
|
|
1612
|
+
const bytes = deserializer.deserializeBytes();
|
|
1613
|
+
return new _Secp256k1Signature(bytes);
|
|
1614
|
+
}
|
|
1578
1615
|
};
|
|
1579
1616
|
var Secp256k1Signature = _Secp256k1Signature;
|
|
1580
1617
|
Secp256k1Signature.LENGTH = 64;
|
|
1581
1618
|
|
|
1619
|
+
// src/core/crypto/anyPublicKey.ts
|
|
1620
|
+
var AnyPublicKey = class extends PublicKey {
|
|
1621
|
+
constructor(publicKey) {
|
|
1622
|
+
super();
|
|
1623
|
+
this.publicKey = publicKey;
|
|
1624
|
+
}
|
|
1625
|
+
toUint8Array() {
|
|
1626
|
+
return this.publicKey.toUint8Array();
|
|
1627
|
+
}
|
|
1628
|
+
toString() {
|
|
1629
|
+
return this.publicKey.toString();
|
|
1630
|
+
}
|
|
1631
|
+
verifySignature(args) {
|
|
1632
|
+
const { message, signature } = args;
|
|
1633
|
+
if (this.isED25519Signature(signature)) {
|
|
1634
|
+
return this.publicKey.verifySignature({ message, signature: signature.signature });
|
|
1635
|
+
} else if (this.isSecp256k1Signature(signature)) {
|
|
1636
|
+
return this.publicKey.verifySignature({ message, signature: signature.signature });
|
|
1637
|
+
} else {
|
|
1638
|
+
throw new Error("Unknown public key type");
|
|
1639
|
+
}
|
|
1640
|
+
}
|
|
1641
|
+
isED25519Signature(signature) {
|
|
1642
|
+
return this.publicKey instanceof Ed25519PublicKey && signature.signature instanceof Ed25519Signature;
|
|
1643
|
+
}
|
|
1644
|
+
isSecp256k1Signature(signature) {
|
|
1645
|
+
return this.publicKey instanceof Secp256k1PublicKey && signature.signature instanceof Secp256k1Signature;
|
|
1646
|
+
}
|
|
1647
|
+
serialize(serializer) {
|
|
1648
|
+
if (this.publicKey instanceof Ed25519PublicKey) {
|
|
1649
|
+
serializer.serializeU32AsUleb128(0 /* Ed25519 */);
|
|
1650
|
+
this.publicKey.serialize(serializer);
|
|
1651
|
+
} else if (this.publicKey instanceof Secp256k1PublicKey) {
|
|
1652
|
+
serializer.serializeU32AsUleb128(1 /* Secp256k1 */);
|
|
1653
|
+
this.publicKey.serialize(serializer);
|
|
1654
|
+
} else {
|
|
1655
|
+
throw new Error("Unknown public key type");
|
|
1656
|
+
}
|
|
1657
|
+
}
|
|
1658
|
+
static deserialize(deserializer) {
|
|
1659
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
1660
|
+
switch (index) {
|
|
1661
|
+
case 0 /* Ed25519 */:
|
|
1662
|
+
return new AnyPublicKey(Ed25519PublicKey.load(deserializer));
|
|
1663
|
+
case 1 /* Secp256k1 */:
|
|
1664
|
+
return new AnyPublicKey(Secp256k1PublicKey.load(deserializer));
|
|
1665
|
+
default:
|
|
1666
|
+
throw new Error(`Unknown variant index for AnyPublicKey: ${index}`);
|
|
1667
|
+
}
|
|
1668
|
+
}
|
|
1669
|
+
};
|
|
1670
|
+
|
|
1582
1671
|
// src/core/authenticationKey.ts
|
|
1583
1672
|
var _AuthenticationKey = class {
|
|
1584
1673
|
constructor(args) {
|
|
@@ -1595,15 +1684,29 @@ var _AuthenticationKey = class {
|
|
|
1595
1684
|
toUint8Array() {
|
|
1596
1685
|
return this.data.toUint8Array();
|
|
1597
1686
|
}
|
|
1598
|
-
static
|
|
1599
|
-
const {
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1687
|
+
static fromPublicKeyAndScheme(args) {
|
|
1688
|
+
const { publicKey, scheme } = args;
|
|
1689
|
+
let authKeyBytes;
|
|
1690
|
+
switch (scheme) {
|
|
1691
|
+
case 2 /* SingleKey */: {
|
|
1692
|
+
const singleKeyBytes = publicKey.bcsToBytes();
|
|
1693
|
+
authKeyBytes = new Uint8Array([...singleKeyBytes, scheme]);
|
|
1694
|
+
break;
|
|
1695
|
+
}
|
|
1696
|
+
case 0 /* Ed25519 */:
|
|
1697
|
+
case 1 /* MultiEd25519 */: {
|
|
1698
|
+
const ed25519PublicKeyBytes = publicKey.toUint8Array();
|
|
1699
|
+
const inputBytes = Hex.fromHexInput(ed25519PublicKeyBytes).toUint8Array();
|
|
1700
|
+
authKeyBytes = new Uint8Array([...inputBytes, scheme]);
|
|
1701
|
+
break;
|
|
1702
|
+
}
|
|
1703
|
+
default:
|
|
1704
|
+
throw new Error(`Scheme ${scheme} is not supported`);
|
|
1705
|
+
}
|
|
1604
1706
|
const hash = import_sha32.sha3_256.create();
|
|
1605
1707
|
hash.update(authKeyBytes);
|
|
1606
|
-
|
|
1708
|
+
const hashDigest = hash.digest();
|
|
1709
|
+
return new _AuthenticationKey({ data: hashDigest });
|
|
1607
1710
|
}
|
|
1608
1711
|
static fromPublicKey(args) {
|
|
1609
1712
|
const { publicKey } = args;
|
|
@@ -1612,13 +1715,12 @@ var _AuthenticationKey = class {
|
|
|
1612
1715
|
scheme = 0 /* Ed25519 */.valueOf();
|
|
1613
1716
|
} else if (publicKey instanceof MultiEd25519PublicKey) {
|
|
1614
1717
|
scheme = 1 /* MultiEd25519 */.valueOf();
|
|
1615
|
-
} else if (publicKey instanceof
|
|
1616
|
-
scheme = 2 /*
|
|
1718
|
+
} else if (publicKey instanceof AnyPublicKey) {
|
|
1719
|
+
scheme = 2 /* SingleKey */.valueOf();
|
|
1617
1720
|
} else {
|
|
1618
1721
|
throw new Error("No supported authentication scheme for public key");
|
|
1619
1722
|
}
|
|
1620
|
-
|
|
1621
|
-
return _AuthenticationKey.fromBytesAndScheme({ bytes: pubKeyBytes, scheme });
|
|
1723
|
+
return _AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme });
|
|
1622
1724
|
}
|
|
1623
1725
|
derivedAddress() {
|
|
1624
1726
|
return new AccountAddress({ data: this.data.toUint8Array() });
|
|
@@ -1676,50 +1778,58 @@ var derivePrivateKeyFromMnemonic = (keyType, path, seedPhrase, offset = HARDENED
|
|
|
1676
1778
|
// src/core/account.ts
|
|
1677
1779
|
var Account = class {
|
|
1678
1780
|
constructor(args) {
|
|
1679
|
-
const { privateKey, address } = args;
|
|
1781
|
+
const { privateKey, address, legacy } = args;
|
|
1680
1782
|
this.publicKey = privateKey.publicKey();
|
|
1681
1783
|
if (this.publicKey instanceof Ed25519PublicKey) {
|
|
1682
|
-
|
|
1784
|
+
if (legacy) {
|
|
1785
|
+
this.signingScheme = 0 /* Ed25519 */;
|
|
1786
|
+
} else {
|
|
1787
|
+
this.publicKey = new AnyPublicKey(this.publicKey);
|
|
1788
|
+
this.signingScheme = 2 /* SingleKey */;
|
|
1789
|
+
}
|
|
1683
1790
|
} else if (this.publicKey instanceof MultiEd25519PublicKey) {
|
|
1684
1791
|
this.signingScheme = 1 /* MultiEd25519 */;
|
|
1685
1792
|
} else if (this.publicKey instanceof Secp256k1PublicKey) {
|
|
1686
|
-
this.
|
|
1793
|
+
this.publicKey = new AnyPublicKey(this.publicKey);
|
|
1794
|
+
this.signingScheme = 2 /* SingleKey */;
|
|
1687
1795
|
} else {
|
|
1688
1796
|
throw new Error("Can not create new Account, unsupported public key type");
|
|
1689
1797
|
}
|
|
1690
1798
|
this.privateKey = privateKey;
|
|
1691
1799
|
this.accountAddress = address;
|
|
1692
1800
|
}
|
|
1693
|
-
static generate(
|
|
1801
|
+
static generate(args) {
|
|
1694
1802
|
let privateKey;
|
|
1695
|
-
switch (scheme) {
|
|
1803
|
+
switch (args == null ? void 0 : args.scheme) {
|
|
1696
1804
|
case 2 /* Secp256k1Ecdsa */:
|
|
1697
1805
|
privateKey = Secp256k1PrivateKey.generate();
|
|
1698
1806
|
break;
|
|
1699
1807
|
default:
|
|
1700
1808
|
privateKey = Ed25519PrivateKey.generate();
|
|
1701
1809
|
}
|
|
1810
|
+
let publicKey = privateKey.publicKey();
|
|
1811
|
+
if (!(args == null ? void 0 : args.legacy)) {
|
|
1812
|
+
publicKey = new AnyPublicKey(privateKey.publicKey());
|
|
1813
|
+
}
|
|
1702
1814
|
const address = new AccountAddress({
|
|
1703
1815
|
data: Account.authKey({
|
|
1704
|
-
publicKey
|
|
1816
|
+
publicKey
|
|
1705
1817
|
}).toUint8Array()
|
|
1706
1818
|
});
|
|
1707
|
-
return new Account({ privateKey, address });
|
|
1708
|
-
}
|
|
1709
|
-
static fromPrivateKey(privateKey) {
|
|
1710
|
-
const publicKey = privateKey.publicKey();
|
|
1711
|
-
const authKey = Account.authKey({ publicKey });
|
|
1712
|
-
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
1713
|
-
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
1819
|
+
return new Account({ privateKey, address, legacy: args == null ? void 0 : args.legacy });
|
|
1714
1820
|
}
|
|
1715
|
-
static
|
|
1716
|
-
|
|
1821
|
+
static fromPrivateKey(args) {
|
|
1822
|
+
const { privateKey, address, legacy } = args;
|
|
1823
|
+
return new Account({ privateKey, address, legacy });
|
|
1717
1824
|
}
|
|
1718
1825
|
static fromDerivationPath(args) {
|
|
1719
1826
|
const { path, mnemonic } = args;
|
|
1720
1827
|
const { key } = derivePrivateKeyFromMnemonic("ed25519 seed" /* ED25519 */, path, mnemonic);
|
|
1721
1828
|
const privateKey = new Ed25519PrivateKey(key);
|
|
1722
|
-
|
|
1829
|
+
const publicKey = privateKey.publicKey();
|
|
1830
|
+
const authKey = Account.authKey({ publicKey });
|
|
1831
|
+
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
1832
|
+
return new Account({ privateKey, address, legacy: true });
|
|
1723
1833
|
}
|
|
1724
1834
|
static authKey(args) {
|
|
1725
1835
|
const { publicKey } = args;
|
|
@@ -2216,7 +2326,7 @@ async function view(args) {
|
|
|
2216
2326
|
body: {
|
|
2217
2327
|
function: payload.function,
|
|
2218
2328
|
type_arguments: (_a = payload.typeArguments) != null ? _a : [],
|
|
2219
|
-
arguments: (_b = payload.
|
|
2329
|
+
arguments: (_b = payload.functionArguments) != null ? _b : []
|
|
2220
2330
|
}
|
|
2221
2331
|
});
|
|
2222
2332
|
return data;
|
|
@@ -2354,7 +2464,7 @@ async function getResource(args) {
|
|
|
2354
2464
|
path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/resource/${resourceType}`,
|
|
2355
2465
|
params: { ledger_version: options == null ? void 0 : options.ledgerVersion }
|
|
2356
2466
|
});
|
|
2357
|
-
return data;
|
|
2467
|
+
return data.data;
|
|
2358
2468
|
}
|
|
2359
2469
|
async function lookupOriginalAccountAddress(args) {
|
|
2360
2470
|
const { aptosConfig, authenticationKey, options } = args;
|
|
@@ -2366,7 +2476,7 @@ async function lookupOriginalAccountAddress(args) {
|
|
|
2366
2476
|
});
|
|
2367
2477
|
const {
|
|
2368
2478
|
address_map: { handle }
|
|
2369
|
-
} = resource
|
|
2479
|
+
} = resource;
|
|
2370
2480
|
try {
|
|
2371
2481
|
const originalAddress = await getTableItem({
|
|
2372
2482
|
aptosConfig,
|
|
@@ -2572,6 +2682,55 @@ async function getAccountOwnedObjects(args) {
|
|
|
2572
2682
|
});
|
|
2573
2683
|
return data.current_objects;
|
|
2574
2684
|
}
|
|
2685
|
+
async function deriveAccountFromPrivateKey(args) {
|
|
2686
|
+
const { aptosConfig, privateKey } = args;
|
|
2687
|
+
const publicKey = new AnyPublicKey(privateKey.publicKey());
|
|
2688
|
+
if (privateKey instanceof Secp256k1PrivateKey) {
|
|
2689
|
+
const authKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: 2 /* SingleKey */ });
|
|
2690
|
+
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
2691
|
+
return Account.fromPrivateKey({ privateKey, address });
|
|
2692
|
+
}
|
|
2693
|
+
if (privateKey instanceof Ed25519PrivateKey) {
|
|
2694
|
+
const SingleSenderTransactionAuthenticatorAuthKey = AuthenticationKey.fromPublicKeyAndScheme({
|
|
2695
|
+
publicKey,
|
|
2696
|
+
scheme: 2 /* SingleKey */
|
|
2697
|
+
});
|
|
2698
|
+
const isSingleSenderTransactionAuthenticator = await isAccountExist({
|
|
2699
|
+
authKey: SingleSenderTransactionAuthenticatorAuthKey,
|
|
2700
|
+
aptosConfig
|
|
2701
|
+
});
|
|
2702
|
+
if (isSingleSenderTransactionAuthenticator) {
|
|
2703
|
+
const address = new AccountAddress({ data: SingleSenderTransactionAuthenticatorAuthKey.toUint8Array() });
|
|
2704
|
+
return Account.fromPrivateKey({ privateKey, address });
|
|
2705
|
+
}
|
|
2706
|
+
const legacyAuthKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: 0 /* Ed25519 */ });
|
|
2707
|
+
const isLegacyEd25519 = await isAccountExist({ authKey: legacyAuthKey, aptosConfig });
|
|
2708
|
+
if (isLegacyEd25519) {
|
|
2709
|
+
const address = new AccountAddress({ data: legacyAuthKey.toUint8Array() });
|
|
2710
|
+
return Account.fromPrivateKey({ privateKey, address, legacy: true });
|
|
2711
|
+
}
|
|
2712
|
+
}
|
|
2713
|
+
throw new Error(`Can't derive account from private key ${privateKey}`);
|
|
2714
|
+
}
|
|
2715
|
+
async function isAccountExist(args) {
|
|
2716
|
+
const { aptosConfig, authKey } = args;
|
|
2717
|
+
const accountAddress = await lookupOriginalAccountAddress({
|
|
2718
|
+
aptosConfig,
|
|
2719
|
+
authenticationKey: authKey.toString()
|
|
2720
|
+
});
|
|
2721
|
+
try {
|
|
2722
|
+
await getInfo({
|
|
2723
|
+
aptosConfig,
|
|
2724
|
+
accountAddress: accountAddress.toString()
|
|
2725
|
+
});
|
|
2726
|
+
return true;
|
|
2727
|
+
} catch (error) {
|
|
2728
|
+
if (error.status === 404) {
|
|
2729
|
+
return false;
|
|
2730
|
+
}
|
|
2731
|
+
throw new Error(`Error while looking for an account info ${accountAddress.toString()}`);
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2575
2734
|
|
|
2576
2735
|
// src/api/account.ts
|
|
2577
2736
|
var Account2 = class {
|
|
@@ -2647,17 +2806,22 @@ var Account2 = class {
|
|
|
2647
2806
|
...args
|
|
2648
2807
|
});
|
|
2649
2808
|
}
|
|
2809
|
+
async deriveAccountFromPrivateKey(args) {
|
|
2810
|
+
return deriveAccountFromPrivateKey({ aptosConfig: this.config, ...args });
|
|
2811
|
+
}
|
|
2650
2812
|
};
|
|
2651
2813
|
|
|
2652
2814
|
// src/api/aptosConfig.ts
|
|
2815
|
+
var import_aptos_client = __toESM(require("@aptos-labs/aptos-client"));
|
|
2653
2816
|
var AptosConfig = class {
|
|
2654
2817
|
constructor(settings) {
|
|
2655
|
-
var _a, _b;
|
|
2818
|
+
var _a, _b, _c;
|
|
2656
2819
|
this.network = (_a = settings == null ? void 0 : settings.network) != null ? _a : DEFAULT_NETWORK;
|
|
2657
2820
|
this.fullnode = settings == null ? void 0 : settings.fullnode;
|
|
2658
2821
|
this.faucet = settings == null ? void 0 : settings.faucet;
|
|
2659
2822
|
this.indexer = settings == null ? void 0 : settings.indexer;
|
|
2660
|
-
this.
|
|
2823
|
+
this.client = (_b = settings == null ? void 0 : settings.client) != null ? _b : { provider: import_aptos_client.default };
|
|
2824
|
+
this.clientConfig = (_c = settings == null ? void 0 : settings.clientConfig) != null ? _c : {};
|
|
2661
2825
|
}
|
|
2662
2826
|
getRequestUrl(apiType) {
|
|
2663
2827
|
switch (apiType) {
|
|
@@ -3067,6 +3231,42 @@ function nextToken(tagStr, pos) {
|
|
|
3067
3231
|
// src/transactions/transaction_builder/transaction_builder.ts
|
|
3068
3232
|
var import_sha33 = require("@noble/hashes/sha3");
|
|
3069
3233
|
|
|
3234
|
+
// src/core/crypto/anySignature.ts
|
|
3235
|
+
var AnySignature = class extends Signature {
|
|
3236
|
+
constructor(signature) {
|
|
3237
|
+
super();
|
|
3238
|
+
this.signature = signature;
|
|
3239
|
+
}
|
|
3240
|
+
toUint8Array() {
|
|
3241
|
+
return this.signature.toUint8Array();
|
|
3242
|
+
}
|
|
3243
|
+
toString() {
|
|
3244
|
+
return this.signature.toString();
|
|
3245
|
+
}
|
|
3246
|
+
serialize(serializer) {
|
|
3247
|
+
if (this.signature instanceof Ed25519Signature) {
|
|
3248
|
+
serializer.serializeU32AsUleb128(0 /* Ed25519 */);
|
|
3249
|
+
this.signature.serialize(serializer);
|
|
3250
|
+
} else if (this.signature instanceof Secp256k1Signature) {
|
|
3251
|
+
serializer.serializeU32AsUleb128(1 /* Secp256k1 */);
|
|
3252
|
+
this.signature.serialize(serializer);
|
|
3253
|
+
} else {
|
|
3254
|
+
throw new Error("Unknown signature type");
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
static deserialize(deserializer) {
|
|
3258
|
+
const index = deserializer.deserializeUleb128AsU32();
|
|
3259
|
+
switch (index) {
|
|
3260
|
+
case 0 /* Ed25519 */:
|
|
3261
|
+
return new AnySignature(Ed25519Signature.load(deserializer));
|
|
3262
|
+
case 1 /* Secp256k1 */:
|
|
3263
|
+
return new AnySignature(Secp256k1Signature.load(deserializer));
|
|
3264
|
+
default:
|
|
3265
|
+
throw new Error(`Unknown variant index for AnySignature: ${index}`);
|
|
3266
|
+
}
|
|
3267
|
+
}
|
|
3268
|
+
};
|
|
3269
|
+
|
|
3070
3270
|
// src/utils/helpers.ts
|
|
3071
3271
|
async function sleep(timeMs) {
|
|
3072
3272
|
return new Promise((resolve) => {
|
|
@@ -3241,8 +3441,8 @@ var AccountAuthenticator = class extends Serializable {
|
|
|
3241
3441
|
return AccountAuthenticatorEd25519.load(deserializer);
|
|
3242
3442
|
case 1 /* MultiEd25519 */:
|
|
3243
3443
|
return AccountAuthenticatorMultiEd25519.load(deserializer);
|
|
3244
|
-
case 2 /*
|
|
3245
|
-
return
|
|
3444
|
+
case 2 /* SingleKey */:
|
|
3445
|
+
return AccountAuthenticatorSingleKey.load(deserializer);
|
|
3246
3446
|
default:
|
|
3247
3447
|
throw new Error(`Unknown variant index for AccountAuthenticator: ${index}`);
|
|
3248
3448
|
}
|
|
@@ -3282,26 +3482,26 @@ var AccountAuthenticatorMultiEd25519 = class extends AccountAuthenticator {
|
|
|
3282
3482
|
return new AccountAuthenticatorMultiEd25519(public_key, signature);
|
|
3283
3483
|
}
|
|
3284
3484
|
};
|
|
3285
|
-
var
|
|
3485
|
+
var AccountAuthenticatorSingleKey = class extends AccountAuthenticator {
|
|
3286
3486
|
constructor(public_key, signature) {
|
|
3287
3487
|
super();
|
|
3288
3488
|
this.public_key = public_key;
|
|
3289
3489
|
this.signature = signature;
|
|
3290
3490
|
}
|
|
3291
3491
|
serialize(serializer) {
|
|
3292
|
-
serializer.serializeU32AsUleb128(2 /*
|
|
3492
|
+
serializer.serializeU32AsUleb128(2 /* SingleKey */);
|
|
3293
3493
|
this.public_key.serialize(serializer);
|
|
3294
3494
|
this.signature.serialize(serializer);
|
|
3295
3495
|
}
|
|
3296
3496
|
static load(deserializer) {
|
|
3297
|
-
const public_key =
|
|
3298
|
-
const signature =
|
|
3299
|
-
return new
|
|
3497
|
+
const public_key = AnyPublicKey.deserialize(deserializer);
|
|
3498
|
+
const signature = AnySignature.deserialize(deserializer);
|
|
3499
|
+
return new AccountAuthenticatorSingleKey(public_key, signature);
|
|
3300
3500
|
}
|
|
3301
3501
|
};
|
|
3302
3502
|
|
|
3303
3503
|
// src/transactions/authenticator/transaction.ts
|
|
3304
|
-
var TransactionAuthenticator = class {
|
|
3504
|
+
var TransactionAuthenticator = class extends Serializable {
|
|
3305
3505
|
static deserialize(deserializer) {
|
|
3306
3506
|
const index = deserializer.deserializeUleb128AsU32();
|
|
3307
3507
|
switch (index) {
|
|
@@ -3313,8 +3513,8 @@ var TransactionAuthenticator = class {
|
|
|
3313
3513
|
return TransactionAuthenticatorMultiAgent.load(deserializer);
|
|
3314
3514
|
case 3 /* FeePayer */:
|
|
3315
3515
|
return TransactionAuthenticatorFeePayer.load(deserializer);
|
|
3316
|
-
case 4 /*
|
|
3317
|
-
return
|
|
3516
|
+
case 4 /* SingleSenderTransactionAuthenticator */:
|
|
3517
|
+
return SingleSenderTransactionAuthenticator.load(deserializer);
|
|
3318
3518
|
default:
|
|
3319
3519
|
throw new Error(`Unknown variant index for TransactionAuthenticator: ${index}`);
|
|
3320
3520
|
}
|
|
@@ -3400,21 +3600,18 @@ var TransactionAuthenticatorFeePayer = class extends TransactionAuthenticator {
|
|
|
3400
3600
|
return new TransactionAuthenticatorFeePayer(sender, secondary_signer_addresses, secondary_signers, fee_payer);
|
|
3401
3601
|
}
|
|
3402
3602
|
};
|
|
3403
|
-
var
|
|
3404
|
-
constructor(
|
|
3603
|
+
var SingleSenderTransactionAuthenticator = class extends TransactionAuthenticator {
|
|
3604
|
+
constructor(sender) {
|
|
3405
3605
|
super();
|
|
3406
|
-
this.
|
|
3407
|
-
this.signature = signature;
|
|
3606
|
+
this.sender = sender;
|
|
3408
3607
|
}
|
|
3409
3608
|
serialize(serializer) {
|
|
3410
|
-
serializer.serializeU32AsUleb128(4 /*
|
|
3411
|
-
this.
|
|
3412
|
-
this.signature.serialize(serializer);
|
|
3609
|
+
serializer.serializeU32AsUleb128(4 /* SingleSenderTransactionAuthenticator */);
|
|
3610
|
+
this.sender.serialize(serializer);
|
|
3413
3611
|
}
|
|
3414
3612
|
static load(deserializer) {
|
|
3415
|
-
const
|
|
3416
|
-
|
|
3417
|
-
return new TransactionAuthenticatorSecp256k1(public_key, signature);
|
|
3613
|
+
const sender = AccountAuthenticator.deserialize(deserializer);
|
|
3614
|
+
return new SingleSenderTransactionAuthenticator(sender);
|
|
3418
3615
|
}
|
|
3419
3616
|
};
|
|
3420
3617
|
|
|
@@ -3752,7 +3949,7 @@ function generateTransactionPayload(args) {
|
|
|
3752
3949
|
var _a, _b, _c;
|
|
3753
3950
|
if ("bytecode" in args) {
|
|
3754
3951
|
return new TransactionPayloadScript(
|
|
3755
|
-
new Script(Hex.fromHexInput(args.bytecode).toUint8Array(), (_a = args.typeArguments) != null ? _a : [], args.
|
|
3952
|
+
new Script(Hex.fromHexInput(args.bytecode).toUint8Array(), (_a = args.typeArguments) != null ? _a : [], args.functionArguments)
|
|
3756
3953
|
);
|
|
3757
3954
|
}
|
|
3758
3955
|
if ("multisigAddress" in args) {
|
|
@@ -3765,7 +3962,7 @@ function generateTransactionPayload(args) {
|
|
|
3765
3962
|
`${funcNameParts2[0]}::${funcNameParts2[1]}`,
|
|
3766
3963
|
funcNameParts2[2],
|
|
3767
3964
|
(_b = args.typeArguments) != null ? _b : [],
|
|
3768
|
-
args.
|
|
3965
|
+
args.functionArguments
|
|
3769
3966
|
)
|
|
3770
3967
|
)
|
|
3771
3968
|
)
|
|
@@ -3777,7 +3974,7 @@ function generateTransactionPayload(args) {
|
|
|
3777
3974
|
`${funcNameParts[0]}::${funcNameParts[1]}`,
|
|
3778
3975
|
funcNameParts[2],
|
|
3779
3976
|
(_c = args.typeArguments) != null ? _c : [],
|
|
3780
|
-
args.
|
|
3977
|
+
args.functionArguments
|
|
3781
3978
|
)
|
|
3782
3979
|
);
|
|
3783
3980
|
}
|
|
@@ -3884,26 +4081,25 @@ function generateSignedTransactionForSimulation(args) {
|
|
|
3884
4081
|
accountAuthenticator.public_key,
|
|
3885
4082
|
accountAuthenticator.signature
|
|
3886
4083
|
);
|
|
3887
|
-
} else if (accountAuthenticator instanceof
|
|
3888
|
-
transactionAuthenticator = new
|
|
3889
|
-
accountAuthenticator.public_key,
|
|
3890
|
-
accountAuthenticator.signature
|
|
3891
|
-
);
|
|
4084
|
+
} else if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
|
|
4085
|
+
transactionAuthenticator = new SingleSenderTransactionAuthenticator(accountAuthenticator);
|
|
3892
4086
|
} else {
|
|
3893
4087
|
throw new Error("Invalid public key");
|
|
3894
4088
|
}
|
|
3895
4089
|
return new SignedTransaction(deserializedTransaction, transactionAuthenticator).bcsToBytes();
|
|
3896
4090
|
}
|
|
3897
4091
|
function getAuthenticatorForSimulation(publicKey) {
|
|
3898
|
-
if (publicKey instanceof
|
|
3899
|
-
|
|
3900
|
-
new
|
|
3901
|
-
|
|
3902
|
-
)
|
|
4092
|
+
if (publicKey instanceof AnyPublicKey) {
|
|
4093
|
+
if (publicKey.publicKey instanceof Ed25519PublicKey) {
|
|
4094
|
+
return new AccountAuthenticatorSingleKey(publicKey, new AnySignature(new Ed25519Signature(new Uint8Array(64))));
|
|
4095
|
+
}
|
|
4096
|
+
if (publicKey.publicKey instanceof Secp256k1PublicKey) {
|
|
4097
|
+
return new AccountAuthenticatorSingleKey(publicKey, new AnySignature(new Secp256k1Signature(new Uint8Array(64))));
|
|
4098
|
+
}
|
|
3903
4099
|
}
|
|
3904
|
-
return new
|
|
3905
|
-
new
|
|
3906
|
-
new
|
|
4100
|
+
return new AccountAuthenticatorEd25519(
|
|
4101
|
+
new Ed25519PublicKey(publicKey.toUint8Array()),
|
|
4102
|
+
new Ed25519Signature(new Uint8Array(64))
|
|
3907
4103
|
);
|
|
3908
4104
|
}
|
|
3909
4105
|
function sign(args) {
|
|
@@ -3917,11 +4113,8 @@ function sign(args) {
|
|
|
3917
4113
|
new Ed25519PublicKey(signer.publicKey.toUint8Array()),
|
|
3918
4114
|
new Ed25519Signature(signerSignature.toUint8Array())
|
|
3919
4115
|
);
|
|
3920
|
-
case 2 /*
|
|
3921
|
-
return new
|
|
3922
|
-
new Secp256k1PublicKey(signer.publicKey.toUint8Array()),
|
|
3923
|
-
new Secp256k1Signature(signerSignature.toUint8Array())
|
|
3924
|
-
);
|
|
4116
|
+
case 2 /* SingleKey */:
|
|
4117
|
+
return new AccountAuthenticatorSingleKey(signer.publicKey, new AnySignature(signerSignature));
|
|
3925
4118
|
default:
|
|
3926
4119
|
throw new Error(`Cannot sign transaction, signing scheme ${signer.signingScheme} not supported`);
|
|
3927
4120
|
}
|
|
@@ -3945,11 +4138,8 @@ function generateSignedTransaction(args) {
|
|
|
3945
4138
|
);
|
|
3946
4139
|
return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
|
|
3947
4140
|
}
|
|
3948
|
-
if (accountAuthenticator instanceof
|
|
3949
|
-
const transactionAuthenticator = new
|
|
3950
|
-
accountAuthenticator.public_key,
|
|
3951
|
-
accountAuthenticator.signature
|
|
3952
|
-
);
|
|
4141
|
+
if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
|
|
4142
|
+
const transactionAuthenticator = new SingleSenderTransactionAuthenticator(accountAuthenticator);
|
|
3953
4143
|
return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
|
|
3954
4144
|
}
|
|
3955
4145
|
throw new Error(
|
|
@@ -4079,6 +4269,28 @@ async function submitTransaction(args) {
|
|
|
4079
4269
|
});
|
|
4080
4270
|
return data;
|
|
4081
4271
|
}
|
|
4272
|
+
async function signAndSubmitTransaction(args) {
|
|
4273
|
+
const { aptosConfig, signer, transaction } = args;
|
|
4274
|
+
const authenticator = signTransaction({ signer, transaction });
|
|
4275
|
+
return submitTransaction({
|
|
4276
|
+
aptosConfig,
|
|
4277
|
+
transaction,
|
|
4278
|
+
senderAuthenticator: authenticator
|
|
4279
|
+
});
|
|
4280
|
+
}
|
|
4281
|
+
async function publishModuleTransaction(args) {
|
|
4282
|
+
const { aptosConfig, account, metadataBytes, byteCode, options } = args;
|
|
4283
|
+
const transaction = await generateTransaction({
|
|
4284
|
+
aptosConfig,
|
|
4285
|
+
sender: account,
|
|
4286
|
+
data: {
|
|
4287
|
+
function: "0x1::code::publish_package_txn",
|
|
4288
|
+
functionArguments: [MoveVector.U8(metadataBytes), new MoveVector([MoveVector.U8(byteCode)])]
|
|
4289
|
+
},
|
|
4290
|
+
options
|
|
4291
|
+
});
|
|
4292
|
+
return transaction;
|
|
4293
|
+
}
|
|
4082
4294
|
|
|
4083
4295
|
// src/internal/coin.ts
|
|
4084
4296
|
async function transferCoinTransaction(args) {
|
|
@@ -4090,7 +4302,7 @@ async function transferCoinTransaction(args) {
|
|
|
4090
4302
|
data: {
|
|
4091
4303
|
function: "0x1::aptos_account::transfer_coins",
|
|
4092
4304
|
typeArguments: [new TypeTagStruct(StructTag.fromString(coinStructType))],
|
|
4093
|
-
|
|
4305
|
+
functionArguments: [AccountAddress.fromHexInput(recipient), new U64(amount)]
|
|
4094
4306
|
},
|
|
4095
4307
|
options
|
|
4096
4308
|
});
|
|
@@ -4115,7 +4327,7 @@ async function mintTokenTransaction(args) {
|
|
|
4115
4327
|
sender: creator.accountAddress.toString(),
|
|
4116
4328
|
data: {
|
|
4117
4329
|
function: "0x4::aptos_token::mint",
|
|
4118
|
-
|
|
4330
|
+
functionArguments: [
|
|
4119
4331
|
new MoveString(args.collection),
|
|
4120
4332
|
new MoveString(args.description),
|
|
4121
4333
|
new MoveString(args.name),
|
|
@@ -4217,7 +4429,7 @@ async function createCollectionTransaction(args) {
|
|
|
4217
4429
|
sender: creator.accountAddress.toString(),
|
|
4218
4430
|
data: {
|
|
4219
4431
|
function: "0x4::aptos_token::create_collection",
|
|
4220
|
-
|
|
4432
|
+
functionArguments: [
|
|
4221
4433
|
new MoveString(args.description),
|
|
4222
4434
|
new U64((_a = args.maxSupply) != null ? _a : MAX_U64_BIG_INT),
|
|
4223
4435
|
new MoveString(args.name),
|
|
@@ -4261,9 +4473,6 @@ async function getCollectionData(args) {
|
|
|
4261
4473
|
query: graphqlQuery,
|
|
4262
4474
|
originMethod: "getCollectionData"
|
|
4263
4475
|
});
|
|
4264
|
-
if (data.current_collections_v2.length === 0) {
|
|
4265
|
-
throw Error("Collection not found");
|
|
4266
|
-
}
|
|
4267
4476
|
return data.current_collections_v2[0];
|
|
4268
4477
|
}
|
|
4269
4478
|
async function getCollectionId(args) {
|
|
@@ -4376,7 +4585,11 @@ async function fundAccount(args) {
|
|
|
4376
4585
|
originMethod: "fundAccount"
|
|
4377
4586
|
});
|
|
4378
4587
|
const txnHash = data.txn_hashes[0];
|
|
4379
|
-
await waitForTransaction({
|
|
4588
|
+
await waitForTransaction({
|
|
4589
|
+
aptosConfig,
|
|
4590
|
+
transactionHash: txnHash,
|
|
4591
|
+
options: { timeoutSecs }
|
|
4592
|
+
});
|
|
4380
4593
|
return txnHash;
|
|
4381
4594
|
}
|
|
4382
4595
|
|
|
@@ -4454,6 +4667,17 @@ var FungibleAsset = class {
|
|
|
4454
4667
|
async getFungibleAssetMetadata(args) {
|
|
4455
4668
|
return getFungibleAssetMetadata({ aptosConfig: this.config, ...args });
|
|
4456
4669
|
}
|
|
4670
|
+
async getFungibleAssetMetadataByAssetType(assetType) {
|
|
4671
|
+
const data = await getFungibleAssetMetadata({
|
|
4672
|
+
aptosConfig: this.config,
|
|
4673
|
+
options: {
|
|
4674
|
+
where: {
|
|
4675
|
+
asset_type: { _eq: assetType }
|
|
4676
|
+
}
|
|
4677
|
+
}
|
|
4678
|
+
});
|
|
4679
|
+
return data[0];
|
|
4680
|
+
}
|
|
4457
4681
|
async getFungibleAssetActivities(args) {
|
|
4458
4682
|
return getFungibleAssetActivities({ aptosConfig: this.config, ...args });
|
|
4459
4683
|
}
|
|
@@ -4622,13 +4846,15 @@ var TransactionSubmission = class {
|
|
|
4622
4846
|
}
|
|
4623
4847
|
async signAndSubmitTransaction(args) {
|
|
4624
4848
|
const { signer, transaction } = args;
|
|
4625
|
-
|
|
4626
|
-
return submitTransaction({
|
|
4849
|
+
return signAndSubmitTransaction({
|
|
4627
4850
|
aptosConfig: this.config,
|
|
4628
|
-
|
|
4629
|
-
|
|
4851
|
+
signer,
|
|
4852
|
+
transaction
|
|
4630
4853
|
});
|
|
4631
4854
|
}
|
|
4855
|
+
async publishModuleTransaction(args) {
|
|
4856
|
+
return publishModuleTransaction({ aptosConfig: this.config, ...args });
|
|
4857
|
+
}
|
|
4632
4858
|
};
|
|
4633
4859
|
|
|
4634
4860
|
// src/api/aptos.ts
|
|
@@ -4675,6 +4901,8 @@ applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
|
|
|
4675
4901
|
AccountAddress,
|
|
4676
4902
|
AccountAuthenticatorVariant,
|
|
4677
4903
|
AddressInvalidReason,
|
|
4904
|
+
AnyPublicKeyVariant,
|
|
4905
|
+
AnySignatureVariant,
|
|
4678
4906
|
Aptos,
|
|
4679
4907
|
AptosApiError,
|
|
4680
4908
|
AptosConfig,
|
|
@@ -4716,6 +4944,7 @@ applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
|
|
|
4716
4944
|
Serializer,
|
|
4717
4945
|
Signature,
|
|
4718
4946
|
SigningScheme,
|
|
4947
|
+
SigningSchemeInput,
|
|
4719
4948
|
StructTag,
|
|
4720
4949
|
TransactionAuthenticatorVariant,
|
|
4721
4950
|
TransactionPayloadVariants,
|
|
@@ -4756,6 +4985,7 @@ applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
|
|
|
4756
4985
|
postAptosFaucet,
|
|
4757
4986
|
postAptosFullNode,
|
|
4758
4987
|
postAptosIndexer,
|
|
4988
|
+
request,
|
|
4759
4989
|
stringStructTag,
|
|
4760
4990
|
validateNumberInRange
|
|
4761
4991
|
});
|