@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.
Files changed (43) hide show
  1. package/README.md +12 -2
  2. package/dist/browser/index.global.js +25 -25
  3. package/dist/browser/index.global.js.map +1 -1
  4. package/dist/cjs/index.d.ts +209 -45
  5. package/dist/cjs/index.js +338 -108
  6. package/dist/cjs/index.js.map +1 -1
  7. package/dist/esm/index.d.ts +209 -45
  8. package/dist/esm/index.mjs +334 -108
  9. package/dist/esm/index.mjs.map +1 -1
  10. package/dist/types/index.d.ts +84 -16
  11. package/dist/types/index.js +26 -3
  12. package/dist/types/index.js.map +1 -1
  13. package/package.json +1 -1
  14. package/src/api/account.ts +26 -6
  15. package/src/api/aptosConfig.ts +8 -1
  16. package/src/api/fungibleAsset.ts +25 -0
  17. package/src/api/general.ts +2 -2
  18. package/src/api/transaction.ts +9 -2
  19. package/src/api/transactionSubmission.ts +34 -10
  20. package/src/bcs/serializable/fixedBytes.ts +1 -1
  21. package/src/client/core.ts +15 -17
  22. package/src/client/get.ts +1 -1
  23. package/src/client/post.ts +2 -2
  24. package/src/core/account.ts +74 -33
  25. package/src/core/authenticationKey.ts +29 -13
  26. package/src/core/crypto/anyPublicKey.ts +84 -0
  27. package/src/core/crypto/anySignature.ts +56 -0
  28. package/src/core/crypto/ed25519.ts +10 -0
  29. package/src/core/crypto/secp256k1.ts +11 -1
  30. package/src/internal/account.ts +78 -6
  31. package/src/internal/coin.ts +1 -1
  32. package/src/internal/digitalAsset.ts +2 -6
  33. package/src/internal/faucet.ts +5 -1
  34. package/src/internal/general.ts +1 -1
  35. package/src/internal/transaction.ts +2 -1
  36. package/src/internal/transactionSubmission.ts +47 -6
  37. package/src/transactions/authenticator/account.ts +16 -15
  38. package/src/transactions/authenticator/transaction.ts +15 -22
  39. package/src/transactions/transaction_builder/transaction_builder.ts +27 -28
  40. package/src/transactions/typeTag/parser.ts +285 -0
  41. package/src/transactions/types.ts +2 -2
  42. package/src/types/index.ts +93 -15
  43. package/src/version.ts +1 -1
@@ -10,9 +10,6 @@ var __decorateClass = (decorators, target, key, kind) => {
10
10
  return result;
11
11
  };
12
12
 
13
- // src/client/core.ts
14
- import aptosClient from "@aptos-labs/aptos-client";
15
-
16
13
  // src/client/types.ts
17
14
  var AptosApiError = class extends Error {
18
15
  constructor(request2, response, message) {
@@ -26,6 +23,9 @@ var AptosApiError = class extends Error {
26
23
  }
27
24
  };
28
25
 
26
+ // src/version.ts
27
+ var VERSION = "2.0.0";
28
+
29
29
  // src/types/index.ts
30
30
  var MimeType = /* @__PURE__ */ ((MimeType2) => {
31
31
  MimeType2["JSON"] = "application/json";
@@ -75,15 +75,26 @@ var TransactionAuthenticatorVariant = /* @__PURE__ */ ((TransactionAuthenticator
75
75
  TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
76
76
  TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiAgent"] = 2] = "MultiAgent";
77
77
  TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["FeePayer"] = 3] = "FeePayer";
78
- TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["Secp256k1Ecdsa"] = 4] = "Secp256k1Ecdsa";
78
+ TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["SingleSenderTransactionAuthenticator"] = 4] = "SingleSenderTransactionAuthenticator";
79
79
  return TransactionAuthenticatorVariant2;
80
80
  })(TransactionAuthenticatorVariant || {});
81
81
  var AccountAuthenticatorVariant = /* @__PURE__ */ ((AccountAuthenticatorVariant2) => {
82
82
  AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Ed25519"] = 0] = "Ed25519";
83
83
  AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
84
- AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Secp256k1"] = 2] = "Secp256k1";
84
+ AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["SingleKey"] = 2] = "SingleKey";
85
+ AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiKey"] = 3] = "MultiKey";
85
86
  return AccountAuthenticatorVariant2;
86
87
  })(AccountAuthenticatorVariant || {});
