@aptos-labs/ts-sdk 0.0.0
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/LICENSE +201 -0
- package/README.md +144 -0
- package/dist/browser/index.global.js +410 -0
- package/dist/browser/index.global.js.map +1 -0
- package/dist/cjs/index.d.ts +4965 -0
- package/dist/cjs/index.js +4762 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/esm/index.d.ts +4965 -0
- package/dist/esm/index.mjs +4645 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/index.d.ts +1247 -0
- package/dist/types/index.js +151 -0
- package/dist/types/index.js.map +1 -0
- package/package.json +79 -0
- package/src/api/account.ts +360 -0
- package/src/api/aptos.ts +103 -0
- package/src/api/aptosConfig.ts +77 -0
- package/src/api/coin.ts +39 -0
- package/src/api/digitalAsset.ts +192 -0
- package/src/api/event.ts +78 -0
- package/src/api/faucet.ts +30 -0
- package/src/api/fungibleAsset.ts +82 -0
- package/src/api/general.ts +188 -0
- package/src/api/index.ts +5 -0
- package/src/api/staking.ts +58 -0
- package/src/api/transaction.ts +135 -0
- package/src/api/transactionSubmission.ts +168 -0
- package/src/bcs/consts.ts +12 -0
- package/src/bcs/deserializer.ts +248 -0
- package/src/bcs/index.ts +9 -0
- package/src/bcs/serializable/entryFunctionBytes.ts +61 -0
- package/src/bcs/serializable/fixedBytes.ts +65 -0
- package/src/bcs/serializable/movePrimitives.ts +211 -0
- package/src/bcs/serializable/moveStructs.ts +462 -0
- package/src/bcs/serializer.ts +353 -0
- package/src/client/core.ts +106 -0
- package/src/client/get.ts +109 -0
- package/src/client/index.ts +7 -0
- package/src/client/post.ts +90 -0
- package/src/client/types.ts +58 -0
- package/src/core/account.ts +180 -0
- package/src/core/accountAddress.ts +407 -0
- package/src/core/authenticationKey.ts +102 -0
- package/src/core/common.ts +40 -0
- package/src/core/crypto/asymmetricCrypto.ts +77 -0
- package/src/core/crypto/ed25519.ts +224 -0
- package/src/core/crypto/index.ts +7 -0
- package/src/core/crypto/multiEd25519.ts +251 -0
- package/src/core/crypto/secp256k1.ts +227 -0
- package/src/core/hex.ts +177 -0
- package/src/core/index.ts +9 -0
- package/src/index.ts +12 -0
- package/src/internal/account.ts +484 -0
- package/src/internal/coin.ts +32 -0
- package/src/internal/digitalAsset.ts +302 -0
- package/src/internal/event.ts +88 -0
- package/src/internal/faucet.ts +41 -0
- package/src/internal/fungibleAsset.ts +114 -0
- package/src/internal/general.ts +160 -0
- package/src/internal/queries/TokenActivitiesFieldsFragment.graphql +17 -0
- package/src/internal/queries/currentTokenOwnershipFieldsFragment.graphql +45 -0
- package/src/internal/queries/getAccountCoinCount.graphql +7 -0
- package/src/internal/queries/getAccountCoinsData.graphql +32 -0
- package/src/internal/queries/getAccountCollectionsWithOwnedTokens.graphql +33 -0
- package/src/internal/queries/getAccountOwnedObjects.graphql +16 -0
- package/src/internal/queries/getAccountOwnedTokens.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensByTokenData.graphql +11 -0
- package/src/internal/queries/getAccountOwnedTokensFromCollectionAddress.graphql +11 -0
- package/src/internal/queries/getAccountTokensCount.graphql +7 -0
- package/src/internal/queries/getAccountTransactionsCount.graphql +7 -0
- package/src/internal/queries/getChainTopUserTransactions.graphql +5 -0
- package/src/internal/queries/getCollectionData.graphql +20 -0
- package/src/internal/queries/getCurrentFungibleAssetBalances.graphql +17 -0
- package/src/internal/queries/getDelegatedStakingActivities.graphql +12 -0
- package/src/internal/queries/getEvents.graphql +12 -0
- package/src/internal/queries/getFungibleAssetActivities.graphql +20 -0
- package/src/internal/queries/getFungibleAssetMetadata.graphql +16 -0
- package/src/internal/queries/getNumberOfDelegatorsQuery.graphql +9 -0
- package/src/internal/queries/getProcessorStatus.graphql +7 -0
- package/src/internal/queries/getTokenActivity.graphql +11 -0
- package/src/internal/queries/getTokenCurrentOwner.graphql +11 -0
- package/src/internal/queries/getTokenData.graphql +38 -0
- package/src/internal/staking.ts +68 -0
- package/src/internal/transaction.ts +245 -0
- package/src/internal/transactionSubmission.ts +162 -0
- package/src/transactions/authenticator/account.ts +121 -0
- package/src/transactions/authenticator/transaction.ts +222 -0
- package/src/transactions/instances/chainId.ts +26 -0
- package/src/transactions/instances/identifier.ts +28 -0
- package/src/transactions/instances/index.ts +9 -0
- package/src/transactions/instances/moduleId.ts +53 -0
- package/src/transactions/instances/rawTransaction.ts +199 -0
- package/src/transactions/instances/signedTransaction.ts +43 -0
- package/src/transactions/instances/transactionArgument.ts +37 -0
- package/src/transactions/instances/transactionPayload.ts +407 -0
- package/src/transactions/transaction_builder/transaction_builder.ts +541 -0
- package/src/transactions/typeTag/typeTag.ts +487 -0
- package/src/transactions/types.ts +262 -0
- package/src/types/codegen.yaml +33 -0
- package/src/types/generated/operations.ts +623 -0
- package/src/types/generated/queries.ts +737 -0
- package/src/types/generated/types.ts +10387 -0
- package/src/types/index.ts +944 -0
- package/src/types/indexer.ts +93 -0
- package/src/utils/apiEndpoints.ts +36 -0
- package/src/utils/const.ts +51 -0
- package/src/utils/hdKey.ts +113 -0
- package/src/utils/helpers.ts +12 -0
- package/src/utils/memoize.ts +68 -0
- package/src/version.ts +9 -0
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { sha3_256 } from "@noble/hashes/sha3";
|
|
5
|
+
import { secp256k1 } from "@noble/curves/secp256k1";
|
|
6
|
+
import { PrivateKey, PublicKey, Signature } from "./asymmetricCrypto";
|
|
7
|
+
import { Deserializer, Serializer } from "../../bcs";
|
|
8
|
+
import { Hex } from "../hex";
|
|
9
|
+
import { HexInput } from "../../types";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Represents the Secp256k1 ecdsa public key
|
|
13
|
+
*/
|
|
14
|
+
export class Secp256k1PublicKey extends PublicKey {
|
|
15
|
+
// Secp256k1 ecdsa public keys contain a prefix indicating compression and two 32-byte coordinates.
|
|
16
|
+
static readonly LENGTH: number = 65;
|
|
17
|
+
|
|
18
|
+
// Hex value of the public key
|
|
19
|
+
private readonly key: Hex;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create a new PublicKey instance from a Uint8Array or String.
|
|
23
|
+
*
|
|
24
|
+
* @param hexInput A HexInput (string or Uint8Array)
|
|
25
|
+
*/
|
|
26
|
+
constructor(hexInput: HexInput) {
|
|
27
|
+
super();
|
|
28
|
+
|
|
29
|
+
const hex = Hex.fromHexInput(hexInput);
|
|
30
|
+
if (hex.toUint8Array().length !== Secp256k1PublicKey.LENGTH) {
|
|
31
|
+
throw new Error(`PublicKey length should be ${Secp256k1PublicKey.LENGTH}`);
|
|
32
|
+
}
|
|
33
|
+
this.key = hex;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the public key in bytes (Uint8Array).
|
|
38
|
+
*
|
|
39
|
+
* @returns Uint8Array representation of the public key
|
|
40
|
+
*/
|
|
41
|
+
toUint8Array(): Uint8Array {
|
|
42
|
+
return this.key.toUint8Array();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Get the public key as a hex string with the 0x prefix.
|
|
47
|
+
*
|
|
48
|
+
* @returns string representation of the public key
|
|
49
|
+
*/
|
|
50
|
+
toString(): string {
|
|
51
|
+
return this.key.toString();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Verifies a signed data with a public key
|
|
56
|
+
*
|
|
57
|
+
* @param args.message message
|
|
58
|
+
* @param args.signature The signature
|
|
59
|
+
* @returns true if the signature is valid
|
|
60
|
+
*/
|
|
61
|
+
verifySignature(args: { message: HexInput; signature: Secp256k1Signature }): boolean {
|
|
62
|
+
const { message, signature } = args;
|
|
63
|
+
const msgHex = Hex.fromHexInput(message).toUint8Array();
|
|
64
|
+
const sha3Message = sha3_256(msgHex);
|
|
65
|
+
const rawSignature = signature.toUint8Array();
|
|
66
|
+
return secp256k1.verify(rawSignature, sha3Message, this.toUint8Array());
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
serialize(serializer: Serializer): void {
|
|
70
|
+
serializer.serializeBytes(this.key.toUint8Array());
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static deserialize(deserializer: Deserializer): Secp256k1PublicKey {
|
|
74
|
+
const bytes = deserializer.deserializeBytes();
|
|
75
|
+
return new Secp256k1PublicKey(bytes);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* A Secp256k1 ecdsa private key
|
|
81
|
+
*/
|
|
82
|
+
export class Secp256k1PrivateKey extends PrivateKey {
|
|
83
|
+
/**
|
|
84
|
+
* Length of Secp256k1 ecdsa private key
|
|
85
|
+
*/
|
|
86
|
+
static readonly LENGTH: number = 32;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The private key bytes
|
|
90
|
+
* @private
|
|
91
|
+
*/
|
|
92
|
+
private readonly key: Hex;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create a new PrivateKey instance from a Uint8Array or String.
|
|
96
|
+
*
|
|
97
|
+
* @param hexInput A HexInput (string or Uint8Array)
|
|
98
|
+
*/
|
|
99
|
+
constructor(hexInput: HexInput) {
|
|
100
|
+
super();
|
|
101
|
+
|
|
102
|
+
const privateKeyHex = Hex.fromHexInput(hexInput);
|
|
103
|
+
if (privateKeyHex.toUint8Array().length !== Secp256k1PrivateKey.LENGTH) {
|
|
104
|
+
throw new Error(`PrivateKey length should be ${Secp256k1PrivateKey.LENGTH}`);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
this.key = privateKeyHex;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Get the private key in bytes (Uint8Array).
|
|
112
|
+
*
|
|
113
|
+
* @returns
|
|
114
|
+
*/
|
|
115
|
+
toUint8Array(): Uint8Array {
|
|
116
|
+
return this.key.toUint8Array();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Get the private key as a hex string with the 0x prefix.
|
|
121
|
+
*
|
|
122
|
+
* @returns string representation of the private key
|
|
123
|
+
*/
|
|
124
|
+
toString(): string {
|
|
125
|
+
return this.key.toString();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Sign the given message with the private key.
|
|
130
|
+
*
|
|
131
|
+
* @param message in HexInput format
|
|
132
|
+
* @returns Signature
|
|
133
|
+
*/
|
|
134
|
+
sign(message: HexInput): Secp256k1Signature {
|
|
135
|
+
const msgHex = Hex.fromHexInput(message);
|
|
136
|
+
const sha3Message = sha3_256(msgHex.toUint8Array());
|
|
137
|
+
const signature = secp256k1.sign(sha3Message, this.key.toUint8Array());
|
|
138
|
+
return new Secp256k1Signature(signature.toCompactRawBytes());
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
serialize(serializer: Serializer): void {
|
|
142
|
+
serializer.serializeBytes(this.toUint8Array());
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
static deserialize(deserializer: Deserializer): Secp256k1PrivateKey {
|
|
146
|
+
const bytes = deserializer.deserializeBytes();
|
|
147
|
+
return new Secp256k1PrivateKey(bytes);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Generate a new random private key.
|
|
152
|
+
*
|
|
153
|
+
* @returns Secp256k1PrivateKey
|
|
154
|
+
*/
|
|
155
|
+
static generate(): Secp256k1PrivateKey {
|
|
156
|
+
const hexInput = secp256k1.utils.randomPrivateKey();
|
|
157
|
+
return new Secp256k1PrivateKey(hexInput);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Derive the Secp256k1PublicKey from this private key.
|
|
162
|
+
*
|
|
163
|
+
* @returns Secp256k1PublicKey
|
|
164
|
+
*/
|
|
165
|
+
publicKey(): Secp256k1PublicKey {
|
|
166
|
+
const bytes = secp256k1.getPublicKey(this.key.toUint8Array(), false);
|
|
167
|
+
return new Secp256k1PublicKey(bytes);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* A signature of a message signed using an Secp256k1 ecdsa private key
|
|
173
|
+
*/
|
|
174
|
+
export class Secp256k1Signature extends Signature {
|
|
175
|
+
/**
|
|
176
|
+
* Secp256k1 ecdsa signatures are 256-bit.
|
|
177
|
+
*/
|
|
178
|
+
static readonly LENGTH = 64;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The signature bytes
|
|
182
|
+
* @private
|
|
183
|
+
*/
|
|
184
|
+
private readonly data: Hex;
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Create a new Signature instance from a Uint8Array or String.
|
|
188
|
+
*
|
|
189
|
+
* @param hexInput A HexInput (string or Uint8Array)
|
|
190
|
+
*/
|
|
191
|
+
constructor(hexInput: HexInput) {
|
|
192
|
+
super();
|
|
193
|
+
|
|
194
|
+
const hex = Hex.fromHexInput(hexInput);
|
|
195
|
+
if (hex.toUint8Array().length !== Secp256k1Signature.LENGTH) {
|
|
196
|
+
throw new Error(`Signature length should be ${Secp256k1Signature.LENGTH}`);
|
|
197
|
+
}
|
|
198
|
+
this.data = hex;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Get the signature in bytes (Uint8Array).
|
|
203
|
+
*
|
|
204
|
+
* @returns Uint8Array representation of the signature
|
|
205
|
+
*/
|
|
206
|
+
toUint8Array(): Uint8Array {
|
|
207
|
+
return this.data.toUint8Array();
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/**
|
|
211
|
+
* Get the signature as a hex string with the 0x prefix.
|
|
212
|
+
*
|
|
213
|
+
* @returns string representation of the signature
|
|
214
|
+
*/
|
|
215
|
+
toString(): string {
|
|
216
|
+
return this.data.toString();
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
serialize(serializer: Serializer): void {
|
|
220
|
+
serializer.serializeBytes(this.data.toUint8Array());
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
static deserialize(deserializer: Deserializer): Secp256k1Signature {
|
|
224
|
+
const hex = deserializer.deserializeBytes();
|
|
225
|
+
return new Secp256k1Signature(hex);
|
|
226
|
+
}
|
|
227
|
+
}
|
package/src/core/hex.ts
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { bytesToHex, hexToBytes } from "@noble/hashes/utils";
|
|
5
|
+
import { ParsingError, ParsingResult } from "./common";
|
|
6
|
+
import { HexInput } from "../types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* This enum is used to explain why parsing might have failed.
|
|
10
|
+
*/
|
|
11
|
+
export enum HexInvalidReason {
|
|
12
|
+
TOO_SHORT = "too_short",
|
|
13
|
+
INVALID_LENGTH = "invalid_length",
|
|
14
|
+
INVALID_HEX_CHARS = "invalid_hex_chars",
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* NOTE: Do not use this class when working with account addresses, use AccountAddress.
|
|
19
|
+
*
|
|
20
|
+
* NOTE: When accepting hex data as input to a function, prefer to accept HexInput and
|
|
21
|
+
* then use the static helper methods of this class to convert it into the desired
|
|
22
|
+
* format. This enables the greatest flexibility for the developer.
|
|
23
|
+
*
|
|
24
|
+
* Hex is a helper class for working with hex data. Hex data, when represented as a
|
|
25
|
+
* string, generally looks like this, for example: 0xaabbcc, 45cd32, etc.
|
|
26
|
+
*
|
|
27
|
+
* You might use this class like this:
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* getTransactionByHash(txnHash: HexInput): Promise<Transaction> {
|
|
31
|
+
* const txnHashString = Hex.fromHexInput(txnHash).toString();
|
|
32
|
+
* return await getTransactionByHashInner(txnHashString);
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* This call to `Hex.fromHexInput().toString()` converts the HexInput to a hex string
|
|
37
|
+
* with a leading 0x prefix, regardless of what the input format was.
|
|
38
|
+
*
|
|
39
|
+
* These are some other ways to chain the functions together:
|
|
40
|
+
* - `Hex.fromString({ hexInput: "0x1f" }).toUint8Array()`
|
|
41
|
+
* - `new Hex([1, 3]).toStringWithoutPrefix()`
|
|
42
|
+
*/
|
|
43
|
+
export class Hex {
|
|
44
|
+
private readonly data: Uint8Array;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a new Hex instance from a Uint8Array.
|
|
48
|
+
*
|
|
49
|
+
* @param data Uint8Array
|
|
50
|
+
*/
|
|
51
|
+
constructor(data: Uint8Array) {
|
|
52
|
+
this.data = data;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ===
|
|
56
|
+
// Methods for representing an instance of Hex as other types.
|
|
57
|
+
// ===
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get the inner hex data. The inner data is already a Uint8Array so no conversion
|
|
61
|
+
* is taking place here, it just returns the inner data.
|
|
62
|
+
*
|
|
63
|
+
* @returns Hex data as Uint8Array
|
|
64
|
+
*/
|
|
65
|
+
toUint8Array(): Uint8Array {
|
|
66
|
+
return this.data;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Get the hex data as a string without the 0x prefix.
|
|
71
|
+
*
|
|
72
|
+
* @returns Hex string without 0x prefix
|
|
73
|
+
*/
|
|
74
|
+
toStringWithoutPrefix(): string {
|
|
75
|
+
return bytesToHex(this.data);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Get the hex data as a string with the 0x prefix.
|
|
80
|
+
*
|
|
81
|
+
* @returns Hex string with 0x prefix
|
|
82
|
+
*/
|
|
83
|
+
toString(): string {
|
|
84
|
+
return `0x${this.toStringWithoutPrefix()}`;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// ===
|
|
88
|
+
// Methods for creating an instance of Hex from other types.
|
|
89
|
+
// ===
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Static method to convert a hex string to Hex
|
|
93
|
+
*
|
|
94
|
+
* @param str A hex string, with or without the 0x prefix
|
|
95
|
+
*
|
|
96
|
+
* @returns Hex
|
|
97
|
+
*/
|
|
98
|
+
static fromString(str: string): Hex {
|
|
99
|
+
let input = str;
|
|
100
|
+
|
|
101
|
+
if (input.startsWith("0x")) {
|
|
102
|
+
input = input.slice(2);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (input.length === 0) {
|
|
106
|
+
throw new ParsingError(
|
|
107
|
+
"Hex string is too short, must be at least 1 char long, excluding the optional leading 0x.",
|
|
108
|
+
HexInvalidReason.TOO_SHORT,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (input.length % 2 !== 0) {
|
|
113
|
+
throw new ParsingError("Hex string must be an even number of hex characters.", HexInvalidReason.INVALID_LENGTH);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
try {
|
|
117
|
+
return new Hex(hexToBytes(input));
|
|
118
|
+
} catch (e) {
|
|
119
|
+
const error = e as Error;
|
|
120
|
+
throw new ParsingError(
|
|
121
|
+
`Hex string contains invalid hex characters: ${error.message}`,
|
|
122
|
+
HexInvalidReason.INVALID_HEX_CHARS,
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Static method to convert an instance of HexInput to Hex
|
|
129
|
+
*
|
|
130
|
+
* @param hexInput A HexInput (string or Uint8Array)
|
|
131
|
+
*
|
|
132
|
+
* @returns Hex
|
|
133
|
+
*/
|
|
134
|
+
static fromHexInput(hexInput: HexInput): Hex {
|
|
135
|
+
if (hexInput instanceof Uint8Array) return new Hex(hexInput);
|
|
136
|
+
return Hex.fromString(hexInput);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// ===
|
|
140
|
+
// Methods for checking validity.
|
|
141
|
+
// ===
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Check if the string is valid hex.
|
|
145
|
+
*
|
|
146
|
+
* @param str A hex string representing byte data.
|
|
147
|
+
*
|
|
148
|
+
* @returns valid = true if the string is valid, false if not. If the string is not
|
|
149
|
+
* valid, invalidReason and invalidReasonMessage will be set explaining why it is
|
|
150
|
+
* invalid.
|
|
151
|
+
*/
|
|
152
|
+
static isValid(str: string): ParsingResult<HexInvalidReason> {
|
|
153
|
+
try {
|
|
154
|
+
Hex.fromString(str);
|
|
155
|
+
return { valid: true };
|
|
156
|
+
} catch (e) {
|
|
157
|
+
const error = e as ParsingError<HexInvalidReason>;
|
|
158
|
+
return {
|
|
159
|
+
valid: false,
|
|
160
|
+
invalidReason: error.invalidReason,
|
|
161
|
+
invalidReasonMessage: error.message,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Return whether Hex instances are equal. Hex instances are considered equal if
|
|
168
|
+
* their underlying byte data is identical.
|
|
169
|
+
*
|
|
170
|
+
* @param other The Hex instance to compare to.
|
|
171
|
+
* @returns true if the Hex instances are equal, false if not.
|
|
172
|
+
*/
|
|
173
|
+
equals(other: Hex): boolean {
|
|
174
|
+
if (this.data.length !== other.data.length) return false;
|
|
175
|
+
return this.data.every((value, index) => value === other.data[index]);
|
|
176
|
+
}
|
|
177
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright © Aptos Foundation
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export * from "./api";
|
|
5
|
+
export * from "./bcs";
|
|
6
|
+
export * from "./client";
|
|
7
|
+
export * from "./core";
|
|
8
|
+
export * from "./transactions/types";
|
|
9
|
+
export * from "./transactions/typeTag/typeTag";
|
|
10
|
+
export * from "./types";
|
|
11
|
+
export * from "./utils/apiEndpoints";
|
|
12
|
+
export * from "./utils/hdKey";
|