@dynamic-labs/aptos 4.44.0 → 4.44.1

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/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
1
 
2
+ ### [4.44.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.44.0...v4.44.1) (2025-11-06)
3
+
4
+
5
+ ### Bug Fixes
6
+
7
+ * better handling of null and undefined values in StorageService ([#9842](https://github.com/dynamic-labs/dynamic-auth/issues/9842)) ([f959943](https://github.com/dynamic-labs/dynamic-auth/commit/f95994337ea938e7e88d0126053b03ad69340a6a))
8
+
2
9
  ## [4.44.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.43.0...v4.44.0) (2025-11-05)
3
10
 
4
11
 
package/package.cjs CHANGED
@@ -3,6 +3,6 @@
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
5
5
 
6
- var version = "4.44.0";
6
+ var version = "4.44.1";
7
7
 
8
8
  exports.version = version;
package/package.js CHANGED
@@ -1,4 +1,4 @@
1
1
  'use client'
2
- var version = "4.44.0";
2
+ var version = "4.44.1";
3
3
 
4
4
  export { version };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamic-labs/aptos",
3
- "version": "4.44.0",
3
+ "version": "4.44.1",
4
4
  "description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
5
5
  "author": "Dynamic Labs, Inc.",
6
6
  "license": "MIT",
@@ -20,14 +20,14 @@
20
20
  "dependencies": {
21
21
  "@aptos-labs/ts-sdk": "5.1.1",
22
22
  "@aptos-labs/wallet-standard": "0.5.2",
23
- "@dynamic-labs/assert-package-version": "4.44.0",
23
+ "@dynamic-labs/assert-package-version": "4.44.1",
24
24
  "@wallet-standard/core": "1.1.1",
25
25
  "@wallet-standard/features": "1.0.3",
26
- "@dynamic-labs/logger": "4.44.0",
27
- "@dynamic-labs/types": "4.44.0",
28
- "@dynamic-labs/utils": "4.44.0",
29
- "@dynamic-labs/wallet-book": "4.44.0",
30
- "@dynamic-labs/wallet-connector-core": "4.44.0"
26
+ "@dynamic-labs/logger": "4.44.1",
27
+ "@dynamic-labs/types": "4.44.1",
28
+ "@dynamic-labs/utils": "4.44.1",
29
+ "@dynamic-labs/wallet-book": "4.44.1",
30
+ "@dynamic-labs/wallet-connector-core": "4.44.1"
31
31
  },
32
32
  "peerDependencies": {}
33
33
  }
@@ -12,6 +12,7 @@ var assertProvider = require('../../utils/assertProvider/assertProvider.cjs');
12
12
  var invokeWalletMethod = require('../../utils/invokeWalletMethod/invokeWalletMethod.cjs');
13
13
  var parseConnectionResult = require('../../utils/parseConnectionResult/parseConnectionResult.cjs');
14
14
  var parseTransactionResponse = require('../../utils/parseTransactionResponse/parseTransactionResponse.cjs');
15
+ var AptosUiTransaction = require('../../utils/AptosUiTransaction/AptosUiTransaction.cjs');
15
16
  var AptosWallet = require('../../wallet/AptosWallet.cjs');
16
17
 
17
18
  /**
@@ -45,10 +46,10 @@ class AptosWalletConnector extends walletConnectorCore.WalletConnectorBase {
45
46
  assertProvider.assertProvider(provider);
46
47
  const network = yield invokeWalletMethod.invokeWalletMethod(provider, 'aptos:network', 'network');
47
48
  if (network === null || network === void 0 ? void 0 : network.chainId) {
48
- return network.chainId;
49
+ return network.chainId.toString();
49
50
  }
50
51
  // default to mainnet
51
- return 1;
52
+ return '1';
52
53
  });
53
54
  }
54
55
  /**
@@ -217,6 +218,32 @@ class AptosWalletConnector extends walletConnectorCore.WalletConnectorBase {
217
218
  }
218
219
  });
219
220
  }
221
+ /**
222
+ * Function used to create transactions in the SDK interface
223
+ *
224
+ * @param from - The sender's address
225
+ * @returns A new AptosUiTransaction instance
226
+ */
227
+ createUiTransaction(from) {
228
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
229
+ yield this.validateActiveWallet(from);
230
+ const aptosClient = yield this.getAptosClient();
231
+ if (!aptosClient) {
232
+ throw new utils.DynamicError('No Aptos client available');
233
+ }
234
+ return new AptosUiTransaction.AptosUiTransaction({
235
+ client: aptosClient,
236
+ from,
237
+ onSubmit: (transaction) => _tslib.__awaiter(this, void 0, void 0, function* () {
238
+ if (!transaction) {
239
+ throw new utils.DynamicError('Transaction must be provided');
240
+ }
241
+ const result = yield this.signAndSubmitTransaction(transaction);
242
+ return result;
243
+ }),
244
+ });
245
+ });
246
+ }
220
247
  }
