@aptos-labs/ts-sdk 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -24
- package/dist/browser/index.global.js +25 -25
- package/dist/browser/index.global.js.map +1 -1
- package/dist/cjs/index.d.ts +809 -184
- package/dist/cjs/index.js +1458 -616
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/index.d.ts +809 -184
- package/dist/esm/index.mjs +1388 -614
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/index.d.ts +72 -25
- package/dist/types/index.js +28 -3
- package/dist/types/index.js.map +1 -1
- package/package.json +1 -1
- package/src/api/account.ts +2 -2
- package/src/api/coin.ts +5 -5
- package/src/api/digitalAsset.ts +5 -5
- package/src/api/event.ts +2 -2
- package/src/api/faucet.ts +7 -3
- package/src/api/transactionSubmission.ts +24 -24
- package/src/bcs/serializable/fixedBytes.ts +1 -1
- package/src/bcs/serializable/moveStructs.ts +16 -36
- package/src/core/account.ts +12 -8
- package/src/core/accountAddress.ts +4 -2
- package/src/core/authenticationKey.ts +24 -2
- package/src/core/crypto/anyPublicKey.ts +14 -18
- package/src/core/crypto/ed25519.ts +6 -0
- package/src/core/crypto/index.ts +1 -0
- package/src/core/crypto/multiKey.ts +122 -0
- package/src/core/crypto/secp256k1.ts +2 -0
- package/src/index.ts +1 -2
- package/src/internal/account.ts +5 -5
- package/src/internal/coin.ts +8 -8
- package/src/internal/digitalAsset.ts +7 -7
- package/src/internal/event.ts +2 -2
- package/src/internal/faucet.ts +9 -5
- package/src/internal/transactionSubmission.ts +40 -15
- package/src/transactions/authenticator/account.ts +39 -0
- package/src/transactions/authenticator/index.ts +5 -0
- package/src/transactions/authenticator/transaction.ts +6 -6
- package/src/transactions/index.ts +9 -0
- package/src/transactions/instances/index.ts +1 -0
- package/src/transactions/instances/transactionPayload.ts +13 -8
- package/src/transactions/transactionBuilder/helpers.ts +99 -0
- package/src/transactions/transactionBuilder/index.ts +6 -0
- package/src/transactions/transactionBuilder/remoteAbi.ts +339 -0
- package/src/transactions/{transaction_builder/transaction_builder.ts → transactionBuilder/transactionBuilder.ts} +149 -68
- package/src/transactions/typeTag/index.ts +385 -0
- package/src/transactions/typeTag/parser.ts +21 -8
- package/src/transactions/types.ts +87 -46
- package/src/types/index.ts +18 -16
- package/src/transactions/typeTag/typeTag.ts +0 -487
|
@@ -24,7 +24,7 @@ import { TransactionArgument } from "../../transactions/instances/transactionArg
|
|
|
24
24
|
* @example
|
|
25
25
|
* const yourCustomSerializedBytes = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
|
|
26
26
|
* const fixedBytes = new FixedBytes(yourCustomSerializedBytes);
|
|
27
|
-
* const payload = generateTransactionPayload({
|
|
27
|
+
* const payload = await generateTransactionPayload({
|
|
28
28
|
* function: "0xbeefcafe::your_module::your_function_that_requires_custom_serialization",
|
|
29
29
|
* functionArguments: [yourCustomBytes],
|
|
30
30
|
* });
|
|
@@ -6,7 +6,6 @@ import { Serializable, Serializer } from "../serializer";
|
|
|
6
6
|
import { Deserializable, Deserializer } from "../deserializer";
|
|
7
7
|
import { AnyNumber, HexInput, ScriptTransactionArgumentVariants } from "../../types";
|
|
8
8
|
import { Hex } from "../../core/hex";
|
|
9
|
-
import { AccountAddress } from "../../core/accountAddress";
|
|
10
9
|
import { EntryFunctionArgument, TransactionArgument } from "../../transactions/instances/transactionArgument";
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -52,7 +51,10 @@ import { EntryFunctionArgument, TransactionArgument } from "../../transactions/i
|
|
|
52
51
|
* values: an Array<T> of values where T is a class that implements Serializable
|
|
53
52
|
* @returns a `MoveVector<T>` with the values `values`
|
|
54
53
|
*/
|
|
55
|
-
export class MoveVector<T extends Serializable
|
|
54
|
+
export class MoveVector<T extends Serializable & EntryFunctionArgument>
|
|
55
|
+
extends Serializable
|
|
56
|
+
implements TransactionArgument
|
|
57
|
+
{
|
|
56
58
|
public values: Array<T>;
|
|
57
59
|
|
|
58
60
|
constructor(values: Array<T>) {
|
|
@@ -209,7 +211,10 @@ export class MoveVector<T extends Serializable> extends Serializable implements
|
|
|
209
211
|
* @returns a MoveVector of the corresponding class T
|
|
210
212
|
* *
|
|
211
213
|
*/
|
|
212
|
-
static deserialize<T extends Serializable
|
|
214
|
+
static deserialize<T extends Serializable & EntryFunctionArgument>(
|
|
215
|
+
deserializer: Deserializer,
|
|
216
|
+
cls: Deserializable<T>,
|
|
217
|
+
): MoveVector<T> {
|
|
213
218
|
const length = deserializer.deserializeUleb128AsU32();
|
|
214
219
|
const values = new Array<T>();
|
|
215
220
|
for (let i = 0; i < length; i += 1) {
|
|
@@ -247,7 +252,10 @@ export class MoveString extends Serializable implements TransactionArgument {
|
|
|
247
252
|
}
|
|
248
253
|
}
|
|
249
254
|
|
|
250
|
-
export class MoveOption<T extends Serializable
|
|
255
|
+
export class MoveOption<T extends Serializable & EntryFunctionArgument>
|
|
256
|
+
extends Serializable
|
|
257
|
+
implements EntryFunctionArgument
|
|
258
|
+
{
|
|
251
259
|
private vec: MoveVector<T>;
|
|
252
260
|
|
|
253
261
|
public readonly value?: T;
|
|
@@ -424,39 +432,11 @@ export class MoveOption<T extends Serializable> extends Serializable implements
|
|
|
424
432
|
return new MoveOption<MoveString>(value !== null && value !== undefined ? new MoveString(value) : undefined);
|
|
425
433
|
}
|
|
426
434
|
|
|
427
|
-
static deserialize<U extends Serializable
|
|
435
|
+
static deserialize<U extends Serializable & EntryFunctionArgument>(
|
|
436
|
+
deserializer: Deserializer,
|
|
437
|
+
cls: Deserializable<U>,
|
|
438
|
+
): MoveOption<U> {
|
|
428
439
|
const vector = MoveVector.deserialize(deserializer, cls);
|
|
429
440
|
return new MoveOption(vector.values[0]);
|
|
430
441
|
}
|
|
431
442
|
}
|
|
432
|
-
|
|
433
|
-
export class MoveObject extends Serializable implements TransactionArgument {
|
|
434
|
-
public value: AccountAddress;
|
|
435
|
-
|
|
436
|
-
constructor(value: HexInput | AccountAddress) {
|
|
437
|
-
super();
|
|
438
|
-
|
|
439
|
-
if (value instanceof AccountAddress) {
|
|
440
|
-
this.value = value;
|
|
441
|
-
} else {
|
|
442
|
-
this.value = AccountAddress.fromHexInputRelaxed(value);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
serialize(serializer: Serializer): void {
|
|
447
|
-
serializer.serialize(this.value);
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
serializeForEntryFunction(serializer: Serializer): void {
|
|
451
|
-
this.value.serializeForEntryFunction(serializer);
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
serializeForScriptFunction(serializer: Serializer): void {
|
|
455
|
-
this.value.serializeForScriptFunction(serializer);
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
static deserialize(deserializer: Deserializer): MoveObject {
|
|
459
|
-
const address = deserializer.deserialize(AccountAddress);
|
|
460
|
-
return new MoveObject(address);
|
|
461
|
-
}
|
|
462
|
-
}
|
package/src/core/account.ts
CHANGED
|
@@ -62,8 +62,8 @@ export class Account {
|
|
|
62
62
|
*
|
|
63
63
|
* @param args.privateKey PrivateKey - private key of the account
|
|
64
64
|
* @param args.address AccountAddress - address of the account
|
|
65
|
-
* @param args.legacy optional. If set to true, the keypair
|
|
66
|
-
* to
|
|
65
|
+
* @param args.legacy optional. If set to true, the keypair authentication keys will be derived with a Legacy scheme.
|
|
66
|
+
* Defaults to deriving an authentication key with a Unified scheme
|
|
67
67
|
*
|
|
68
68
|
* This method is private because it should only be called by the factory static methods.
|
|
69
69
|
* @returns Account
|
|
@@ -129,7 +129,6 @@ export class Account {
|
|
|
129
129
|
case SigningSchemeInput.Secp256k1Ecdsa:
|
|
130
130
|
privateKey = Secp256k1PrivateKey.generate();
|
|
131
131
|
break;
|
|
132
|
-
// TODO: Add support for MultiEd25519 as AnyMultiKey
|
|
133
132
|
default:
|
|
134
133
|
privateKey = Ed25519PrivateKey.generate();
|
|
135
134
|
}
|
|
@@ -141,23 +140,28 @@ export class Account {
|
|
|
141
140
|
|
|
142
141
|
const address = new AccountAddress({
|
|
143
142
|
data: Account.authKey({
|
|
144
|
-
publicKey,
|
|
143
|
+
publicKey,
|
|
145
144
|
}).toUint8Array(),
|
|
146
145
|
});
|
|
147
146
|
return new Account({ privateKey, address, legacy: args?.legacy });
|
|
148
147
|
}
|
|
149
148
|
|
|
150
149
|
/**
|
|
151
|
-
*
|
|
150
|
+
* Instantiates an account given a private key and a specified account address.
|
|
151
|
+
* This is primarily used to instantiate an `Account` that has had its authentication key rotated.
|
|
152
152
|
*
|
|
153
153
|
* @param privateKey PrivateKey - private key of the account
|
|
154
154
|
* @param address The account address
|
|
155
|
-
* @param args.legacy optional. If set to true, the keypair
|
|
156
|
-
* to
|
|
155
|
+
* @param args.legacy optional. If set to true, the keypair authentication keys will be derived with a Legacy scheme.
|
|
156
|
+
* Defaults to deriving an authentication key with a Unified scheme
|
|
157
157
|
*
|
|
158
158
|
* @returns Account
|
|
159
159
|
*/
|
|
160
|
-
static
|
|
160
|
+
static fromPrivateKeyAndAddress(args: {
|
|
161
|
+
privateKey: PrivateKey;
|
|
162
|
+
address: AccountAddress;
|
|
163
|
+
legacy?: boolean;
|
|
164
|
+
}): Account {
|
|
161
165
|
const { privateKey, address, legacy } = args;
|
|
162
166
|
return new Account({ privateKey, address, legacy });
|
|
163
167
|
}
|
|
@@ -53,6 +53,8 @@ export class AccountAddress extends Serializable implements TransactionArgument
|
|
|
53
53
|
*/
|
|
54
54
|
static readonly LONG_STRING_LENGTH: number = 64;
|
|
55
55
|
|
|
56
|
+
static ZERO: AccountAddress = AccountAddress.fromString("0x0");
|
|
57
|
+
|
|
56
58
|
static ONE: AccountAddress = AccountAddress.fromString("0x1");
|
|
57
59
|
|
|
58
60
|
static TWO: AccountAddress = AccountAddress.fromString("0x2");
|
|
@@ -107,7 +109,7 @@ export class AccountAddress extends Serializable implements TransactionArgument
|
|
|
107
109
|
*
|
|
108
110
|
* @returns AccountAddress as a string conforming to AIP-40.
|
|
109
111
|
*/
|
|
110
|
-
toString(): string {
|
|
112
|
+
toString(): `0x${string}` {
|
|
111
113
|
return `0x${this.toStringWithoutPrefix()}`;
|
|
112
114
|
}
|
|
113
115
|
|
|
@@ -139,7 +141,7 @@ export class AccountAddress extends Serializable implements TransactionArgument
|
|
|
139
141
|
*
|
|
140
142
|
* @returns AccountAddress as a string in LONG form.
|
|
141
143
|
*/
|
|
142
|
-
toStringLong(): string {
|
|
144
|
+
toStringLong(): `0x${string}` {
|
|
143
145
|
return `0x${this.toStringLongWithoutPrefix()}`;
|
|
144
146
|
}
|
|
145
147
|
|
|
@@ -9,6 +9,9 @@ import { MultiEd25519PublicKey } from "./crypto/multiEd25519";
|
|
|
9
9
|
import { Hex } from "./hex";
|
|
10
10
|
import { AuthenticationKeyScheme, HexInput, SigningScheme } from "../types";
|
|
11
11
|
import { AnyPublicKey } from "./crypto/anyPublicKey";
|
|
12
|
+
import { MultiKey } from "./crypto/multiKey";
|
|
13
|
+
import { Serializable, Serializer } from "../bcs/serializer";
|
|
14
|
+
import { Deserializer } from "../bcs/deserializer";
|
|
12
15
|
|
|
13
16
|
/**
|
|
14
17
|
* Each account stores an authentication key. Authentication key enables account owners to rotate
|
|
@@ -19,7 +22,7 @@ import { AnyPublicKey } from "./crypto/anyPublicKey";
|
|
|
19
22
|
*
|
|
20
23
|
* Account addresses can be derived from AuthenticationKey
|
|
21
24
|
*/
|
|
22
|
-
export class AuthenticationKey {
|
|
25
|
+
export class AuthenticationKey extends Serializable {
|
|
23
26
|
/**
|
|
24
27
|
* An authentication key is always a SHA3-256 hash of data, and is always 32 bytes.
|
|
25
28
|
*/
|
|
@@ -31,6 +34,7 @@ export class AuthenticationKey {
|
|
|
31
34
|
public readonly data: Hex;
|
|
32
35
|
|
|
33
36
|
constructor(args: { data: HexInput }) {
|
|
37
|
+
super();
|
|
34
38
|
const { data } = args;
|
|
35
39
|
const hex = Hex.fromHexInput(data);
|
|
36
40
|
if (hex.toUint8Array().length !== AuthenticationKey.LENGTH) {
|
|
@@ -39,6 +43,20 @@ export class AuthenticationKey {
|
|
|
39
43
|
this.data = hex;
|
|
40
44
|
}
|
|
41
45
|
|
|
46
|
+
serialize(serializer: Serializer): void {
|
|
47
|
+
serializer.serializeFixedBytes(this.data.toUint8Array());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Deserialize an AuthenticationKey from the byte buffer in a Deserializer instance.
|
|
52
|
+
* @param deserializer The deserializer to deserialize the AuthenticationKey from.
|
|
53
|
+
* @returns An instance of AuthenticationKey.
|
|
54
|
+
*/
|
|
55
|
+
static deserialize(deserializer: Deserializer): AuthenticationKey {
|
|
56
|
+
const bytes = deserializer.deserializeFixedBytes(AuthenticationKey.LENGTH);
|
|
57
|
+
return new AuthenticationKey({ data: bytes });
|
|
58
|
+
}
|
|
59
|
+
|
|
42
60
|
toString(): string {
|
|
43
61
|
return this.data.toString();
|
|
44
62
|
}
|
|
@@ -57,13 +75,14 @@ export class AuthenticationKey {
|
|
|
57
75
|
const { publicKey, scheme } = args;
|
|
58
76
|
let authKeyBytes: Uint8Array;
|
|
59
77
|
|
|
60
|
-
// TODO - support multied25519 key and MultiKey
|
|
61
78
|
switch (scheme) {
|
|
79
|
+
case SigningScheme.MultiKey:
|
|
62
80
|
case SigningScheme.SingleKey: {
|
|
63
81
|
const singleKeyBytes = publicKey.bcsToBytes();
|
|
64
82
|
authKeyBytes = new Uint8Array([...singleKeyBytes, scheme]);
|
|
65
83
|
break;
|
|
66
84
|
}
|
|
85
|
+
|
|
67
86
|
case SigningScheme.Ed25519:
|
|
68
87
|
case SigningScheme.MultiEd25519: {
|
|
69
88
|
const ed25519PublicKeyBytes = publicKey.toUint8Array();
|
|
@@ -71,6 +90,7 @@ export class AuthenticationKey {
|
|
|
71
90
|
authKeyBytes = new Uint8Array([...inputBytes, scheme]);
|
|
72
91
|
break;
|
|
73
92
|
}
|
|
93
|
+
|
|
74
94
|
default:
|
|
75
95
|
throw new Error(`Scheme ${scheme} is not supported`);
|
|
76
96
|
}
|
|
@@ -99,6 +119,8 @@ export class AuthenticationKey {
|
|
|
99
119
|
scheme = SigningScheme.MultiEd25519.valueOf();
|
|
100
120
|
} else if (publicKey instanceof AnyPublicKey) {
|
|
101
121
|
scheme = SigningScheme.SingleKey.valueOf();
|
|
122
|
+
} else if (publicKey instanceof MultiKey) {
|
|
123
|
+
scheme = SigningScheme.MultiKey.valueOf();
|
|
102
124
|
} else {
|
|
103
125
|
throw new Error("No supported authentication scheme for public key");
|
|
104
126
|
}
|
|
@@ -2,10 +2,21 @@ import { Serializer, Deserializer } from "../../bcs";
|
|
|
2
2
|
import { AnyPublicKeyVariant, HexInput } from "../../types";
|
|
3
3
|
import { AnySignature } from "./anySignature";
|
|
4
4
|
import { PublicKey } from "./asymmetricCrypto";
|
|
5
|
-
import { Ed25519PublicKey
|
|
6
|
-
import { Secp256k1PublicKey
|
|
5
|
+
import { Ed25519PublicKey } from "./ed25519";
|
|
6
|
+
import { Secp256k1PublicKey } from "./secp256k1";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Represents any public key supported by Aptos.
|
|
10
|
+
*
|
|
11
|
+
* Since [AIP-55](https://github.com/aptos-foundation/AIPs/pull/263) Aptos supports
|
|
12
|
+
* `Legacy` and `Unified` authentication keys.
|
|
13
|
+
*
|
|
14
|
+
* Any unified authentication key is represented in the SDK as `AnyPublicKey`.
|
|
15
|
+
*/
|
|
8
16
|
export class AnyPublicKey extends PublicKey {
|
|
17
|
+
/**
|
|
18
|
+
* Reference to the inner public key
|
|
19
|
+
*/
|
|
9
20
|
public readonly publicKey: PublicKey;
|
|
10
21
|
|
|
11
22
|
constructor(publicKey: PublicKey) {
|
|
@@ -40,22 +51,7 @@ export class AnyPublicKey extends PublicKey {
|
|
|
40
51
|
*/
|
|
41
52
|
verifySignature(args: { message: HexInput; signature: AnySignature }): boolean {
|
|
42
53
|
const { message, signature } = args;
|
|
43
|
-
|
|
44
|
-
return this.publicKey.verifySignature({ message, signature: signature.signature });
|
|
45
|
-
// eslint-disable-next-line no-else-return
|
|
46
|
-
} else if (this.isSecp256k1Signature(signature)) {
|
|
47
|
-
return this.publicKey.verifySignature({ message, signature: signature.signature });
|
|
48
|
-
} else {
|
|
49
|
-
throw new Error("Unknown public key type");
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
isED25519Signature(signature: AnySignature): boolean {
|
|
54
|
-
return this.publicKey instanceof Ed25519PublicKey && signature.signature instanceof Ed25519Signature;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
isSecp256k1Signature(signature: AnySignature): boolean {
|
|
58
|
-
return this.publicKey instanceof Secp256k1PublicKey && signature.signature instanceof Secp256k1Signature;
|
|
54
|
+
return this.publicKey.verifySignature({ message, signature });
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
serialize(serializer: Serializer): void {
|
|
@@ -10,6 +10,12 @@ import { HexInput } from "../../types";
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Represents the public key of an Ed25519 key pair.
|
|
13
|
+
*
|
|
14
|
+
* Since [AIP-55](https://github.com/aptos-foundation/AIPs/pull/263) Aptos supports
|
|
15
|
+
* `Legacy` and `Unified` authentication keys.
|
|
16
|
+
*
|
|
17
|
+
* Ed25519 scheme is represented in the SDK as `Legacy authentication key` and also
|
|
18
|
+
* as `AnyPublicKey` that represents any `Unified authentication key`
|
|
13
19
|
*/
|
|
14
20
|
export class Ed25519PublicKey extends PublicKey {
|
|
15
21
|
/**
|
package/src/core/crypto/index.ts
CHANGED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { Hex } from "../hex";
|
|
2
|
+
import { HexInput } from "../../types";
|
|
3
|
+
import { Deserializer } from "../../bcs/deserializer";
|
|
4
|
+
import { Serializer } from "../../bcs/serializer";
|
|
5
|
+
import { AnyPublicKey } from "./anyPublicKey";
|
|
6
|
+
import { AnySignature } from "./anySignature";
|
|
7
|
+
import { PublicKey } from "./asymmetricCrypto";
|
|
8
|
+
|
|
9
|
+
export class MultiKey extends PublicKey {
|
|
10
|
+
/**
|
|
11
|
+
* List of any public keys
|
|
12
|
+
*/
|
|
13
|
+
public readonly publicKeys: AnyPublicKey[];
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The minimum number of valid signatures required, for the number of public keys specified
|
|
17
|
+
*/
|
|
18
|
+
public readonly signaturesRequired: number;
|
|
19
|
+
|
|
20
|
+
constructor(args: { publicKeys: PublicKey[]; signaturesRequired: number }) {
|
|
21
|
+
super();
|
|
22
|
+
const { publicKeys, signaturesRequired } = args;
|
|
23
|
+
|
|
24
|
+
// Validate number of public keys is greater than signature required
|
|
25
|
+
if (signaturesRequired < 1) {
|
|
26
|
+
throw new Error("The number of required signatures needs to be greater then 0");
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Validate number of public keys is greater than signature required
|
|
30
|
+
if (publicKeys.length < signaturesRequired) {
|
|
31
|
+
throw new Error(
|
|
32
|
+
`Provided ${publicKeys.length} public keys is smaller than the ${signaturesRequired} required signatures`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const keys: AnyPublicKey[] = [];
|
|
37
|
+
publicKeys.forEach((publicKey) => {
|
|
38
|
+
if (publicKey instanceof AnyPublicKey) {
|
|
39
|
+
keys.push(publicKey);
|
|
40
|
+
} else {
|
|
41
|
+
// if public key is instance of a legacy authentication key, i.e
|
|
42
|
+
// Legacy Ed25519, convert it into AnyPublicKey
|
|
43
|
+
keys.push(new AnyPublicKey(publicKey));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
this.publicKeys = keys;
|
|
48
|
+
this.signaturesRequired = signaturesRequired;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
toUint8Array(): Uint8Array {
|
|
52
|
+
return this.bcsToBytes();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Create a bitmap that holds the mapping from the original public keys
|
|
57
|
+
* to the signatures passed in
|
|
58
|
+
*
|
|
59
|
+
* @param args.bits array of the index mapping to the matching public keys
|
|
60
|
+
* @returns Uint8array bit map
|
|
61
|
+
*/
|
|
62
|
+
createBitmap(args: { bits: number[] }): Uint8Array {
|
|
63
|
+
const { bits } = args;
|
|
64
|
+
// Bits are read from left to right. e.g. 0b10000000 represents the first bit is set in one byte.
|
|
65
|
+
// The decimal value of 0b10000000 is 128.
|
|
66
|
+
const firstBitInByte = 128;
|
|
67
|
+
const bitmap = new Uint8Array([0, 0, 0, 0]);
|
|
68
|
+
|
|
69
|
+
// Check if duplicates exist in bits
|
|
70
|
+
const dupCheckSet = new Set();
|
|
71
|
+
|
|
72
|
+
bits.forEach((bit: number, idx: number) => {
|
|
73
|
+
if (idx + 1 > this.publicKeys.length) {
|
|
74
|
+
throw new Error(`Signature index ${idx + 1} is out of public keys range, ${this.publicKeys.length}.`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (dupCheckSet.has(bit)) {
|
|
78
|
+
throw new Error(`Duplicate bit ${bit} detected.`);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
dupCheckSet.add(bit);
|
|
82
|
+
|
|
83
|
+
const byteOffset = Math.floor(bit / 8);
|
|
84
|
+
|
|
85
|
+
let byte = bitmap[byteOffset];
|
|
86
|
+
|
|
87
|
+
// eslint-disable-next-line no-bitwise
|
|
88
|
+
byte |= firstBitInByte >> bit % 8;
|
|
89
|
+
|
|
90
|
+
bitmap[byteOffset] = byte;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return bitmap;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Hex string representation the multi key bytes
|
|
98
|
+
*
|
|
99
|
+
* @returns string
|
|
100
|
+
*/
|
|
101
|
+
toString(): string {
|
|
102
|
+
return Hex.fromHexInput(this.toUint8Array()).toString();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// TODO
|
|
106
|
+
// eslint-disable-next-line class-methods-use-this, @typescript-eslint/no-unused-vars
|
|
107
|
+
verifySignature(args: { message: HexInput; signature: AnySignature }): boolean {
|
|
108
|
+
throw new Error("not implemented");
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
serialize(serializer: Serializer): void {
|
|
112
|
+
serializer.serializeVector(this.publicKeys);
|
|
113
|
+
serializer.serializeU8(this.signaturesRequired);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
static deserialize(deserializer: Deserializer): MultiKey {
|
|
117
|
+
const keys = deserializer.deserializeVector(AnyPublicKey);
|
|
118
|
+
const signaturesRequired = deserializer.deserializeU8();
|
|
119
|
+
|
|
120
|
+
return new MultiKey({ publicKeys: keys, signaturesRequired });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -10,6 +10,8 @@ import { HexInput } from "../../types";
|
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Represents the Secp256k1 ecdsa public key
|
|
13
|
+
*
|
|
14
|
+
* Secp256k1 authentication key is represented in the SDK as `AnyPublicKey`.
|
|
13
15
|
*/
|
|
14
16
|
export class Secp256k1PublicKey extends PublicKey {
|
|
15
17
|
// Secp256k1 ecdsa public keys contain a prefix indicating compression and two 32-byte coordinates.
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,7 @@ export * from "./api";
|
|
|
5
5
|
export * from "./bcs";
|
|
6
6
|
export * from "./client";
|
|
7
7
|
export * from "./core";
|
|
8
|
-
export * from "./transactions
|
|
9
|
-
export * from "./transactions/typeTag/typeTag";
|
|
8
|
+
export * from "./transactions";
|
|
10
9
|
export * from "./types";
|
|
11
10
|
export * from "./utils/apiEndpoints";
|
|
12
11
|
export * from "./utils/hdKey";
|
package/src/internal/account.ts
CHANGED
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
LedgerVersion,
|
|
27
27
|
MoveModuleBytecode,
|
|
28
28
|
MoveResource,
|
|
29
|
-
|
|
29
|
+
MoveStructType,
|
|
30
30
|
OrderBy,
|
|
31
31
|
PaginationArgs,
|
|
32
32
|
SigningScheme,
|
|
@@ -164,7 +164,7 @@ export async function getResources(args: {
|
|
|
164
164
|
export async function getResource<T extends {}>(args: {
|
|
165
165
|
aptosConfig: AptosConfig;
|
|
166
166
|
accountAddress: HexInput;
|
|
167
|
-
resourceType:
|
|
167
|
+
resourceType: MoveStructType;
|
|
168
168
|
options?: LedgerVersion;
|
|
169
169
|
}): Promise<T> {
|
|
170
170
|
const { aptosConfig, accountAddress, resourceType, options } = args;
|
|
@@ -503,7 +503,7 @@ export async function deriveAccountFromPrivateKey(args: {
|
|
|
503
503
|
// private key is secp256k1, therefore we know it for sure uses a single signer key
|
|
504
504
|
const authKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: SigningScheme.SingleKey });
|
|
505
505
|
const address = new AccountAddress({ data: authKey.toUint8Array() });
|
|
506
|
-
return Account.
|
|
506
|
+
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
if (privateKey instanceof Ed25519PrivateKey) {
|
|
@@ -518,14 +518,14 @@ export async function deriveAccountFromPrivateKey(args: {
|
|
|
518
518
|
});
|
|
519
519
|
if (isSingleSenderTransactionAuthenticator) {
|
|
520
520
|
const address = new AccountAddress({ data: SingleSenderTransactionAuthenticatorAuthKey.toUint8Array() });
|
|
521
|
-
return Account.
|
|
521
|
+
return Account.fromPrivateKeyAndAddress({ privateKey, address });
|
|
522
522
|
}
|
|
523
523
|
// lookup legacy ed25519
|
|
524
524
|
const legacyAuthKey = AuthenticationKey.fromPublicKeyAndScheme({ publicKey, scheme: SigningScheme.Ed25519 });
|
|
525
525
|
const isLegacyEd25519 = await isAccountExist({ authKey: legacyAuthKey, aptosConfig });
|
|
526
526
|
if (isLegacyEd25519) {
|
|
527
527
|
const address = new AccountAddress({ data: legacyAuthKey.toUint8Array() });
|
|
528
|
-
return Account.
|
|
528
|
+
return Account.fromPrivateKeyAndAddress({ privateKey, address, legacy: true });
|
|
529
529
|
}
|
|
530
530
|
}
|
|
531
531
|
// if we are here, it means we couldn't find an address with an
|
package/src/internal/coin.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import { AptosConfig } from "../api/aptosConfig";
|
|
2
2
|
import { U64 } from "../bcs/serializable/movePrimitives";
|
|
3
3
|
import { Account, AccountAddress } from "../core";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import { HexInput, AnyNumber, MoveResourceType } from "../types";
|
|
4
|
+
import { InputGenerateTransactionOptions, InputSingleSignerTransaction } from "../transactions/types";
|
|
5
|
+
import { HexInput, AnyNumber, MoveStructType } from "../types";
|
|
7
6
|
import { APTOS_COIN } from "../utils/const";
|
|
8
7
|
import { generateTransaction } from "./transactionSubmission";
|
|
8
|
+
import { parseTypeTag } from "../transactions/typeTag/parser";
|
|
9
9
|
|
|
10
10
|
export async function transferCoinTransaction(args: {
|
|
11
11
|
aptosConfig: AptosConfig;
|
|
12
12
|
sender: Account;
|
|
13
13
|
recipient: HexInput;
|
|
14
14
|
amount: AnyNumber;
|
|
15
|
-
coinType?:
|
|
16
|
-
options?:
|
|
17
|
-
}): Promise<
|
|
15
|
+
coinType?: MoveStructType;
|
|
16
|
+
options?: InputGenerateTransactionOptions;
|
|
17
|
+
}): Promise<InputSingleSignerTransaction> {
|
|
18
18
|
const { aptosConfig, sender, recipient, amount, coinType, options } = args;
|
|
19
19
|
const coinStructType = coinType ?? APTOS_COIN;
|
|
20
20
|
const transaction = await generateTransaction({
|
|
@@ -22,11 +22,11 @@ export async function transferCoinTransaction(args: {
|
|
|
22
22
|
sender: sender.accountAddress.toString(),
|
|
23
23
|
data: {
|
|
24
24
|
function: "0x1::aptos_account::transfer_coins",
|
|
25
|
-
typeArguments: [
|
|
25
|
+
typeArguments: [parseTypeTag(coinStructType)],
|
|
26
26
|
functionArguments: [AccountAddress.fromHexInput(recipient), new U64(amount)],
|
|
27
27
|
},
|
|
28
28
|
options,
|
|
29
29
|
});
|
|
30
30
|
|
|
31
|
-
return transaction as
|
|
31
|
+
return transaction as InputSingleSignerTransaction;
|
|
32
32
|
}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { AptosConfig } from "../api/aptosConfig";
|
|
12
12
|
import { MoveString, MoveVector, Bool, U64, U8 } from "../bcs";
|
|
13
13
|
import { Account, Hex } from "../core";
|
|
14
|
-
import {
|
|
14
|
+
import { InputGenerateTransactionOptions, InputSingleSignerTransaction } from "../transactions/types";
|
|
15
15
|
import {
|
|
16
16
|
AnyNumber,
|
|
17
17
|
GetCollectionDataResponse,
|
|
@@ -55,8 +55,8 @@ export async function mintTokenTransaction(args: {
|
|
|
55
55
|
description: string;
|
|
56
56
|
name: string;
|
|
57
57
|
uri: string;
|
|
58
|
-
options?:
|
|
59
|
-
}): Promise<
|
|
58
|
+
options?: InputGenerateTransactionOptions;
|
|
59
|
+
}): Promise<InputSingleSignerTransaction> {
|
|
60
60
|
const { aptosConfig, options, creator } = args;
|
|
61
61
|
const transaction = await generateTransaction({
|
|
62
62
|
aptosConfig,
|
|
@@ -75,7 +75,7 @@ export async function mintTokenTransaction(args: {
|
|
|
75
75
|
},
|
|
76
76
|
options,
|
|
77
77
|
});
|
|
78
|
-
return transaction as
|
|
78
|
+
return transaction as InputSingleSignerTransaction;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
export async function getTokenData(args: {
|
|
@@ -218,9 +218,9 @@ export async function createCollectionTransaction(
|
|
|
218
218
|
description: string;
|
|
219
219
|
name: string;
|
|
220
220
|
uri: string;
|
|
221
|
-
options?:
|
|
221
|
+
options?: InputGenerateTransactionOptions;
|
|
222
222
|
} & CreateCollectionOptions,
|
|
223
|
-
): Promise<
|
|
223
|
+
): Promise<InputSingleSignerTransaction> {
|
|
224
224
|
const { aptosConfig, options, creator } = args;
|
|
225
225
|
const transaction = await generateTransaction({
|
|
226
226
|
aptosConfig,
|
|
@@ -248,7 +248,7 @@ export async function createCollectionTransaction(
|
|
|
248
248
|
},
|
|
249
249
|
options,
|
|
250
250
|
});
|
|
251
|
-
return transaction as
|
|
251
|
+
return transaction as InputSingleSignerTransaction;
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
export async function getCollectionData(args: {
|
package/src/internal/event.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { AptosConfig } from "../api/aptosConfig";
|
|
12
12
|
import { AccountAddress } from "../core";
|
|
13
|
-
import { AnyNumber, GetEventsResponse, HexInput, PaginationArgs,
|
|
13
|
+
import { AnyNumber, GetEventsResponse, HexInput, PaginationArgs, MoveStructType, OrderBy } from "../types";
|
|
14
14
|
import { GetEventsQuery } from "../types/generated/operations";
|
|
15
15
|
import { GetEvents } from "../types/generated/queries";
|
|
16
16
|
import { EventsBoolExp } from "../types/generated/types";
|
|
@@ -35,7 +35,7 @@ export async function getAccountEventsByCreationNumber(args: {
|
|
|
35
35
|
export async function getAccountEventsByEventType(args: {
|
|
36
36
|
aptosConfig: AptosConfig;
|
|
37
37
|
accountAddress: HexInput;
|
|
38
|
-
eventType:
|
|
38
|
+
eventType: MoveStructType;
|
|
39
39
|
options?: {
|
|
40
40
|
pagination?: PaginationArgs;
|
|
41
41
|
orderBy?: OrderBy<GetEventsResponse[0]>;
|
package/src/internal/faucet.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
import { AptosConfig } from "../api/aptosConfig";
|
|
12
12
|
import { postAptosFaucet } from "../client";
|
|
13
13
|
import { AccountAddress } from "../core";
|
|
14
|
-
import { HexInput } from "../types";
|
|
14
|
+
import { HexInput, WaitForTransactionOptions } from "../types";
|
|
15
15
|
import { DEFAULT_TXN_TIMEOUT_SEC } from "../utils/const";
|
|
16
16
|
import { waitForTransaction } from "./transaction";
|
|
17
17
|
|
|
@@ -19,10 +19,10 @@ export async function fundAccount(args: {
|
|
|
19
19
|
aptosConfig: AptosConfig;
|
|
20
20
|
accountAddress: HexInput;
|
|
21
21
|
amount: number;
|
|
22
|
-
|
|
22
|
+
options?: WaitForTransactionOptions;
|
|
23
23
|
}): Promise<string> {
|
|
24
|
-
const { aptosConfig, accountAddress, amount } = args;
|
|
25
|
-
const
|
|
24
|
+
const { aptosConfig, accountAddress, amount, options } = args;
|
|
25
|
+
const timeout = options?.timeoutSecs || DEFAULT_TXN_TIMEOUT_SEC;
|
|
26
26
|
const { data } = await postAptosFaucet<any, { txn_hashes: Array<string> }>({
|
|
27
27
|
aptosConfig,
|
|
28
28
|
path: "fund",
|
|
@@ -38,7 +38,11 @@ export async function fundAccount(args: {
|
|
|
38
38
|
await waitForTransaction({
|
|
39
39
|
aptosConfig,
|
|
40
40
|
transactionHash: txnHash,
|
|
41
|
-
options: {
|
|
41
|
+
options: {
|
|
42
|
+
timeoutSecs: timeout,
|
|
43
|
+
checkSuccess: options?.checkSuccess,
|
|
44
|
+
indexerVersionCheck: options?.indexerVersionCheck,
|
|
45
|
+
},
|
|
42
46
|
});
|
|
43
47
|
|
|
44
48
|
return txnHash;
|