88
+ var AnyPublicKeyVariant = /* @__PURE__ */ ((AnyPublicKeyVariant2) => {
89
+ AnyPublicKeyVariant2[AnyPublicKeyVariant2["Ed25519"] = 0] = "Ed25519";
90
+ AnyPublicKeyVariant2[AnyPublicKeyVariant2["Secp256k1"] = 1] = "Secp256k1";
91
+ return AnyPublicKeyVariant2;
92
+ })(AnyPublicKeyVariant || {});
93
+ var AnySignatureVariant = /* @__PURE__ */ ((AnySignatureVariant2) => {
94
+ AnySignatureVariant2[AnySignatureVariant2["Ed25519"] = 0] = "Ed25519";
95
+ AnySignatureVariant2[AnySignatureVariant2["Secp256k1"] = 1] = "Secp256k1";
96
+ return AnySignatureVariant2;
97
+ })(AnySignatureVariant || {});
87
98
  var TransactionResponseType = /* @__PURE__ */ ((TransactionResponseType2) => {
88
99
  TransactionResponseType2["Pending"] = "pending_transaction";
89
100
  TransactionResponseType2["User"] = "user_transaction";
@@ -113,9 +124,15 @@ var RoleType = /* @__PURE__ */ ((RoleType2) => {
113
124
  var SigningScheme = /* @__PURE__ */ ((SigningScheme2) => {
114
125
  SigningScheme2[SigningScheme2["Ed25519"] = 0] = "Ed25519";
115
126
  SigningScheme2[SigningScheme2["MultiEd25519"] = 1] = "MultiEd25519";
116
- SigningScheme2[SigningScheme2["Secp256k1Ecdsa"] = 2] = "Secp256k1Ecdsa";
127
+ SigningScheme2[SigningScheme2["SingleKey"] = 2] = "SingleKey";
117
128
  return SigningScheme2;
118
129
  })(SigningScheme || {});
130
+ var SigningSchemeInput = /* @__PURE__ */ ((SigningSchemeInput2) => {
131
+ SigningSchemeInput2[SigningSchemeInput2["Ed25519"] = 0] = "Ed25519";
132
+ SigningSchemeInput2[SigningSchemeInput2["MultiEd25519"] = 1] = "MultiEd25519";
133
+ SigningSchemeInput2[SigningSchemeInput2["Secp256k1Ecdsa"] = 2] = "Secp256k1Ecdsa";
134
+ return SigningSchemeInput2;
135
+ })(SigningSchemeInput || {});
119
136
  var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
120
137
  DeriveScheme2[DeriveScheme2["DeriveAuid"] = 251] = "DeriveAuid";
121
138
  DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromObject"] = 252] = "DeriveObjectAddressFromObject";
@@ -125,9 +142,6 @@ var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
125
142
  return DeriveScheme2;
126
143
  })(DeriveScheme || {});
127
144
 
128
- // src/version.ts
129
- var VERSION = "0.0.0";
130
-
131
145
  // src/client/core.ts
132
146
  var errors = {
133
147
  400: "Bad Request",
@@ -139,7 +153,8 @@ var errors = {
139
153
  502: "Bad Gateway",
140
154
  503: "Service Unavailable"
141
155
  };
142
- async function request(url, method, body, contentType, params, overrides) {
156
+ async function request(options, client) {
157
+ const { url, method, body, contentType, params, overrides } = options;
143
158
  const headers = {
144
159
  ...overrides == null ? void 0 : overrides.HEADERS,
145
160
  "x-aptos-client": `aptos-ts-sdk/${VERSION}`,
@@ -148,7 +163,7 @@ async function request(url, method, body, contentType, params, overrides) {
148
163
  if (overrides == null ? void 0 : overrides.TOKEN) {
149
164
  headers.Authorization = `Bearer ${overrides == null ? void 0 : overrides.TOKEN}`;
150
165
  }
151
- return aptosClient({
166
+ return client.provider({
152
167
  url,
153
168
  method,
154
169
  body,
@@ -159,26 +174,28 @@ async function request(url, method, body, contentType, params, overrides) {
159
174
  }
160
175
  async function aptosRequest(options, aptosConfig) {
161
176
  var _a;
162
- const { url, path, method, body, contentType, params, overrides } = options;
177
+ const { url, path } = options;
163
178
  const fullUrl = `${url}/${path != null ? path : ""}`;
164
- const response = await request(fullUrl, method, body, contentType, params, overrides);
179
+ const response = await request({ ...options, url: fullUrl }, aptosConfig.client);
165
180
  const result = {
166
181
  status: response.status,
167
182
  statusText: response.statusText,
168
183
  data: response.data,
169
184
  headers: response.headers,
170
185
  config: response.config,
186
+ request: response.request,
171
187
  url: fullUrl
172
188
  };
173
189
  if (aptosConfig.isIndexerRequest(url)) {
174
- if (result.data.errors) {
190
+ const indexerResponse = result.data;
191
+ if (indexerResponse.errors) {
175
192
  throw new AptosApiError(
176
193
  options,
177
194
  result,
178
- (_a = response.data.errors[0].message) != null ? _a : `Unhandled Error ${response.status} : ${response.statusText}`
195
+ (_a = indexerResponse.errors[0].message) != null ? _a : `Unhandled Error ${response.status} : ${response.statusText}`
179
196
  );
180
197
  }
181
- result.data = result.data.data;
198
+ result.data = indexerResponse.data;
182
199
  }
183
200
  if (result.status >= 200 && result.status < 300) {
184
201
  return result;
@@ -246,7 +263,7 @@ async function get(options) {
246
263
  acceptType: acceptType == null ? void 0 : acceptType.valueOf(),
247
264
  params,
248
265
  overrides: {
249
- ...aptosConfig,
266
+ ...aptosConfig.clientConfig,
250
267
  ...overrides
251
268
  }
252
269
  },
@@ -294,7 +311,7 @@ async function post(options) {
294
311
  acceptType: acceptType == null ? void 0 : acceptType.valueOf(),
295
312
  params,
296
313
  overrides: {
297
- ...aptosConfig,
314
+ ...aptosConfig.clientConfig,
298
315
  ...overrides
299
316
  }
300
317
  },
@@ -1182,6 +1199,10 @@ var _Ed25519PublicKey = class extends PublicKey {
1182
1199
  const bytes = deserializer.deserializeBytes();
1183
1200
  return new _Ed25519PublicKey(bytes);
1184
1201
  }
1202
+ static load(deserializer) {
1203
+ const bytes = deserializer.deserializeBytes();
1204
+ return new _Ed25519PublicKey(bytes);
1205
+ }
1185
1206
  };
1186
1207
  var Ed25519PublicKey = _Ed25519PublicKey;
1187
1208
  Ed25519PublicKey.LENGTH = 32;
@@ -1245,6 +1266,10 @@ var _Ed25519Signature = class extends Signature {
1245
1266
  const bytes = deserializer.deserializeBytes();
1246
1267
  return new _Ed25519Signature(bytes);
1247
1268
  }
1269
+ static load(deserializer) {
1270
+ const bytes = deserializer.deserializeBytes();
1271
+ return new _Ed25519Signature(bytes);
1272
+ }
1248
1273
  };
1249
1274
  var Ed25519Signature = _Ed25519Signature;
1250
1275
  Ed25519Signature.LENGTH = 64;
@@ -1395,6 +1420,10 @@ var _Secp256k1PublicKey = class extends PublicKey {
1395
1420
  const bytes = deserializer.deserializeBytes();
1396
1421
  return new _Secp256k1PublicKey(bytes);
1397
1422
  }
1423
+ static load(deserializer) {
1424
+ const bytes = deserializer.deserializeBytes();
1425
+ return new _Secp256k1PublicKey(bytes);
1426
+ }
1398
1427
  };
1399
1428
  var Secp256k1PublicKey = _Secp256k1PublicKey;
1400
1429
  Secp256k1PublicKey.LENGTH = 65;
@@ -1442,7 +1471,7 @@ var _Secp256k1Signature = class extends Signature {
1442
1471
  super();
1443
1472
  const hex = Hex.fromHexInput(hexInput);
1444
1473
  if (hex.toUint8Array().length !== _Secp256k1Signature.LENGTH) {
1445
- throw new Error(`Signature length should be ${_Secp256k1Signature.LENGTH}`);
1474
+ throw new Error(`Signature length should be ${_Secp256k1Signature.LENGTH}, recieved ${hex.toUint8Array().length}`);
1446
1475
  }
1447
1476
  this.data = hex;
1448
1477
  }
@@ -1459,10 +1488,66 @@ var _Secp256k1Signature = class extends Signature {
1459
1488
  const hex = deserializer.deserializeBytes();
1460
1489
  return new _Secp256k1Signature(hex);
1461
1490
  }
1491
+ static load(deserializer) {
1492
+ const bytes = deserializer.deserializeBytes();
1493
+ return new _Secp256k1Signature(bytes);
1494
+ }
1462
1495
  };
1463
1496
  var Secp256k1Signature = _Secp256k1Signature;
1464
1497
  Secp256k1Signature.LENGTH = 64;
1465
1498
 
1499
+ // src/core/crypto/anyPublicKey.ts
1500
+ var AnyPublicKey = class extends PublicKey {
1501
+ constructor(publicKey) {
1502
+ super();
1503
+ this.publicKey = publicKey;
1504
+ }
1505
+ toUint8Array() {
1506
+ return this.publicKey.toUint8Array();
1507
+ }
1508
+ toString() {
1509
+ return this.publicKey.toString();
1510
+ }
1511
+ verifySignature(args) {
1512
+ const { message, signature } = args;
1513
+ if (this.isED25519Signature(signature)) {
1514
+ return this.publicKey.verifySignature({ message, signature: signature.signature });
1515
+ } else if (this.isSecp256k1Signature(signature)) {
1516
+ return this.publicKey.verifySignature({ message, signature: signature.signature });
1517
+ } else {
1518
+ throw new Error("Unknown public key type");
1519
+ }
1520
+ }
1521
+ isED25519Signature(signature) {
1522
+ return this.publicKey instanceof Ed25519PublicKey && signature.signature instanceof Ed25519Signature;
1523
+ }
1524
+ isSecp256k1Signature(signature) {
1525
+ return this.publicKey instanceof Secp256k1PublicKey && signature.signature instanceof Secp256k1Signature;
1526
+ }
1527
+ serialize(serializer) {
1528
+ if (this.publicKey instanceof Ed25519PublicKey) {
1529
+ serializer.serializeU32AsUleb128(0 /* Ed25519 */);
1530
+ this.publicKey.serialize(serializer);
1531
+ } else if (this.publicKey instanceof Secp256k1PublicKey) {
1532
+ serializer.serializeU32AsUleb128(1 /* Secp256k1 */);
1533
+ this.publicKey.serialize(serializer);
1534
+ } else {
1535
+ throw new Error("Unknown public key type");
1536
+ }
1537
+ }
1538
+ static deserialize(deserializer) {
1539
+ const index = deserializer.deserializeUleb128AsU32();
1540
+ switch (index) {
1541
+ case 0 /* Ed25519 */:
1542
+ return new AnyPublicKey(Ed25519PublicKey.load(deserializer));
1543
+ case 1 /* Secp256k1 */:
1544
+ return new AnyPublicKey(Secp256k1PublicKey.load(deserializer));
1545
+ default:
1546
+ throw new Error(`Unknown variant index for AnyPublicKey: ${index}`);
1547
+ }
1548
+ }
1549
+ };
1550
+
1466
1551
  // src/core/authenticationKey.ts
1467
1552
  var _AuthenticationKey = class {
1468
1553
  constructor(args) {
@@ -1479,15 +1564,29 @@ var _AuthenticationKey = class {
1479
1564
  toUint8Array() {
1480
1565
  return this.data.toUint8Array();
1481
1566
  }
1482
- static fromBytesAndScheme(args) {
1483
- const { bytes, scheme } = args;
1484
- const inputBytes = Hex.fromHexInput(bytes).toUint8Array();
1485
- const authKeyBytes = new Uint8Array(inputBytes.length + 1);
1486
- authKeyBytes.set(inputBytes);
1487
- authKeyBytes.set([scheme], inputBytes.length);
1567
+ static fromPublicKeyAndScheme(args) {
1568
+ const { publicKey, scheme } = args;
1569
+ let authKeyBytes;
1570
+ switch (scheme) {
1571
+ case 2 /* SingleKey */: {
1572
+ const singleKeyBytes = publicKey.bcsToBytes();
1573
+ authKeyBytes = new Uint8Array([...singleKeyBytes, scheme]);
1574
+ break;
1575
+ }
1576
+ case 0 /* Ed25519 */:
1577
+ case 1 /* MultiEd25519 */: {
1578
+ const ed25519PublicKeyBytes = publicKey.toUint8Array();
1579
+ const inputBytes = Hex.fromHexInput(ed25519PublicKeyBytes).toUint8Array();
1580
+ authKeyBytes = new Uint8Array([...inputBytes, scheme]);
1581
+ break;
1582
+ }
1583
+ default:
1584
+ throw new Error(`Scheme ${scheme} is not supported`);
1585
+ }
1488
1586
  const hash = sha3Hash.create();
1489
1587
  hash.update(authKeyBytes);
1490
- return new _AuthenticationKey({ data: hash.digest() });
1588
+ const hashDigest = hash.digest();
1589
+ return new _AuthenticationKey({ data: hashDigest });
1491
1590
  }
1492
1591
  static fromPublicKey(args) {
1493
1592
  const { publicKey } = args;
@@ -1496,13 +1595,12 @@ var _AuthenticationKey = class {
1496
1595
  scheme = 0 /* Ed25519 */.valueOf();
1497
1596
  } else if (publicKey instanceof MultiEd25519PublicKey) {
1498
1597
  scheme = 1 /* MultiEd25519 */.valueOf();
1499
- } else if (publicKey instanceof Secp256k1PublicKey) {
1500
- scheme = 2 /* Secp256k1Ecdsa */.valueOf();
1598
+ } else if (publicKey instanceof AnyPublicKey) {
1599
+ scheme = 2 /* SingleKey */.valueOf();
1501
1600
  } else {
1502
1601
  throw new Error("No supported authentication scheme for public key");
1503
1602
  }
1504
- const pubKeyBytes = publicKey.toUint8Array();
1505
- return _AuthenticationKey.fromBytesAndScheme({ bytes: pubKeyBytes, scheme });
1603
+ return _AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme });
1506
1604
  }
1507
1605
  derivedAddress() {
1508
1606
  return new AccountAddress({ data: this.data.toUint8Array() });
@@ -1560,50 +1658,58 @@ var derivePrivateKeyFromMnemonic = (keyType, path, seedPhrase, offset = HARDENED
1560
1658
  // src/core/account.ts
1561
1659
  var Account = class {
1562
1660
  constructor(args) {
1563
- const { privateKey, address } = args;
1661
+ const { privateKey, address, legacy } = args;
1564
1662
  this.publicKey = privateKey.publicKey();
1565
1663
  if (this.publicKey instanceof Ed25519PublicKey) {
1566
- this.signingScheme = 0 /* Ed25519 */;
1664
+ if (legacy) {
1665
+ this.signingScheme = 0 /* Ed25519 */;
1666
+ } else {
1667
+ this.publicKey = new AnyPublicKey(this.publicKey);
1668
+ this.signingScheme = 2 /* SingleKey */;
1669
+ }
1567
1670
  } else if (this.publicKey instanceof MultiEd25519PublicKey) {
1568
1671
  this.signingScheme = 1 /* MultiEd25519 */;
1569
1672
  } else if (this.publicKey instanceof Secp256k1PublicKey) {
1570
- this.signingScheme = 2 /* Secp256k1Ecdsa */;
1673
+ this.publicKey = new AnyPublicKey(this.publicKey);
1674
+ this.signingScheme = 2 /* SingleKey */;
1571
1675
  } else {
1572
1676
  throw new Error("Can not create new Account, unsupported public key type");
1573
1677
  }
1574
1678
  this.privateKey = privateKey;
1575
1679
  this.accountAddress = address;
1576
1680
  }
1577
- static generate(scheme) {
1681
+ static generate(args) {
1578
1682
  let privateKey;
1579
- switch (scheme) {
1683
+ switch (args == null ? void 0 : args.scheme) {
1580
1684
  case 2 /* Secp256k1Ecdsa */:
1581
1685
  privateKey = Secp256k1PrivateKey.generate();
1582
1686
  break;
1583
1687
  default:
1584
1688
  privateKey = Ed25519PrivateKey.generate();
1585
1689
  }
1690
+ let publicKey = privateKey.publicKey();
1691
+ if (!(args == null ? void 0 : args.legacy)) {
1692
+ publicKey = new AnyPublicKey(privateKey.publicKey());
1693
+ }
1586
1694
  const address = new AccountAddress({
1587
1695
  data: Account.authKey({
1588
- publicKey: privateKey.publicKey()
1696
+ publicKey
1589
1697
  }).toUint8Array()
1590
1698
  });
1591
- return new Account({ privateKey, address });
1592
- }
1593
- static fromPrivateKey(privateKey) {
1594
- const publicKey = privateKey.publicKey();
1595
- const authKey = Account.authKey({ publicKey });
1596
- const address = new AccountAddress({ data: authKey.toUint8Array() });
1597
- return Account.fromPrivateKeyAndAddress({ privateKey, address });
1699
+ return new Account({ privateKey, address, legacy: args == null ? void 0 : args.legacy });
1598
1700
  }
1599
- static fromPrivateKeyAndAddress(args) {
1600
- return new Account(args);
1701
+ static fromPrivateKey(args) {
1702
+ const { privateKey, address, legacy } = args;
1703
+ return new Account({ privateKey, address, legacy });
1601
1704
  }
1602
1705
  static fromDerivationPath(args) {
1603
1706
  const { path, mnemonic } = args;
1604
1707
  const { key } = derivePrivateKeyFromMnemonic("ed25519 seed" /* ED25519 */, path, mnemonic);
1605
1708
  const privateKey = new Ed25519PrivateKey(key);
1606
- return Account.fromPrivateKey(privateKey);
1709
+ const publicKey = privateKey.publicKey();
1710
+ const authKey = Account.authKey({ publicKey });
1711
+ const address = new AccountAddress({ data: authKey.toUint8Array() });
1712
+ return new Account({ privateKey, address, legacy: true });
1607
1713
  }
1608
1714
  static authKey(args) {
1609
1715
  const { publicKey } = args;
@@ -2100,7 +2206,7 @@ async function view(args) {
2100
2206
  body: {
2101
2207
  function: payload.function,
2102
2208
  type_arguments: (_a = payload.typeArguments) != null ? _a : [],
2103
- arguments: (_b = payload.arguments) != null ? _b : []
2209
+ arguments: (_b = payload.functionArguments) != null ? _b : []
2104
2210
  }
2105
2211
  });
2106
2212
  return data;
@@ -2238,7 +2344,7 @@ async function getResource(args) {
2238
2344
  path: `accounts/${AccountAddress.fromHexInput(accountAddress).toString()}/resource/${resourceType}`,
2239
2345
  params: { ledger_version: options == null ? void 0 : options.ledgerVersion }
2240
2346
  });
2241
- return data;
2347
+ return data.data;
2242
2348
  }
2243
2349
  async function lookupOriginalAccountAddress(args) {
2244
2350
  const { aptosConfig, authenticationKey, options } = args;
@@ -2250,7 +2356,7 @@ async function lookupOriginalAccountAddress(args) {
2250
2356
  });
2251
2357
  const {
2252
2358
  address_map: { handle }
2253
- } = resource.data;
2359
+ } = resource;
2254
2360
  try {
2255
2361
  const originalAddress = await getTableItem({
2256
2362
  aptosConfig,
@@ -2456,6 +2562,55 @@ async function getAccountOwnedObjects(args) {
2456
2562
  });
2457
2563
  return data.current_objects;
2458
2564
  }
2565
+ async function deriveAccountFromPrivateKey(args) {
2566
+ const { aptosConfig, privateKey } = args;
2567
+ const publicKey = new AnyPublicKey(privateKey.publicKey());
2568
+ if (privateKey instanceof Secp256k1PrivateKey) {
2569
+ const authKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: 2 /* SingleKey */ });
2570
+ const address = new AccountAddress({ data: authKey.toUint8Array() });
2571
+ return Account.fromPrivateKey({ privateKey, address });
2572
+ }
2573
+ if (privateKey instanceof Ed25519PrivateKey) {
2574
+ const SingleSenderTransactionAuthenticatorAuthKey = AuthenticationKey.fromPublicKeyAndScheme({
2575
+ publicKey,
2576
+ scheme: 2 /* SingleKey */
2577
+ });
2578
+ const isSingleSenderTransactionAuthenticator = await isAccountExist({
2579
+ authKey: SingleSenderTransactionAuthenticatorAuthKey,
2580
+ aptosConfig
2581
+ });
2582
+ if (isSingleSenderTransactionAuthenticator) {
2583
+ const address = new AccountAddress({ data: SingleSenderTransactionAuthenticatorAuthKey.toUint8Array() });
2584
+ return Account.fromPrivateKey({ privateKey, address });
2585
+ }
2586
+ const legacyAuthKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: 0 /* Ed25519 */ });
2587
+ const isLegacyEd25519 = await isAccountExist({ authKey: legacyAuthKey, aptosConfig });
2588
+ if (isLegacyEd25519) {
2589
+ const address = new AccountAddress({ data: legacyAuthKey.toUint8Array() });
2590
+ return Account.fromPrivateKey({ privateKey, address, legacy: true });
2591
+ }
2592
+ }
2593
+ throw new Error(`Can't derive account from private key ${privateKey}`);
2594
+ }
2595
+ async function isAccountExist(args) {
2596
+ const { aptosConfig, authKey } = args;
2597
+ const accountAddress = await lookupOriginalAccountAddress({
2598
+ aptosConfig,
2599
+ authenticationKey: authKey.toString()
2600
+ });
2601
+ try {
2602
+ await getInfo({
2603
+ aptosConfig,
2604
+ accountAddress: accountAddress.toString()
2605
+ });
2606
+ return true;
2607
+ } catch (error) {
2608
+ if (error.status === 404) {
2609
+ return false;
2610
+ }
2611
+ throw new Error(`Error while looking for an account info ${accountAddress.toString()}`);
2612
+ }
2613
+ }
2459
2614
 
2460
2615
  // src/api/account.ts
2461
2616
  var Account2 = class {
@@ -2531,17 +2686,22 @@ var Account2 = class {
2531
2686
  ...args
2532
2687
  });
2533
2688
  }
2689
+ async deriveAccountFromPrivateKey(args) {
2690
+ return deriveAccountFromPrivateKey({ aptosConfig: this.config, ...args });
2691
+ }
2534
2692
  };
2535
2693
 
2536
2694
  // src/api/aptosConfig.ts
2695
+ import aptosClient from "@aptos-labs/aptos-client";
2537
2696
  var AptosConfig = class {
2538
2697
  constructor(settings) {
2539
- var _a, _b;
2698
+ var _a, _b, _c;
2540
2699
  this.network = (_a = settings == null ? void 0 : settings.network) != null ? _a : DEFAULT_NETWORK;
2541
2700
  this.fullnode = settings == null ? void 0 : settings.fullnode;
2542
2701
  this.faucet = settings == null ? void 0 : settings.faucet;
2543
2702
  this.indexer = settings == null ? void 0 : settings.indexer;
2544
- this.clientConfig = (_b = settings == null ? void 0 : settings.clientConfig) != null ? _b : {};
2703
+ this.client = (_b = settings == null ? void 0 : settings.client) != null ? _b : { provider: aptosClient };
2704
+ this.clientConfig = (_c = settings == null ? void 0 : settings.clientConfig) != null ? _c : {};
2545
2705
  }
2546
2706
  getRequestUrl(apiType) {
2547
2707
  switch (apiType) {
@@ -2951,6 +3111,42 @@ function nextToken(tagStr, pos) {
2951
3111
  // src/transactions/transaction_builder/transaction_builder.ts
2952
3112
  import { sha3_256 as sha3Hash2 } from "@noble/hashes/sha3";
2953
3113
 
3114
+ // src/core/crypto/anySignature.ts
3115
+ var AnySignature = class extends Signature {
3116
+ constructor(signature) {
3117
+ super();
3118
+ this.signature = signature;
3119
+ }
3120
+ toUint8Array() {
3121
+ return this.signature.toUint8Array();
3122
+ }
3123
+ toString() {
3124
+ return this.signature.toString();
3125
+ }
3126
+ serialize(serializer) {
3127
+ if (this.signature instanceof Ed25519Signature) {
3128
+ serializer.serializeU32AsUleb128(0 /* Ed25519 */);
3129
+ this.signature.serialize(serializer);
3130
+ } else if (this.signature instanceof Secp256k1Signature) {
3131
+ serializer.serializeU32AsUleb128(1 /* Secp256k1 */);
3132
+ this.signature.serialize(serializer);
3133
+ } else {
3134
+ throw new Error("Unknown signature type");
3135
+ }
3136
+ }
3137
+ static deserialize(deserializer) {
3138
+ const index = deserializer.deserializeUleb128AsU32();
3139
+ switch (index) {
3140
+ case 0 /* Ed25519 */:
3141
+ return new AnySignature(Ed25519Signature.load(deserializer));
3142
+ case 1 /* Secp256k1 */:
3143
+ return new AnySignature(Secp256k1Signature.load(deserializer));
3144
+ default:
3145
+ throw new Error(`Unknown variant index for AnySignature: ${index}`);
3146
+ }
3147
+ }
3148
+ };
3149
+
2954
3150
  // src/utils/helpers.ts
2955
3151
  async function sleep(timeMs) {
2956
3152
  return new Promise((resolve) => {
@@ -3125,8 +3321,8 @@ var AccountAuthenticator = class extends Serializable {
3125
3321
  return AccountAuthenticatorEd25519.load(deserializer);
3126
3322
  case 1 /* MultiEd25519 */:
3127
3323
  return AccountAuthenticatorMultiEd25519.load(deserializer);
3128
- case 2 /* Secp256k1 */:
3129
- return AccountAuthenticatorSecp256k1.load(deserializer);
3324
+ case 2 /* SingleKey */:
3325
+ return AccountAuthenticatorSingleKey.load(deserializer);
3130
3326
  default:
3131
3327
  throw new Error(`Unknown variant index for AccountAuthenticator: ${index}`);
3132
3328
  }
@@ -3166,26 +3362,26 @@ var AccountAuthenticatorMultiEd25519 = class extends AccountAuthenticator {
3166
3362
  return new AccountAuthenticatorMultiEd25519(public_key, signature);
3167
3363
  }
3168
3364
  };
3169
- var AccountAuthenticatorSecp256k1 = class extends AccountAuthenticator {
3365
+ var AccountAuthenticatorSingleKey = class extends AccountAuthenticator {
3170
3366
  constructor(public_key, signature) {
3171
3367
  super();
3172
3368
  this.public_key = public_key;
3173
3369
  this.signature = signature;
3174
3370
  }
3175
3371
  serialize(serializer) {
3176
- serializer.serializeU32AsUleb128(2 /* Secp256k1 */);
3372
+ serializer.serializeU32AsUleb128(2 /* SingleKey */);
3177
3373
  this.public_key.serialize(serializer);
3178
3374
  this.signature.serialize(serializer);
3179
3375
  }
3180
3376
  static load(deserializer) {
3181
- const public_key = Secp256k1PublicKey.deserialize(deserializer);
3182
- const signature = Secp256k1Signature.deserialize(deserializer);
3183
- return new AccountAuthenticatorSecp256k1(public_key, signature);
3377
+ const public_key = AnyPublicKey.deserialize(deserializer);
3378
+ const signature = AnySignature.deserialize(deserializer);
3379
+ return new AccountAuthenticatorSingleKey(public_key, signature);
3184
3380
  }
3185
3381
  };
3186
3382
 
3187
3383
  // src/transactions/authenticator/transaction.ts
3188
- var TransactionAuthenticator = class {
3384
+ var TransactionAuthenticator = class extends Serializable {
3189
3385
  static deserialize(deserializer) {
3190
3386
  const index = deserializer.deserializeUleb128AsU32();
3191
3387
  switch (index) {
@@ -3197,8 +3393,8 @@ var TransactionAuthenticator = class {
3197
3393
  return TransactionAuthenticatorMultiAgent.load(deserializer);
3198
3394
  case 3 /* FeePayer */:
3199
3395
  return TransactionAuthenticatorFeePayer.load(deserializer);
3200
- case 4 /* Secp256k1Ecdsa */:
3201
- return TransactionAuthenticatorSecp256k1.load(deserializer);
3396
+ case 4 /* SingleSenderTransactionAuthenticator */:
3397
+ return SingleSenderTransactionAuthenticator.load(deserializer);
3202
3398
  default:
3203
3399
  throw new Error(`Unknown variant index for TransactionAuthenticator: ${index}`);
3204
3400
  }
@@ -3284,21 +3480,18 @@ var TransactionAuthenticatorFeePayer = class extends TransactionAuthenticator {
3284
3480
  return new TransactionAuthenticatorFeePayer(sender, secondary_signer_addresses, secondary_signers, fee_payer);
3285
3481
  }
3286
3482
  };
3287
- var TransactionAuthenticatorSecp256k1 = class extends TransactionAuthenticator {
3288
- constructor(public_key, signature) {
3483
+ var SingleSenderTransactionAuthenticator = class extends TransactionAuthenticator {
3484
+ constructor(sender) {
3289
3485
  super();
3290
- this.public_key = public_key;
3291
- this.signature = signature;
3486
+ this.sender = sender;
3292
3487
  }
3293
3488
  serialize(serializer) {
3294
- serializer.serializeU32AsUleb128(4 /* Secp256k1Ecdsa */);
3295
- this.public_key.serialize(serializer);
3296
- this.signature.serialize(serializer);
3489
+ serializer.serializeU32AsUleb128(4 /* SingleSenderTransactionAuthenticator */);
3490
+ this.sender.serialize(serializer);
3297
3491
  }
3298
3492
  static load(deserializer) {
3299
- const public_key = Secp256k1PublicKey.deserialize(deserializer);
3300
- const signature = Secp256k1Signature.deserialize(deserializer);
3301
- return new TransactionAuthenticatorSecp256k1(public_key, signature);
3493
+ const sender = AccountAuthenticator.deserialize(deserializer);
3494
+ return new SingleSenderTransactionAuthenticator(sender);
3302
3495
  }
3303
3496
  };
3304
3497
 
@@ -3636,7 +3829,7 @@ function generateTransactionPayload(args) {
3636
3829
  var _a, _b, _c;
3637
3830
  if ("bytecode" in args) {
3638
3831
  return new TransactionPayloadScript(
3639
- new Script(Hex.fromHexInput(args.bytecode).toUint8Array(), (_a = args.typeArguments) != null ? _a : [], args.arguments)
3832
+ new Script(Hex.fromHexInput(args.bytecode).toUint8Array(), (_a = args.typeArguments) != null ? _a : [], args.functionArguments)
3640
3833
  );
3641
3834
  }
3642
3835
  if ("multisigAddress" in args) {
@@ -3649,7 +3842,7 @@ function generateTransactionPayload(args) {
3649
3842
  `${funcNameParts2[0]}::${funcNameParts2[1]}`,
3650
3843
  funcNameParts2[2],
3651
3844
  (_b = args.typeArguments) != null ? _b : [],
3652
- args.arguments
3845
+ args.functionArguments
3653
3846
  )
3654
3847
  )
3655
3848
  )
@@ -3661,7 +3854,7 @@ function generateTransactionPayload(args) {
3661
3854
  `${funcNameParts[0]}::${funcNameParts[1]}`,
3662
3855
  funcNameParts[2],
3663
3856
  (_c = args.typeArguments) != null ? _c : [],
3664
- args.arguments
3857
+ args.functionArguments
3665
3858
  )
3666
3859
  );
3667
3860
  }
@@ -3768,26 +3961,25 @@ function generateSignedTransactionForSimulation(args) {
3768
3961
  accountAuthenticator.public_key,
3769
3962
  accountAuthenticator.signature
3770
3963
  );
3771
- } else if (accountAuthenticator instanceof AccountAuthenticatorSecp256k1) {
3772
- transactionAuthenticator = new TransactionAuthenticatorSecp256k1(
3773
- accountAuthenticator.public_key,
3774
- accountAuthenticator.signature
3775
- );
3964
+ } else if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
3965
+ transactionAuthenticator = new SingleSenderTransactionAuthenticator(accountAuthenticator);
3776
3966
  } else {
3777
3967
  throw new Error("Invalid public key");
3778
3968
  }
3779
3969
  return new SignedTransaction(deserializedTransaction, transactionAuthenticator).bcsToBytes();
3780
3970
  }
3781
3971
  function getAuthenticatorForSimulation(publicKey) {
3782
- if (publicKey instanceof Ed25519PublicKey) {
3783
- return new AccountAuthenticatorEd25519(
3784
- new Ed25519PublicKey(publicKey.toUint8Array()),
3785
- new Ed25519Signature(new Uint8Array(64))
3786
- );
3972
+ if (publicKey instanceof AnyPublicKey) {
3973
+ if (publicKey.publicKey instanceof Ed25519PublicKey) {
3974
+ return new AccountAuthenticatorSingleKey(publicKey, new AnySignature(new Ed25519Signature(new Uint8Array(64))));
3975
+ }
3976
+ if (publicKey.publicKey instanceof Secp256k1PublicKey) {
3977
+ return new AccountAuthenticatorSingleKey(publicKey, new AnySignature(new Secp256k1Signature(new Uint8Array(64))));
3978
+ }
3787
3979
  }
3788
- return new AccountAuthenticatorSecp256k1(
3789
- new Secp256k1PublicKey(publicKey.toUint8Array()),
3790
- new Secp256k1Signature(new Uint8Array(64))
3980
+ return new AccountAuthenticatorEd25519(
3981
+ new Ed25519PublicKey(publicKey.toUint8Array()),
3982
+ new Ed25519Signature(new Uint8Array(64))
3791
3983
  );
3792
3984
  }
3793
3985
  function sign(args) {
@@ -3801,11 +3993,8 @@ function sign(args) {
3801
3993
  new Ed25519PublicKey(signer.publicKey.toUint8Array()),
3802
3994
  new Ed25519Signature(signerSignature.toUint8Array())
3803
3995
  );
3804
- case 2 /* Secp256k1Ecdsa */:
3805
- return new AccountAuthenticatorSecp256k1(
3806
- new Secp256k1PublicKey(signer.publicKey.toUint8Array()),
3807
- new Secp256k1Signature(signerSignature.toUint8Array())
3808
- );
3996
+ case 2 /* SingleKey */:
3997
+ return new AccountAuthenticatorSingleKey(signer.publicKey, new AnySignature(signerSignature));
3809
3998
  default:
3810
3999
  throw new Error(`Cannot sign transaction, signing scheme ${signer.signingScheme} not supported`);
3811
4000
  }
@@ -3829,11 +4018,8 @@ function generateSignedTransaction(args) {
3829
4018
  );
3830
4019
  return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
3831
4020
  }
3832
- if (accountAuthenticator instanceof AccountAuthenticatorSecp256k1) {
3833
- const transactionAuthenticator = new TransactionAuthenticatorSecp256k1(
3834
- accountAuthenticator.public_key,
3835
- accountAuthenticator.signature
3836
- );
4021
+ if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
4022
+ const transactionAuthenticator = new SingleSenderTransactionAuthenticator(accountAuthenticator);
3837
4023
  return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
3838
4024
  }
3839
4025
  throw new Error(
@@ -3963,6 +4149,28 @@ async function submitTransaction(args) {
3963
4149
  });
3964
4150
  return data;
3965
4151
  }
4152
+ async function signAndSubmitTransaction(args) {
4153
+ const { aptosConfig, signer, transaction } = args;
4154
+ const authenticator = signTransaction({ signer, transaction });
4155
+ return submitTransaction({
4156
+ aptosConfig,
4157
+ transaction,
4158
+ senderAuthenticator: authenticator
4159
+ });
4160
+ }
4161
+ async function publishModuleTransaction(args) {
4162
+ const { aptosConfig, account, metadataBytes, byteCode, options } = args;
4163
+ const transaction = await generateTransaction({
4164
+ aptosConfig,
4165
+ sender: account,
4166
+ data: {
4167
+ function: "0x1::code::publish_package_txn",
4168
+ functionArguments: [MoveVector.U8(metadataBytes), new MoveVector([MoveVector.U8(byteCode)])]
4169
+ },
4170
+ options
4171
+ });
4172
+ return transaction;
4173
+ }
3966
4174
 
3967
4175
  // src/internal/coin.ts
3968
4176
  async function transferCoinTransaction(args) {
@@ -3974,7 +4182,7 @@ async function transferCoinTransaction(args) {
3974
4182
  data: {
3975
4183
  function: "0x1::aptos_account::transfer_coins",
3976
4184
  typeArguments: [new TypeTagStruct(StructTag.fromString(coinStructType))],
3977
- arguments: [AccountAddress.fromHexInput(recipient), new U64(amount)]
4185
+ functionArguments: [AccountAddress.fromHexInput(recipient), new U64(amount)]
3978
4186
  },
3979
4187
  options
3980
4188
  });
@@ -3999,7 +4207,7 @@ async function mintTokenTransaction(args) {
3999
4207
  sender: creator.accountAddress.toString(),
4000
4208
  data: {
4001
4209
  function: "0x4::aptos_token::mint",
4002
- arguments: [
4210
+ functionArguments: [
4003
4211
  new MoveString(args.collection),
4004
4212
  new MoveString(args.description),
4005
4213
  new MoveString(args.name),
@@ -4101,7 +4309,7 @@ async function createCollectionTransaction(args) {
4101
4309
  sender: creator.accountAddress.toString(),
4102
4310
  data: {
4103
4311
  function: "0x4::aptos_token::create_collection",
4104
- arguments: [
4312
+ functionArguments: [
4105
4313
  new MoveString(args.description),
4106
4314
  new U64((_a = args.maxSupply) != null ? _a : MAX_U64_BIG_INT),
4107
4315
  new MoveString(args.name),
@@ -4145,9 +4353,6 @@ async function getCollectionData(args) {
4145
4353
  query: graphqlQuery,
4146
4354
  originMethod: "getCollectionData"
4147
4355
  });
4148
- if (data.current_collections_v2.length === 0) {
4149
- throw Error("Collection not found");
4150
- }
4151
4356
  return data.current_collections_v2[0];
4152
4357
  }
4153
4358
  async function getCollectionId(args) {
@@ -4260,7 +4465,11 @@ async function fundAccount(args) {
4260
4465
  originMethod: "fundAccount"
4261
4466
  });
4262
4467
  const txnHash = data.txn_hashes[0];
4263
- await waitForTransaction({ aptosConfig, transactionHash: txnHash, options: { timeoutSecs } });
4468
+ await waitForTransaction({
4469
+ aptosConfig,
4470
+ transactionHash: txnHash,
4471
+ options: { timeoutSecs }
4472
+ });
4264
4473
  return txnHash;
4265
4474
  }
4266
4475
 
@@ -4338,6 +4547,17 @@ var FungibleAsset = class {
4338
4547
  async getFungibleAssetMetadata(args) {
4339
4548
  return getFungibleAssetMetadata({ aptosConfig: this.config, ...args });
4340
4549
  }
4550
+ async getFungibleAssetMetadataByAssetType(assetType) {
4551
+ const data = await getFungibleAssetMetadata({
4552
+ aptosConfig: this.config,
4553
+ options: {
4554
+ where: {
4555
+ asset_type: { _eq: assetType }
4556
+ }
4557
+ }
4558
+ });
4559
+ return data[0];
4560
+ }
4341
4561
  async getFungibleAssetActivities(args) {
4342
4562
  return getFungibleAssetActivities({ aptosConfig: this.config, ...args });
4343
4563
  }
@@ -4506,13 +4726,15 @@ var TransactionSubmission = class {
4506
4726
  }
4507
4727
  async signAndSubmitTransaction(args) {
4508
4728
  const { signer, transaction } = args;
4509
- const authenticator = signTransaction({ signer, transaction });
4510
- return submitTransaction({
4729
+ return signAndSubmitTransaction({
4511
4730
  aptosConfig: this.config,
4512
- transaction,
4513
- senderAuthenticator: authenticator
4731
+ signer,
4732
+ transaction
4514
4733
  });
4515
4734
  }
4735
+ async publishModuleTransaction(args) {
4736
+ return publishModuleTransaction({ aptosConfig: this.config, ...args });
4737
+ }
4516
4738
  };
4517
4739
 
4518
4740
  // src/api/aptos.ts
@@ -4558,6 +4780,8 @@ export {
4558
4780
  AccountAddress,
4559
4781
  AccountAuthenticatorVariant,
4560
4782
  AddressInvalidReason,
4783
+ AnyPublicKeyVariant,
4784
+ AnySignatureVariant,
4561
4785
  Aptos,
4562
4786
  AptosApiError,
4563
4787
  AptosConfig,
@@ -4599,6 +4823,7 @@ export {
4599
4823
  Serializer,
4600
4824
  Signature,
4601
4825
  SigningScheme,
4826
+ SigningSchemeInput,
4602
4827
  StructTag,
4603
4828
  TransactionAuthenticatorVariant,
4604
4829
  TransactionPayloadVariants,
@@ -4639,6 +4864,7 @@ export {
4639
4864
  postAptosFaucet,
4640
4865
  postAptosFullNode,
4641
4866
  postAptosIndexer,
4867
+ request,
4642
4868
  stringStructTag,
4643
4869
  validateNumberInRange
4644
4870
  };