221
248
 
222
249
  exports.AptosWalletConnector = AptosWalletConnector;
@@ -3,7 +3,7 @@ import { Aptos, InputGenerateTransactionPayloadData } from '@aptos-labs/ts-sdk';
3
3
  import type { AccountInfo, AptosSignMessageInput, AptosSignMessageOutput, NetworkInfo, UserResponse } from '@aptos-labs/wallet-standard';
4
4
  import { Logger } from '@dynamic-labs/logger';
5
5
  import { type Chain, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
6
- import { GenericNetwork } from '@dynamic-labs/types';
6
+ import { GenericNetwork, IUITransaction } from '@dynamic-labs/types';
7
7
  import type { AptosWalletConnectorProps, IAptosProvider } from '../../types';
8
8
  import { AptosWallet } from '../../wallet/AptosWallet';
9
9
  /**
@@ -33,7 +33,7 @@ export declare abstract class AptosWalletConnector extends WalletConnectorBase<t
33
33
  */
34
34
  abstract getProvider(): IAptosProvider | undefined;
35
35
  getEnabledNetworks(): GenericNetwork[];
36
- getNetwork(): Promise<number | undefined>;
36
+ getNetwork(): Promise<string | undefined>;
37
37
  /**
38
38
  * Connects to the Aptos wallet.
39
39
  */
@@ -72,4 +72,11 @@ export declare abstract class AptosWalletConnector extends WalletConnectorBase<t
72
72
  * Gets the Aptos client instance configured for the current network.
73
73
  */
74
74
  getAptosClient(): Promise<Aptos | undefined>;
75
+ /**
76
+ * Function used to create transactions in the SDK interface
77
+ *
78
+ * @param from - The sender's address
79
+ * @returns A new AptosUiTransaction instance
80
+ */
81
+ createUiTransaction(from: string): Promise<IUITransaction>;
75
82
  }
@@ -8,6 +8,7 @@ import { assertProvider } from '../../utils/assertProvider/assertProvider.js';
8
8
  import { invokeWalletMethod } from '../../utils/invokeWalletMethod/invokeWalletMethod.js';
9
9
  import { parseConnectionResult } from '../../utils/parseConnectionResult/parseConnectionResult.js';
10
10
  import { parseTransactionResponse } from '../../utils/parseTransactionResponse/parseTransactionResponse.js';
11
+ import { AptosUiTransaction } from '../../utils/AptosUiTransaction/AptosUiTransaction.js';
11
12
  import { AptosWallet } from '../../wallet/AptosWallet.js';
12
13
 
