@aptos-labs/ts-sdk 0.0.1 → 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/dist/browser/index.global.js +25 -25
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.d.ts +160 -43
- package/dist/cjs/index.js +297 -94
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +160 -43
- package/dist/esm/index.mjs +294 -94
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +61 -15
- package/dist/types/index.js +26 -3
- package/dist/types/index.js.map +1 -1
- package/package.json +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,
|
|
@@ -141,7 +144,7 @@ var AptosApiError = class extends Error {
|
|
|
141
144
|
};
|
|
142
145
|
|
|
143
146
|
// src/version.ts
|
|
144
|
-
var VERSION = "
|
|
147
|
+
var VERSION = "2.0.0";
|
|
145
148
|
|
|
146
149
|
// src/types/index.ts
|
|
147
150
|
var MimeType = /* @__PURE__ */ ((MimeType2) => {
|
|
@@ -192,15 +195,26 @@ var TransactionAuthenticatorVariant = /* @__PURE__ */ ((TransactionAuthenticator
|
|
|
192
195
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
193
196
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["MultiAgent"] = 2] = "MultiAgent";
|
|
194
197
|
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["FeePayer"] = 3] = "FeePayer";
|
|
195
|
-
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["
|
|
198
|
+
TransactionAuthenticatorVariant2[TransactionAuthenticatorVariant2["SingleSenderTransactionAuthenticator"] = 4] = "SingleSenderTransactionAuthenticator";
|
|
196
199
|
return TransactionAuthenticatorVariant2;
|
|
197
200
|
})(TransactionAuthenticatorVariant || {});
|
|
198
201
|
var AccountAuthenticatorVariant = /* @__PURE__ */ ((AccountAuthenticatorVariant2) => {
|
|
199
202
|
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["Ed25519"] = 0] = "Ed25519";
|
|
200
203
|
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
201
|
-
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["
|
|
204
|
+
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["SingleKey"] = 2] = "SingleKey";
|
|
205
|
+
AccountAuthenticatorVariant2[AccountAuthenticatorVariant2["MultiKey"] = 3] = "MultiKey";
|
|
202
206
|
return AccountAuthenticatorVariant2;
|
|
203
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 || {});
|
|
204
218
|
var TransactionResponseType = /* @__PURE__ */ ((TransactionResponseType2) => {
|
|
205
219
|
TransactionResponseType2["Pending"] = "pending_transaction";
|
|
206
220
|
TransactionResponseType2["User"] = "user_transaction";
|
|
@@ -230,9 +244,15 @@ var RoleType = /* @__PURE__ */ ((RoleType2) => {
|
|
|
230
244
|
var SigningScheme = /* @__PURE__ */ ((SigningScheme2) => {
|
|
231
245
|
SigningScheme2[SigningScheme2["Ed25519"] = 0] = "Ed25519";
|
|
232
246
|
SigningScheme2[SigningScheme2["MultiEd25519"] = 1] = "MultiEd25519";
|
|
233
|
-
SigningScheme2[SigningScheme2["
|
|
247
|
+
SigningScheme2[SigningScheme2["SingleKey"] = 2] = "SingleKey";
|
|
234
248
|
return SigningScheme2;
|
|
235
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 || {});
|
|
236
256
|
var DeriveScheme = /* @__PURE__ */ ((DeriveScheme2) => {
|
|
237
257
|
DeriveScheme2[DeriveScheme2["DeriveAuid"] = 251] = "DeriveAuid";
|
|
238
258
|
DeriveScheme2[DeriveScheme2["DeriveObjectAddressFromObject"] = 252] = "DeriveObjectAddressFromObject";
|
|
@@ -287,14 +307,15 @@ async function aptosRequest(options, aptosConfig) {
|
|
|
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 });
|
|
1819
|
+
return new Account({ privateKey, address, legacy: args == null ? void 0 : args.legacy });
|
|
1708
1820
|
}
|
|
1709
|
-
static fromPrivateKey(
|
|
1710
|
-
const
|
|
1711
|
-
|
|
1712
|
-
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
1713
|
-
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
1714
|
-
}
|
|
1715
|
-
static fromPrivateKeyAndAddress(args) {
|
|
1716
|
-
return new Account(args);
|
|
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,6 +2806,9 @@ 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
|
|
@@ -3069,6 +3231,42 @@ function nextToken(tagStr, pos) {
|
|
|
3069
3231
|
// src/transactions/transaction_builder/transaction_builder.ts
|
|
3070
3232
|
var import_sha33 = require("@noble/hashes/sha3");
|
|
3071
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
|
+
|
|
3072
3270
|
// src/utils/helpers.ts
|
|
3073
3271
|
async function sleep(timeMs) {
|
|
3074
3272
|
return new Promise((resolve) => {
|
|
@@ -3243,8 +3441,8 @@ var AccountAuthenticator = class extends Serializable {
|
|
|
3243
3441
|
return AccountAuthenticatorEd25519.load(deserializer);
|
|
3244
3442
|
case 1 /* MultiEd25519 */:
|
|
3245
3443
|
return AccountAuthenticatorMultiEd25519.load(deserializer);
|
|
3246
|
-
case 2 /*
|
|
3247
|
-
return
|
|
3444
|
+
case 2 /* SingleKey */:
|
|
3445
|
+
return AccountAuthenticatorSingleKey.load(deserializer);
|
|
3248
3446
|
default:
|
|
3249
3447
|
throw new Error(`Unknown variant index for AccountAuthenticator: ${index}`);
|
|
3250
3448
|
}
|
|
@@ -3284,26 +3482,26 @@ var AccountAuthenticatorMultiEd25519 = class extends AccountAuthenticator {
|
|
|
3284
3482
|
return new AccountAuthenticatorMultiEd25519(public_key, signature);
|
|
3285
3483
|
}
|
|
3286
3484
|
};
|
|
3287
|
-
var
|
|
3485
|
+
var AccountAuthenticatorSingleKey = class extends AccountAuthenticator {
|
|
3288
3486
|
constructor(public_key, signature) {
|
|
3289
3487
|
super();
|
|
3290
3488
|
this.public_key = public_key;
|
|
3291
3489
|
this.signature = signature;
|
|
3292
3490
|
}
|
|
3293
3491
|
serialize(serializer) {
|
|
3294
|
-
serializer.serializeU32AsUleb128(2 /*
|
|
3492
|
+
serializer.serializeU32AsUleb128(2 /* SingleKey */);
|
|
3295
3493
|
this.public_key.serialize(serializer);
|
|
3296
3494
|
this.signature.serialize(serializer);
|
|
3297
3495
|
}
|
|
3298
3496
|
static load(deserializer) {
|
|
3299
|
-
const public_key =
|
|
3300
|
-
const signature =
|
|
3301
|
-
return new
|
|
3497
|
+
const public_key = AnyPublicKey.deserialize(deserializer);
|
|
3498
|
+
const signature = AnySignature.deserialize(deserializer);
|
|
3499
|
+
return new AccountAuthenticatorSingleKey(public_key, signature);
|
|
3302
3500
|
}
|
|
3303
3501
|
};
|
|
3304
3502
|
|
|
3305
3503
|
// src/transactions/authenticator/transaction.ts
|
|
3306
|
-
var TransactionAuthenticator = class {
|
|
3504
|
+
var TransactionAuthenticator = class extends Serializable {
|
|
3307
3505
|
static deserialize(deserializer) {
|
|
3308
3506
|
const index = deserializer.deserializeUleb128AsU32();
|
|
3309
3507
|
switch (index) {
|
|
@@ -3315,8 +3513,8 @@ var TransactionAuthenticator = class {
|
|
|
3315
3513
|
return TransactionAuthenticatorMultiAgent.load(deserializer);
|
|
3316
3514
|
case 3 /* FeePayer */:
|
|
3317
3515
|
return TransactionAuthenticatorFeePayer.load(deserializer);
|
|
3318
|
-
case 4 /*
|
|
3319
|
-
return
|
|
3516
|
+
case 4 /* SingleSenderTransactionAuthenticator */:
|
|
3517
|
+
return SingleSenderTransactionAuthenticator.load(deserializer);
|
|
3320
3518
|
default:
|
|
3321
3519
|
throw new Error(`Unknown variant index for TransactionAuthenticator: ${index}`);
|
|
3322
3520
|
}
|
|
@@ -3402,21 +3600,18 @@ var TransactionAuthenticatorFeePayer = class extends TransactionAuthenticator {
|
|
|
3402
3600
|
return new TransactionAuthenticatorFeePayer(sender, secondary_signer_addresses, secondary_signers, fee_payer);
|
|
3403
3601
|
}
|
|
3404
3602
|
};
|
|
3405
|
-
var
|
|
3406
|
-
constructor(
|
|
3603
|
+
var SingleSenderTransactionAuthenticator = class extends TransactionAuthenticator {
|
|
3604
|
+
constructor(sender) {
|
|
3407
3605
|
super();
|
|
3408
|
-
this.
|
|
3409
|
-
this.signature = signature;
|
|
3606
|
+
this.sender = sender;
|
|
3410
3607
|
}
|
|
3411
3608
|
serialize(serializer) {
|
|
3412
|
-
serializer.serializeU32AsUleb128(4 /*
|
|
3413
|
-
this.
|
|
3414
|
-
this.signature.serialize(serializer);
|
|
3609
|
+
serializer.serializeU32AsUleb128(4 /* SingleSenderTransactionAuthenticator */);
|
|
3610
|
+
this.sender.serialize(serializer);
|
|
3415
3611
|
}
|
|
3416
3612
|
static load(deserializer) {
|
|
3417
|
-
const
|
|
3418
|
-
|
|
3419
|
-
return new TransactionAuthenticatorSecp256k1(public_key, signature);
|
|
3613
|
+
const sender = AccountAuthenticator.deserialize(deserializer);
|
|
3614
|
+
return new SingleSenderTransactionAuthenticator(sender);
|
|
3420
3615
|
}
|
|
3421
3616
|
};
|
|
3422
3617
|
|
|
@@ -3754,7 +3949,7 @@ function generateTransactionPayload(args) {
|
|
|
3754
3949
|
var _a, _b, _c;
|
|
3755
3950
|
if ("bytecode" in args) {
|
|
3756
3951
|
return new TransactionPayloadScript(
|
|
3757
|
-
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)
|
|
3758
3953
|
);
|
|
3759
3954
|
}
|
|
3760
3955
|
if ("multisigAddress" in args) {
|
|
@@ -3767,7 +3962,7 @@ function generateTransactionPayload(args) {
|
|
|
3767
3962
|
`${funcNameParts2[0]}::${funcNameParts2[1]}`,
|
|
3768
3963
|
funcNameParts2[2],
|
|
3769
3964
|
(_b = args.typeArguments) != null ? _b : [],
|
|
3770
|
-
args.
|
|
3965
|
+
args.functionArguments
|
|
3771
3966
|
)
|
|
3772
3967
|
)
|
|
3773
3968
|
)
|
|
@@ -3779,7 +3974,7 @@ function generateTransactionPayload(args) {
|
|
|
3779
3974
|
`${funcNameParts[0]}::${funcNameParts[1]}`,
|
|
3780
3975
|
funcNameParts[2],
|
|
3781
3976
|
(_c = args.typeArguments) != null ? _c : [],
|
|
3782
|
-
args.
|
|
3977
|
+
args.functionArguments
|
|
3783
3978
|
)
|
|
3784
3979
|
);
|
|
3785
3980
|
}
|
|
@@ -3886,26 +4081,25 @@ function generateSignedTransactionForSimulation(args) {
|
|
|
3886
4081
|
accountAuthenticator.public_key,
|
|
3887
4082
|
accountAuthenticator.signature
|
|
3888
4083
|
);
|
|
3889
|
-
} else if (accountAuthenticator instanceof
|
|
3890
|
-
transactionAuthenticator = new
|
|
3891
|
-
accountAuthenticator.public_key,
|
|
3892
|
-
accountAuthenticator.signature
|
|
3893
|
-
);
|
|
4084
|
+
} else if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
|
|
4085
|
+
transactionAuthenticator = new SingleSenderTransactionAuthenticator(accountAuthenticator);
|
|
3894
4086
|
} else {
|
|
3895
4087
|
throw new Error("Invalid public key");
|
|
3896
4088
|
}
|
|
3897
4089
|
return new SignedTransaction(deserializedTransaction, transactionAuthenticator).bcsToBytes();
|
|
3898
4090
|
}
|
|
3899
4091
|
function getAuthenticatorForSimulation(publicKey) {
|
|
3900
|
-
if (publicKey instanceof
|
|
3901
|
-
|
|
3902
|
-
new
|
|
3903
|
-
|
|
3904
|
-
)
|
|
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
|
+
}
|
|
3905
4099
|
}
|
|
3906
|
-
return new
|
|
3907
|
-
new
|
|
3908
|
-
new
|
|
4100
|
+
return new AccountAuthenticatorEd25519(
|
|
4101
|
+
new Ed25519PublicKey(publicKey.toUint8Array()),
|
|
4102
|
+
new Ed25519Signature(new Uint8Array(64))
|
|
3909
4103
|
);
|
|
3910
4104
|
}
|
|
3911
4105
|
function sign(args) {
|
|
@@ -3919,11 +4113,8 @@ function sign(args) {
|
|
|
3919
4113
|
new Ed25519PublicKey(signer.publicKey.toUint8Array()),
|
|
3920
4114
|
new Ed25519Signature(signerSignature.toUint8Array())
|
|
3921
4115
|
);
|
|
3922
|
-
case 2 /*
|
|
3923
|
-
return new
|
|
3924
|
-
new Secp256k1PublicKey(signer.publicKey.toUint8Array()),
|
|
3925
|
-
new Secp256k1Signature(signerSignature.toUint8Array())
|
|
3926
|
-
);
|
|
4116
|
+
case 2 /* SingleKey */:
|
|
4117
|
+
return new AccountAuthenticatorSingleKey(signer.publicKey, new AnySignature(signerSignature));
|
|
3927
4118
|
default:
|
|
3928
4119
|
throw new Error(`Cannot sign transaction, signing scheme ${signer.signingScheme} not supported`);
|
|
3929
4120
|
}
|
|
@@ -3947,11 +4138,8 @@ function generateSignedTransaction(args) {
|
|
|
3947
4138
|
);
|
|
3948
4139
|
return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
|
|
3949
4140
|
}
|
|
3950
|
-
if (accountAuthenticator instanceof
|
|
3951
|
-
const transactionAuthenticator = new
|
|
3952
|
-
accountAuthenticator.public_key,
|
|
3953
|
-
accountAuthenticator.signature
|
|
3954
|
-
);
|
|
4141
|
+
if (accountAuthenticator instanceof AccountAuthenticatorSingleKey) {
|
|
4142
|
+
const transactionAuthenticator = new SingleSenderTransactionAuthenticator(accountAuthenticator);
|
|
3955
4143
|
return new SignedTransaction(transactionToSubmit, transactionAuthenticator).bcsToBytes();
|
|
3956
4144
|
}
|
|
3957
4145
|
throw new Error(
|
|
@@ -4097,7 +4285,7 @@ async function publishModuleTransaction(args) {
|
|
|
4097
4285
|
sender: account,
|
|
4098
4286
|
data: {
|
|
4099
4287
|
function: "0x1::code::publish_package_txn",
|
|
4100
|
-
|
|
4288
|
+
functionArguments: [MoveVector.U8(metadataBytes), new MoveVector([MoveVector.U8(byteCode)])]
|
|
4101
4289
|
},
|
|
4102
4290
|
options
|
|
4103
4291
|
});
|
|
@@ -4114,7 +4302,7 @@ async function transferCoinTransaction(args) {
|
|
|
4114
4302
|
data: {
|
|
4115
4303
|
function: "0x1::aptos_account::transfer_coins",
|
|
4116
4304
|
typeArguments: [new TypeTagStruct(StructTag.fromString(coinStructType))],
|
|
4117
|
-
|
|
4305
|
+
functionArguments: [AccountAddress.fromHexInput(recipient), new U64(amount)]
|
|
4118
4306
|
},
|
|
4119
4307
|
options
|
|
4120
4308
|
});
|
|
@@ -4139,7 +4327,7 @@ async function mintTokenTransaction(args) {
|
|
|
4139
4327
|
sender: creator.accountAddress.toString(),
|
|
4140
4328
|
data: {
|
|
4141
4329
|
function: "0x4::aptos_token::mint",
|
|
4142
|
-
|
|
4330
|
+
functionArguments: [
|
|
4143
4331
|
new MoveString(args.collection),
|
|
4144
4332
|
new MoveString(args.description),
|
|
4145
4333
|
new MoveString(args.name),
|
|
@@ -4241,7 +4429,7 @@ async function createCollectionTransaction(args) {
|
|
|
4241
4429
|
sender: creator.accountAddress.toString(),
|
|
4242
4430
|
data: {
|
|
4243
4431
|
function: "0x4::aptos_token::create_collection",
|
|
4244
|
-
|
|
4432
|
+
functionArguments: [
|
|
4245
4433
|
new MoveString(args.description),
|
|
4246
4434
|
new U64((_a = args.maxSupply) != null ? _a : MAX_U64_BIG_INT),
|
|
4247
4435
|
new MoveString(args.name),
|
|
@@ -4285,9 +4473,6 @@ async function getCollectionData(args) {
|
|
|
4285
4473
|
query: graphqlQuery,
|
|
4286
4474
|
originMethod: "getCollectionData"
|
|
4287
4475
|
});
|
|
4288
|
-
if (data.current_collections_v2.length === 0) {
|
|
4289
|
-
throw Error("Collection not found");
|
|
4290
|
-
}
|
|
4291
4476
|
return data.current_collections_v2[0];
|
|
4292
4477
|
}
|
|
4293
4478
|
async function getCollectionId(args) {
|
|
@@ -4400,7 +4585,11 @@ async function fundAccount(args) {
|
|
|
4400
4585
|
originMethod: "fundAccount"
|
|
4401
4586
|
});
|
|
4402
4587
|
const txnHash = data.txn_hashes[0];
|
|
4403
|
-
await waitForTransaction({
|
|
4588
|
+
await waitForTransaction({
|
|
4589
|
+
aptosConfig,
|
|
4590
|
+
transactionHash: txnHash,
|
|
4591
|
+
options: { timeoutSecs }
|
|
4592
|
+
});
|
|
4404
4593
|
return txnHash;
|
|
4405
4594
|
}
|
|
4406
4595
|
|
|
@@ -4478,6 +4667,17 @@ var FungibleAsset = class {
|
|
|
4478
4667
|
async getFungibleAssetMetadata(args) {
|
|
4479
4668
|
return getFungibleAssetMetadata({ aptosConfig: this.config, ...args });
|
|
4480
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
|
+
}
|
|
4481
4681
|
async getFungibleAssetActivities(args) {
|
|
4482
4682
|
return getFungibleAssetActivities({ aptosConfig: this.config, ...args });
|
|
4483
4683
|
}
|
|
@@ -4701,6 +4901,8 @@ applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
|
|
|
4701
4901
|
AccountAddress,
|
|
4702
4902
|
AccountAuthenticatorVariant,
|
|
4703
4903
|
AddressInvalidReason,
|
|
4904
|
+
AnyPublicKeyVariant,
|
|
4905
|
+
AnySignatureVariant,
|
|
4704
4906
|
Aptos,
|
|
4705
4907
|
AptosApiError,
|
|
4706
4908
|
AptosConfig,
|
|
@@ -4742,6 +4944,7 @@ applyMixin(Aptos, TransactionSubmission, "transactionSubmission");
|
|
|
4742
4944
|
Serializer,
|
|
4743
4945
|
Signature,
|
|
4744
4946
|
SigningScheme,
|
|
4947
|
+
SigningSchemeInput,
|
|
4745
4948
|
StructTag,
|
|
4746
4949
|
TransactionAuthenticatorVariant,
|
|
4747
4950
|
TransactionPayloadVariants,
|