13
14
  /**
@@ -41,10 +42,10 @@ class AptosWalletConnector extends WalletConnectorBase {
41
42
  assertProvider(provider);
42
43
  const network = yield invokeWalletMethod(provider, 'aptos:network', 'network');
43
44
  if (network === null || network === void 0 ? void 0 : network.chainId) {
44
- return network.chainId;
45
+ return network.chainId.toString();
45
46
  }
46
47
  // default to mainnet
47
- return 1;
48
+ return '1';
48
49
  });
49
50
  }
50
51
  /**
@@ -213,6 +214,32 @@ class AptosWalletConnector extends WalletConnectorBase {
213
214
  }
214
215
  });
215
216
  }
217
+ /**
218
+ * Function used to create transactions in the SDK interface
219
+ *
220
+ * @param from - The sender's address
221
+ * @returns A new AptosUiTransaction instance
222
+ */
223
+ createUiTransaction(from) {
224
+ return __awaiter(this, void 0, void 0, function* () {
225
+ yield this.validateActiveWallet(from);
226
+ const aptosClient = yield this.getAptosClient();
227
+ if (!aptosClient) {
228
+ throw new DynamicError('No Aptos client available');
229
+ }
230
+ return new AptosUiTransaction({
231
+ client: aptosClient,
232
+ from,
233
+ onSubmit: (transaction) => __awaiter(this, void 0, void 0, function* () {
234
+ if (!transaction) {
235
+ throw new DynamicError('Transaction must be provided');
236
+ }
237
+ const result = yield this.signAndSubmitTransaction(transaction);
238
+ return result;
239
+ }),
240
+ });
241
+ });
242
+ }
216
243
  }
217
244
 
218
245
  export { AptosWalletConnector };
package/src/index.cjs CHANGED
@@ -14,6 +14,7 @@ var AptosWalletConnector = require('./connectors/AptosWalletConnector/AptosWalle
14
14
  var fetchInjectedWalletConnectors = require('./injected/fetchInjectedWalletConnectors.cjs');
15
15
  var AptosWallet = require('./wallet/AptosWallet.cjs');
16
16
  var assertProvider = require('./utils/assertProvider/assertProvider.cjs');
17
+ var AptosUiTransaction = require('./utils/AptosUiTransaction/AptosUiTransaction.cjs');
17
18
  var getWalletStandardWallets = require('./utils/getWalletStandardWallets/getWalletStandardWallets.cjs');
18
19
  var invokeWalletMethod = require('./utils/invokeWalletMethod/invokeWalletMethod.cjs');
19
20
  var isWalletWithRequiredFeatureSet = require('./utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.cjs');
@@ -32,6 +33,7 @@ const AptosWalletConnectors = (props) => [
32
33
  exports.AptosWalletConnector = AptosWalletConnector.AptosWalletConnector;
33
34
  exports.AptosWallet = AptosWallet.AptosWallet;
34
35
  exports.assertProvider = assertProvider.assertProvider;
36
+ exports.AptosUiTransaction = AptosUiTransaction.AptosUiTransaction;
35
37
  exports.getWalletStandardWallets = getWalletStandardWallets.getWalletStandardWallets;
36
38
  exports.invokeWalletMethod = invokeWalletMethod.invokeWalletMethod;
37
39
  exports.isWalletWithRequiredFeatureSet = isWalletWithRequiredFeatureSet.isWalletWithRequiredFeatureSet;
package/src/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export { AptosWallet } from './wallet';
2
2
  export { AptosWalletConnector } from './connectors/AptosWalletConnector';
3
3
  export type { IAptosProvider, AptosConnectionResult, AptosSendBalanceProps, AptosWalletConnectorProps, AptosFeatureName, AptosMethodName, } from './types';
4
4
  export { assertProvider } from './utils/assertProvider';
5
+ export { AptosUiTransaction } from './utils/AptosUiTransaction';
5
6
  export { getWalletStandardWallets } from './utils/getWalletStandardWallets';
6
7
  export { invokeWalletMethod } from './utils/invokeWalletMethod';
7
8
  export { isWalletWithRequiredFeatureSet } from './utils/isWalletWithRequiredFeatureSet';
package/src/index.js CHANGED
@@ -10,6 +10,7 @@ export { AptosWalletConnector } from './connectors/AptosWalletConnector/AptosWal
10
10
  import { fetchInjectedWalletConnectors } from './injected/fetchInjectedWalletConnectors.js';
11
11
  export { AptosWallet } from './wallet/AptosWallet.js';
12
12
  export { assertProvider } from './utils/assertProvider/assertProvider.js';
13
+ export { AptosUiTransaction } from './utils/AptosUiTransaction/AptosUiTransaction.js';
13
14
  export { getWalletStandardWallets } from './utils/getWalletStandardWallets/getWalletStandardWallets.js';
14
15
  export { invokeWalletMethod } from './utils/invokeWalletMethod/invokeWalletMethod.js';
15
16
  export { isWalletWithRequiredFeatureSet } from './utils/isWalletWithRequiredFeatureSet/isWalletWithRequiredFeatureSet.js';
@@ -0,0 +1,189 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ var _tslib = require('../../../_virtual/_tslib.cjs');
7
+ var utils = require('@dynamic-labs/utils');
8
+ var constants = require('../constants/constants.cjs');
9
+
10
+ /**
11
+ * Aptos UI Transaction class for managing Aptos transactions in the UI.
12
+ *
13
+ * This class implements the IUITransaction interface and provides Aptos-specific
14
+ * functionality for creating, formatting, and submitting transactions.
15
+ */
16
+ class AptosUiTransaction {
17
+ constructor({ onSubmit, from, client }) {
18
+ this.chain = 'APTOS';
19
+ this.data = undefined;
20
+ this.fee = { gas: undefined };
21
+ /**
22
+ * Formats a non-native token value back to a string
23
+ *
24
+ * @param value - The value as bigint
25
+ * @param decimals - The number of decimals for the token
26
+ * @returns The formatted amount as string
27
+ */
28
+ this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
29
+ this.from = from;
30
+ this.onSubmit = onSubmit;
31
+ this.client = client;
32
+ }
33
+ /**
34
+ * Fetches the gas fee for the transaction.
35
+ *
36
+ * Note: Aptos gas fees are typically fixed or very low, so we set a default
37
+ * estimate. In the future, this could be enhanced with actual gas estimation.
38
+ *
39
+ * @returns The gas fee for the transaction
40
+ */
41
+ fetchFee() {
42
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
43
+ if (this.fee.gas)
44
+ return;
45
+ const transaction = yield this.createTransactionSafe();
46
+ if (!transaction) {
47
+ throw new Error('Could not create a valid Aptos transaction, check your address and value');
48
+ }
49
+ // Aptos has a simple gas model. For now, we'll use a default estimate.
50
+ // In the future, this could use the client to simulate the transaction.
51
+ // Typical Aptos transactions cost around 100-1000 octas (0.0000001 - 0.000001 APT)
52
+ // We'll use a conservative estimate of 1000 octas
53
+ this.fee.gas = BigInt(1000);
54
+ });
55
+ }
56
+ isGasSponsored() {
57
+ return false;
58
+ }
59
+ /**
60
+ * Parses a string amount into bigint octas (APT smallest unit, 1e8)
61
+ *
62
+ * @param input - The amount as a string (e.g., "1.5")
63
+ * @returns The amount in octas as bigint
64
+ */
65
+ parse(input) {
66
+ const floatValue = parseFloat(input);
67
+ const octas = Math.round(floatValue * constants.OCTAS_PER_APT);
68
+ return BigInt(octas);
69
+ }
70
+ /**
71
+ * Parses a non-native token amount with custom decimals
72
+ *
73
+ * @param input - The amount as a string
74
+ * @param decimals - The number of decimals for the token
75
+ * @returns The amount as bigint
76
+ */
77
+ parseNonNativeToken(input, decimals) {
78
+ return BigInt(Math.floor(Number(input) * Math.pow(10, decimals)));
79
+ }
80
+ /**
81
+ * Formats a bigint value (in octas) to a human-readable APT string
82
+ *
83
+ * @param value - The value in octas
84
+ * @param options - Formatting options including precision
85
+ * @returns The formatted amount as string
86
+ */
87
+ format(value, { precision } = {}) {
88
+ const aptValue = Number(value) / constants.OCTAS_PER_APT;
89
+ const decimalString = aptValue.toLocaleString('fullwide', {
90
+ maximumFractionDigits: 20,
91
+ minimumFractionDigits: 0,
92
+ useGrouping: false,
93
+ });
94
+ return utils.formatNumberText(decimalString, { precision });
95
+ }
96
+ /**
97
+ * Submits the transaction by creating it and calling onSubmit
98
+ *
99
+ * @returns The transaction hash from onSubmit
100
+ */
101
+ submit() {
102
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
103
+ const sendTransaction = (yield this.createTransaction());
104
+ return this.onSubmit(sendTransaction);
105
+ });
106
+ }
107
+ /**
108
+ * Gets the balance of the sender's account in octas
109
+ *
110
+ * @returns The balance as bigint in octas
111
+ */
112
+ getBalance() {
113
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
114
+ const balance = yield this.client.getBalance({
115
+ accountAddress: this.from,
116
+ // APT coin type
117
+ asset: '0x1::aptos_coin::AptosCoin',
118
+ });
119
+ // Balance comes back as a number in octas (1e8 octas = 1 APT)
120
+ return BigInt(Math.floor(balance));
121
+ });
122
+ }
123
+ /**
124
+ * Validates that an address is a valid Aptos address format
125
+ *
126
+ * Aptos addresses are 64-character hex strings prefixed with 0x (66 chars total)
127
+ *
128
+ * @param address - The address to validate
129
+ * @returns true if the address format is valid
130
+ */
131
+ validateAddressFormat(address) {
132
+ if (address === 'dyn_send_transaction.multiple_recipients') {
133
+ return true;
134
+ }
135
+ // Aptos addresses are 0x followed by 64 hex characters
136
+ return /^0x[0-9a-fA-F]{64}$/.test(address);
137
+ }
138
+ /**
139
+ * Creates a transaction payload for sending APT or tokens
140
+ *
141
+ * @returns The transaction payload or undefined if invalid
142
+ */
143
+ createTransaction() {
144
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
145
+ const { value, to, nonNativeAddress, nonNativeValue } = this;
146
+ if (!to) {
147
+ throw new Error('Destination is required');
148
+ }
149
+ if (!value && !nonNativeValue) {
150
+ return undefined;
151
+ }
152
+ // Create the transaction payload
153
+ if (nonNativeAddress && nonNativeValue) {
154
+ // Transfer non-native token
155
+ return {
156
+ function: '0x1::coin::transfer',
157
+ functionArguments: [to, nonNativeValue],
158
+ typeArguments: [nonNativeAddress],
159
+ };
160
+ }
161
+ if (value) {
162
+ // Transfer native APT
163
+ return {
164
+ function: '0x1::coin::transfer',
165
+ functionArguments: [to, value],
166
+ typeArguments: ['0x1::aptos_coin::AptosCoin'],
167
+ };
168
+ }
169
+ return undefined;
170
+ });
171
+ }
172
+ /**
173
+ * Safely creates a transaction, returning undefined on error
174
+ *
175
+ * @returns The transaction payload or undefined if creation fails
176
+ */
177
+ createTransactionSafe() {
178
+ return _tslib.__awaiter(this, void 0, void 0, function* () {
179
+ try {
180
+ return yield this.createTransaction();
181
+ }
182
+ catch (error) {
183
+ return undefined;
184
+ }
185
+ });
186
+ }
187
+ }
188
+
189
+ exports.AptosUiTransaction = AptosUiTransaction;
@@ -0,0 +1,110 @@
1
+ import type { InputGenerateTransactionPayloadData } from '@aptos-labs/ts-sdk';
2
+ import { Aptos } from '@aptos-labs/ts-sdk';
3
+ import { IUITransaction, IUITransactionFormatOptions } from '@dynamic-labs/types';
4
+ type AptosUiTransactionProps = {
5
+ /** Aptos Address of the sender */
6
+ from: string;
7
+ /** The [Aptos] client instance, needed to estimate gas fees and get balance */
8
+ client: Aptos;
9
+ /** The function to call when the transaction is submitted */
10
+ onSubmit: (transaction?: InputGenerateTransactionPayloadData) => Promise<any>;
11
+ };
12
+ /**
13
+ * Aptos UI Transaction class for managing Aptos transactions in the UI.
14
+ *
15
+ * This class implements the IUITransaction interface and provides Aptos-specific
16
+ * functionality for creating, formatting, and submitting transactions.
17
+ */
18
+ export declare class AptosUiTransaction implements IUITransaction {
19
+ to: string | undefined;
20
+ from: string;
21
+ value: bigint | undefined;
22
+ chain: string;
23
+ receipt: string | undefined;
24
+ data: undefined;
25
+ fee: {
26
+ gas: bigint | undefined;
27
+ };
28
+ nonNativeAddress?: string;
29
+ nonNativeDecimal?: number;
30
+ nonNativeValue?: bigint;
31
+ nativePrice?: number;
32
+ private onSubmit;
33
+ private client;
34
+ constructor({ onSubmit, from, client }: AptosUiTransactionProps);
35
+ /**
36
+ * Fetches the gas fee for the transaction.
37
+ *
38
+ * Note: Aptos gas fees are typically fixed or very low, so we set a default
39
+ * estimate. In the future, this could be enhanced with actual gas estimation.
40
+ *
41
+ * @returns The gas fee for the transaction
42
+ */
43
+ fetchFee(): Promise<void>;
44
+ isGasSponsored(): boolean;
45
+ /**
46
+ * Parses a string amount into bigint octas (APT smallest unit, 1e8)
47
+ *
48
+ * @param input - The amount as a string (e.g., "1.5")
49
+ * @returns The amount in octas as bigint
50
+ */
51
+ parse(input: string): bigint;
52
+ /**
53
+ * Parses a non-native token amount with custom decimals
54
+ *
55
+ * @param input - The amount as a string
56
+ * @param decimals - The number of decimals for the token
57
+ * @returns The amount as bigint
58
+ */
59
+ parseNonNativeToken(input: string, decimals: number): bigint;
60
+ /**
61
+ * Formats a non-native token value back to a string
62
+ *
63
+ * @param value - The value as bigint
64
+ * @param decimals - The number of decimals for the token
65
+ * @returns The formatted amount as string
66
+ */
67
+ formatNonNativeToken: (value: bigint, decimals: number) => string;
68
+ /**
69
+ * Formats a bigint value (in octas) to a human-readable APT string
70
+ *
71
+ * @param value - The value in octas
72
+ * @param options - Formatting options including precision
73
+ * @returns The formatted amount as string
74
+ */
75
+ format(value: bigint, { precision }?: IUITransactionFormatOptions): string;
76
+ /**
77
+ * Submits the transaction by creating it and calling onSubmit
78
+ *
79
+ * @returns The transaction hash from onSubmit
80
+ */
81
+ submit(): Promise<any>;
82
+ /**
83
+ * Gets the balance of the sender's account in octas
84
+ *
85
+ * @returns The balance as bigint in octas
86
+ */
87
+ getBalance(): Promise<bigint>;
88
+ /**
89
+ * Validates that an address is a valid Aptos address format
90
+ *
91
+ * Aptos addresses are 64-character hex strings prefixed with 0x (66 chars total)
92
+ *
93
+ * @param address - The address to validate
94
+ * @returns true if the address format is valid
95
+ */
96
+ validateAddressFormat(address: string): boolean;
97
+ /**
98
+ * Creates a transaction payload for sending APT or tokens
99
+ *
100
+ * @returns The transaction payload or undefined if invalid
101
+ */
102
+ private createTransaction;
103
+ /**
104
+ * Safely creates a transaction, returning undefined on error
105
+ *
106
+ * @returns The transaction payload or undefined if creation fails
107
+ */
108
+ private createTransactionSafe;
109
+ }
110
+ export {};
@@ -0,0 +1,185 @@
1
+ 'use client'
2
+ import { __awaiter } from '../../../_virtual/_tslib.js';
3
+ import { formatNumberText } from '@dynamic-labs/utils';
4
+ import { OCTAS_PER_APT } from '../constants/constants.js';
5
+
6
+ /**
7
+ * Aptos UI Transaction class for managing Aptos transactions in the UI.
8
+ *
9
+ * This class implements the IUITransaction interface and provides Aptos-specific
10
+ * functionality for creating, formatting, and submitting transactions.
11
+ */
12
+ class AptosUiTransaction {
13
+ constructor({ onSubmit, from, client }) {
14
+ this.chain = 'APTOS';
15
+ this.data = undefined;
16
+ this.fee = { gas: undefined };
17
+ /**
18
+ * Formats a non-native token value back to a string
19
+ *
20
+ * @param value - The value as bigint
21
+ * @param decimals - The number of decimals for the token
22
+ * @returns The formatted amount as string
23
+ */
24
+ this.formatNonNativeToken = (value, decimals) => (Number(value) / Number(Math.pow(10, decimals))).toString();
25
+ this.from = from;
26
+ this.onSubmit = onSubmit;
27
+ this.client = client;
28
+ }
29
+ /**
30
+ * Fetches the gas fee for the transaction.
31
+ *
32
+ * Note: Aptos gas fees are typically fixed or very low, so we set a default
33
+ * estimate. In the future, this could be enhanced with actual gas estimation.
34
+ *
35
+ * @returns The gas fee for the transaction
36
+ */
37
+ fetchFee() {
38
+ return __awaiter(this, void 0, void 0, function* () {
39
+ if (this.fee.gas)
40
+ return;
41
+ const transaction = yield this.createTransactionSafe();
42
+ if (!transaction) {
43
+ throw new Error('Could not create a valid Aptos transaction, check your address and value');
44
+ }
45
+ // Aptos has a simple gas model. For now, we'll use a default estimate.
46
+ // In the future, this could use the client to simulate the transaction.
47
+ // Typical Aptos transactions cost around 100-1000 octas (0.0000001 - 0.000001 APT)
48
+ // We'll use a conservative estimate of 1000 octas
49
+ this.fee.gas = BigInt(1000);
50
+ });
51
+ }
52
+ isGasSponsored() {
53
+ return false;
54
+ }
55
+ /**
56
+ * Parses a string amount into bigint octas (APT smallest unit, 1e8)
57
+ *
58
+ * @param input - The amount as a string (e.g., "1.5")
59
+ * @returns The amount in octas as bigint
60
+ */
61
+ parse(input) {
62
+ const floatValue = parseFloat(input);
63
+ const octas = Math.round(floatValue * OCTAS_PER_APT);
64
+ return BigInt(octas);
65
+ }
66
+ /**
67
+ * Parses a non-native token amount with custom decimals
68
+ *
69
+ * @param input - The amount as a string
70
+ * @param decimals - The number of decimals for the token
71
+ * @returns The amount as bigint
72
+ */
73
+ parseNonNativeToken(input, decimals) {
74
+ return BigInt(Math.floor(Number(input) * Math.pow(10, decimals)));
75
+ }
76
+ /**
77
+ * Formats a bigint value (in octas) to a human-readable APT string
78
+ *
79
+ * @param value - The value in octas
80
+ * @param options - Formatting options including precision
81
+ * @returns The formatted amount as string
82
+ */
83
+ format(value, { precision } = {}) {
84
+ const aptValue = Number(value) / OCTAS_PER_APT;
85
+ const decimalString = aptValue.toLocaleString('fullwide', {
86
+ maximumFractionDigits: 20,
87
+ minimumFractionDigits: 0,
88
+ useGrouping: false,
89
+ });
90
+ return formatNumberText(decimalString, { precision });
91
+ }
92
+ /**
93
+ * Submits the transaction by creating it and calling onSubmit
94
+ *
95
+ * @returns The transaction hash from onSubmit
96
+ */
97
+ submit() {
98
+ return __awaiter(this, void 0, void 0, function* () {
99
+ const sendTransaction = (yield this.createTransaction());
100
+ return this.onSubmit(sendTransaction);
101
+ });
102
+ }
103
+ /**
104
+ * Gets the balance of the sender's account in octas
105
+ *
106
+ * @returns The balance as bigint in octas
107
+ */
108
+ getBalance() {
109
+ return __awaiter(this, void 0, void 0, function* () {
110
+ const balance = yield this.client.getBalance({
111
+ accountAddress: this.from,
112
+ // APT coin type
113
+ asset: '0x1::aptos_coin::AptosCoin',
114
+ });
115
+ // Balance comes back as a number in octas (1e8 octas = 1 APT)
116
+ return BigInt(Math.floor(balance));
117
+ });
118
+ }
119
+ /**
120
+ * Validates that an address is a valid Aptos address format
121
+ *
122
+ * Aptos addresses are 64-character hex strings prefixed with 0x (66 chars total)
123
+ *
124
+ * @param address - The address to validate
125
+ * @returns true if the address format is valid
126
+ */
127
+ validateAddressFormat(address) {
128
+ if (address === 'dyn_send_transaction.multiple_recipients') {
129
+ return true;
130
+ }
131
+ // Aptos addresses are 0x followed by 64 hex characters
132
+ return /^0x[0-9a-fA-F]{64}$/.test(address);
133
+ }
134
+ /**
135
+ * Creates a transaction payload for sending APT or tokens
136
+ *
137
+ * @returns The transaction payload or undefined if invalid
138
+ */
139
+ createTransaction() {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ const { value, to, nonNativeAddress, nonNativeValue } = this;
142
+ if (!to) {
143
+ throw new Error('Destination is required');
144
+ }
145
+ if (!value && !nonNativeValue) {
146
+ return undefined;
147
+ }
148
+ // Create the transaction payload
149
+ if (nonNativeAddress && nonNativeValue) {
150
+ // Transfer non-native token
151
+ return {
152
+ function: '0x1::coin::transfer',
153
+ functionArguments: [to, nonNativeValue],
154
+ typeArguments: [nonNativeAddress],
155
+ };
156
+ }
157
+ if (value) {
158
+ // Transfer native APT
159
+ return {
160
+ function: '0x1::coin::transfer',
161
+ functionArguments: [to, value],
162
+ typeArguments: ['0x1::aptos_coin::AptosCoin'],
163
+ };
164
+ }
165
+ return undefined;
166
+ });
167
+ }
168
+ /**
169
+ * Safely creates a transaction, returning undefined on error
170
+ *
171
+ * @returns The transaction payload or undefined if creation fails
172
+ */
173
+ createTransactionSafe() {
174
+ return __awaiter(this, void 0, void 0, function* () {
175
+ try {
176
+ return yield this.createTransaction();
177
+ }
178
+ catch (error) {
179
+ return undefined;
180
+ }
181
+ });
182
+ }
183
+ }
184
+
185
+ export { AptosUiTransaction };
@@ -0,0 +1 @@
1
+ export { AptosUiTransaction } from './AptosUiTransaction';
@@ -0,0 +1,8 @@
1
+ 'use client'
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, '__esModule', { value: true });
5
+
6
+ const OCTAS_PER_APT = 1e8;
7
+
8
+ exports.OCTAS_PER_APT = OCTAS_PER_APT;
@@ -0,0 +1 @@
1
+ export declare const OCTAS_PER_APT = 100000000;
@@ -0,0 +1,4 @@
1
+ 'use client'
2
+ const OCTAS_PER_APT = 1e8;
3
+
4
+ export { OCTAS_PER_APT };
@@ -0,0 +1 @@
1
+ export { OCTAS_PER_APT } from './constants';