@movebridge/core 0.1.0 → 0.2.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/dist/index.d.ts CHANGED
@@ -37,7 +37,11 @@ interface Transaction {
37
37
  hash: string;
38
38
  sender: string;
39
39
  sequenceNumber: string;
40
- payload: TransactionPayload;
40
+ payload: {
41
+ function: string;
42
+ typeArguments: string[];
43
+ functionArguments: unknown[];
44
+ };
41
45
  timestamp: string;
42
46
  }
43
47
  /** Transaction response after confirmation */
@@ -48,12 +52,14 @@ interface TransactionResponse {
48
52
  gasUsed: string;
49
53
  events: ContractEvent[];
50
54
  }
51
- /** Transaction payload for entry functions */
55
+ /** Transaction payload for entry functions (AIP-62 compatible) */
52
56
  interface TransactionPayload {
53
- type: 'entry_function_payload';
57
+ /** Entry function identifier: address::module::function */
54
58
  function: string;
59
+ /** Type arguments for generic functions */
55
60
  typeArguments: string[];
56
- arguments: unknown[];
61
+ /** Function arguments */
62
+ functionArguments: unknown[];
57
63
  }
58
64
  /** Signed transaction ready for submission */
59
65
  interface SignedTransaction {
@@ -97,9 +103,20 @@ interface ContractOptions {
97
103
  address: string;
98
104
  module: string;
99
105
  }
100
- /** Event subscription configuration */
106
+ /** Event subscription configuration (new format) */
101
107
  interface EventSubscription {
108
+ /** Account address to watch for events */
109
+ accountAddress: string;
110
+ /** Event type (e.g., '0x1::coin::DepositEvent') */
111
+ eventType: string;
112
+ /** Callback function when events are received */
113
+ callback: (event: ContractEvent) => void;
114
+ }
115
+ /** Legacy event subscription (backward compatible) */
116
+ interface LegacyEventSubscription$1 {
117
+ /** Event handle in format: 0xADDRESS::module::EventType */
102
118
  eventHandle: string;
119
+ /** Callback function when events are received */
103
120
  callback: (event: ContractEvent) => void;
104
121
  }
105
122
 
@@ -109,6 +126,20 @@ interface EventSubscription {
109
126
  * Uses Aptos Wallet Standard (AIP-62) for wallet interactions
110
127
  */
111
128
 
129
+ /**
130
+ * AIP-62 Transaction Payload format
131
+ */
132
+ interface AIP62TransactionPayload {
133
+ payload: {
134
+ function: string;
135
+ typeArguments: string[];
136
+ functionArguments: unknown[];
137
+ };
138
+ }
139
+ /**
140
+ * Unified wallet adapter interface
141
+ * Abstracts different wallet implementations into a common interface
142
+ */
112
143
  interface UnifiedWalletAdapter {
113
144
  name: string;
114
145
  icon: string;
@@ -117,16 +148,38 @@ interface UnifiedWalletAdapter {
117
148
  publicKey: string;
118
149
  }>;
119
150
  disconnect(): Promise<void>;
120
- signAndSubmitTransaction(payload: any): Promise<{
151
+ signAndSubmitTransaction(payload: AIP62TransactionPayload): Promise<{
121
152
  hash: string;
122
153
  }>;
123
- signTransaction(payload: any): Promise<Uint8Array>;
154
+ signTransaction(payload: AIP62TransactionPayload): Promise<Uint8Array>;
124
155
  onAccountChange(cb: (account: {
125
156
  address: string;
126
157
  publicKey: string;
127
158
  } | null) => void): void;
128
159
  onNetworkChange(cb: (network: string) => void): void;
129
160
  }
161
+ /**
162
+ * Wallet Manager
163
+ * Manages wallet detection, connection, and state
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const walletManager = new WalletManager();
168
+ *
169
+ * // Detect available wallets
170
+ * const wallets = walletManager.detectWallets();
171
+ *
172
+ * // Connect to a wallet
173
+ * await walletManager.connect('razor');
174
+ *
175
+ * // Get current state
176
+ * const state = walletManager.getState();
177
+ * console.log(state.address);
178
+ *
179
+ * // Disconnect
180
+ * await walletManager.disconnect();
181
+ * ```
182
+ */
130
183
  declare class WalletManager extends EventEmitter<WalletEvents> {
131
184
  private state;
132
185
  private currentWallet;
@@ -134,18 +187,50 @@ declare class WalletManager extends EventEmitter<WalletEvents> {
134
187
  private standardWallets;
135
188
  private detectedWallets;
136
189
  private unsubscribe;
190
+ /**
191
+ * Detects available wallets using AIP-62 standard
192
+ * @returns Array of detected wallet types
193
+ */
137
194
  detectWallets(): WalletType[];
195
+ /**
196
+ * Gets detailed wallet information for UI display
197
+ * @returns Array of wallet info objects
198
+ */
138
199
  getWalletInfo(): Array<{
139
200
  type: WalletType;
140
201
  name: string;
141
202
  icon: string;
142
203
  }>;
204
+ /**
205
+ * Connects to a wallet
206
+ * @param wallet - Wallet type to connect to
207
+ * @throws MovementError if wallet not found or connection fails
208
+ */
143
209
  connect(wallet: WalletType): Promise<void>;
210
+ /**
211
+ * Disconnects from the current wallet
212
+ */
144
213
  disconnect(): Promise<void>;
214
+ /**
215
+ * Gets the current wallet state
216
+ */
145
217
  getState(): WalletState;
218
+ /**
219
+ * Gets the currently connected wallet type
220
+ */
146
221
  getWallet(): WalletType | null;
222
+ /**
223
+ * Gets the wallet adapter for direct access
224
+ * @internal
225
+ */
147
226
  getAdapter(): UnifiedWalletAdapter | null;
227
+ /**
228
+ * Attempts to auto-connect to the last used wallet
229
+ */
148
230
  autoConnect(): Promise<void>;
231
+ /**
232
+ * Cleans up resources
233
+ */
149
234
  destroy(): void;
150
235
  private setupEventListeners;
151
236
  private saveLastWallet;
@@ -155,7 +240,7 @@ declare class WalletManager extends EventEmitter<WalletEvents> {
155
240
 
156
241
  /**
157
242
  * @movebridge/core - Transaction Builder
158
- * Constructs, signs, and submits transactions
243
+ * Constructs, signs, and submits transactions using AIP-62 wallet standard
159
244
  */
160
245
 
161
246
  /**
@@ -164,22 +249,19 @@ declare class WalletManager extends EventEmitter<WalletEvents> {
164
249
  *
165
250
  * @example
166
251
  * ```typescript
167
- * // Transfer tokens
168
- * const tx = await movement.transaction.transfer({
252
+ * // Transfer tokens using aptos_account::transfer (recommended)
253
+ * const hash = await movement.transaction.transfer({
169
254
  * to: '0x123...',
170
- * amount: '1000000',
255
+ * amount: '1000000', // in octas
171
256
  * });
172
257
  *
173
- * // Build custom transaction
174
- * const tx = await movement.transaction.build({
175
- * function: '0x1::coin::transfer',
176
- * typeArguments: ['0x1::aptos_coin::AptosCoin'],
258
+ * // Build and submit custom transaction
259
+ * const payload = await movement.transaction.build({
260
+ * function: '0x1::aptos_account::transfer',
261
+ * typeArguments: [],
177
262
  * arguments: ['0x123...', '1000000'],
178
263
  * });
179
- *
180
- * // Sign and submit
181
- * const signed = await movement.transaction.sign(tx);
182
- * const hash = await movement.transaction.submit(signed);
264
+ * const hash = await movement.transaction.signAndSubmit(payload);
183
265
  * ```
184
266
  */
185
267
  declare class TransactionBuilder {
@@ -188,50 +270,48 @@ declare class TransactionBuilder {
188
270
  constructor(aptosClient: Aptos, walletManager: WalletManager);
189
271
  /**
190
272
  * Builds a transfer transaction payload
273
+ * Uses 0x1::aptos_account::transfer which handles account creation
191
274
  * @param options - Transfer options
192
- * @returns Transaction payload
275
+ * @returns Transaction payload ready for signing
193
276
  */
194
277
  transfer(options: TransferOptions): Promise<TransactionPayload>;
195
278
  /**
196
279
  * Builds a generic transaction payload
197
- * @param options - Build options
198
- * @returns Transaction payload
280
+ * @param options - Build options with function, typeArguments, and arguments
281
+ * @returns Transaction payload ready for signing
199
282
  */
200
283
  build(options: BuildOptions): Promise<TransactionPayload>;
201
- /**
202
- * Signs a transaction payload
203
- * @param payload - Transaction payload to sign
204
- * @returns Signed transaction
205
- * @throws MovementError with code WALLET_NOT_CONNECTED if no wallet is connected
206
- */
207
- sign(payload: TransactionPayload): Promise<SignedTransaction>;
208
- /**
209
- * Submits a signed transaction to the network
210
- * @param signed - Signed transaction
211
- * @returns Transaction hash
212
- */
213
- submit(signed: SignedTransaction): Promise<string>;
214
284
  /**
215
285
  * Signs and submits a transaction in one step
286
+ * This is the recommended method for most use cases
216
287
  * @param payload - Transaction payload
217
288
  * @returns Transaction hash
289
+ * @throws MovementError with code WALLET_NOT_CONNECTED if no wallet connected
290
+ * @throws MovementError with code TRANSACTION_FAILED if submission fails
218
291
  */
219
292
  signAndSubmit(payload: TransactionPayload): Promise<string>;
220
293
  /**
221
294
  * Simulates a transaction without submitting
295
+ * Useful for gas estimation and checking if transaction will succeed
222
296
  * @param payload - Transaction payload
223
- * @returns Simulation result with gas estimate
297
+ * @returns Simulation result with success status and gas estimate
224
298
  */
225
299
  simulate(payload: TransactionPayload): Promise<{
226
300
  success: boolean;
227
301
  gasUsed: string;
228
302
  vmStatus: string;
229
303
  }>;
304
+ /**
305
+ * Convenience method: Transfer and wait for confirmation
306
+ * @param options - Transfer options
307
+ * @returns Transaction hash
308
+ */
309
+ transferAndSubmit(options: TransferOptions): Promise<string>;
230
310
  }
231
311
 
232
312
  /**
233
313
  * @movebridge/core - Contract Interface
234
- * Simplified interface for contract interactions
314
+ * Simplified interface for Move module interactions
235
315
  */
236
316
 
237
317
  /**
@@ -241,15 +321,15 @@ declare class TransactionBuilder {
241
321
  * @example
242
322
  * ```typescript
243
323
  * const contract = movement.contract({
244
- * address: '0x123...',
245
- * module: 'counter',
324
+ * address: '0x1',
325
+ * module: 'coin',
246
326
  * });
247
327
  *
248
- * // Read (view function)
249
- * const count = await contract.view('get_count', []);
328
+ * // Read (view function) - no wallet needed
329
+ * const balance = await contract.view('balance', ['0x123...'], ['0x1::aptos_coin::AptosCoin']);
250
330
  *
251
- * // Write (entry function)
252
- * const txHash = await contract.call('increment', []);
331
+ * // Write (entry function) - requires connected wallet
332
+ * const txHash = await contract.call('transfer', ['0x456...', '1000000'], ['0x1::aptos_coin::AptosCoin']);
253
333
  * ```
254
334
  */
255
335
  declare class ContractInterface {
@@ -262,33 +342,67 @@ declare class ContractInterface {
262
342
  constructor(aptosClient: Aptos, walletManager: WalletManager, options: ContractOptions);
263
343
  /**
264
344
  * Calls a view function (read-only)
345
+ * View functions don't require a wallet connection
346
+ *
265
347
  * @param functionName - Name of the view function
266
348
  * @param args - Function arguments
267
- * @param typeArgs - Type arguments (optional)
349
+ * @param typeArgs - Type arguments for generic functions
268
350
  * @returns Function result
269
351
  * @throws MovementError with code VIEW_FUNCTION_FAILED if call fails
270
- */
271
- view<T = unknown>(functionName: string, args: unknown[], typeArgs?: string[]): Promise<T>;
352
+ *
353
+ * @example
354
+ * ```typescript
355
+ * // Get coin balance
356
+ * const balance = await contract.view('balance', [address], ['0x1::aptos_coin::AptosCoin']);
357
+ *
358
+ * // Check if account exists
359
+ * const exists = await contract.view('exists_at', [address]);
360
+ * ```
361
+ */
362
+ view<T = unknown>(functionName: string, args?: unknown[], typeArgs?: string[]): Promise<T>;
272
363
  /**
273
364
  * Calls an entry function (write operation)
365
+ * Requires a connected wallet
366
+ *
274
367
  * @param functionName - Name of the entry function
275
368
  * @param args - Function arguments
276
- * @param typeArgs - Type arguments (optional)
369
+ * @param typeArgs - Type arguments for generic functions
277
370
  * @returns Transaction hash
278
- * @throws MovementError with code WALLET_NOT_CONNECTED if no wallet is connected
371
+ * @throws MovementError with code WALLET_NOT_CONNECTED if no wallet connected
279
372
  * @throws MovementError with code TRANSACTION_FAILED if transaction fails
280
- */
281
- call(functionName: string, args: unknown[], typeArgs?: string[]): Promise<string>;
373
+ *
374
+ * @example
375
+ * ```typescript
376
+ * // Transfer coins
377
+ * const txHash = await contract.call('transfer', [recipient, amount], ['0x1::aptos_coin::AptosCoin']);
378
+ *
379
+ * // Call a custom function
380
+ * const txHash = await contract.call('increment', []);
381
+ * ```
382
+ */
383
+ call(functionName: string, args?: unknown[], typeArgs?: string[]): Promise<string>;
282
384
  /**
283
385
  * Checks if a resource exists at the contract address
284
- * @param resourceType - Full resource type (e.g., '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>')
386
+ * @param resourceType - Full resource type
285
387
  * @returns true if resource exists
388
+ *
389
+ * @example
390
+ * ```typescript
391
+ * const hasCoin = await contract.hasResource('0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>');
392
+ * ```
286
393
  */
287
394
  hasResource(resourceType: string): Promise<boolean>;
288
395
  /**
289
396
  * Gets a resource from the contract address
290
397
  * @param resourceType - Full resource type
291
398
  * @returns Resource data or null if not found
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * const coinStore = await contract.getResource<{ coin: { value: string } }>(
403
+ * '0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>'
404
+ * );
405
+ * ```
292
406
  */
293
407
  getResource<T = unknown>(resourceType: string): Promise<T | null>;
294
408
  /**
@@ -301,25 +415,46 @@ declare class ContractInterface {
301
415
 
302
416
  /**
303
417
  * @movebridge/core - Event Listener
304
- * Subscribes to and handles contract events
418
+ * Subscribes to and handles blockchain events via polling
305
419
  */
306
420
 
421
+ /**
422
+ * Event subscription configuration
423
+ */
424
+ interface EventSubscriptionConfig {
425
+ /** Account address to watch for events */
426
+ accountAddress: string;
427
+ /** Event type (e.g., '0x1::coin::DepositEvent') */
428
+ eventType: string;
429
+ /** Callback function when events are received */
430
+ callback: (event: ContractEvent) => void;
431
+ }
432
+ /**
433
+ * Legacy event subscription (for backward compatibility)
434
+ */
435
+ interface LegacyEventSubscription {
436
+ /** Event handle in format: 0xADDRESS::module::EventType */
437
+ eventHandle: string;
438
+ /** Callback function when events are received */
439
+ callback: (event: ContractEvent) => void;
440
+ }
307
441
  /**
308
442
  * Event Listener
309
- * Manages event subscriptions and polling
443
+ * Manages event subscriptions and polling for blockchain events
310
444
  *
311
445
  * @example
312
446
  * ```typescript
313
- * // Subscribe to events
314
- * const subscriptionId = movement.events.subscribe({
315
- * eventHandle: '0x123::counter::CounterChanged',
447
+ * // Subscribe to deposit events for an account
448
+ * const subId = movement.events.subscribe({
449
+ * accountAddress: '0x123...',
450
+ * eventType: '0x1::coin::DepositEvent',
316
451
  * callback: (event) => {
317
- * console.log('Counter changed:', event);
452
+ * console.log('Deposit received:', event.data);
318
453
  * },
319
454
  * });
320
455
  *
321
- * // Unsubscribe
322
- * movement.events.unsubscribe(subscriptionId);
456
+ * // Unsubscribe when done
457
+ * movement.events.unsubscribe(subId);
323
458
  * ```
324
459
  */
325
460
  declare class EventListener {
@@ -331,12 +466,29 @@ declare class EventListener {
331
466
  pollIntervalMs?: number;
332
467
  });
333
468
  /**
334
- * Subscribes to contract events
469
+ * Subscribes to blockchain events
470
+ * Supports both new format (accountAddress + eventType) and legacy format (eventHandle)
471
+ *
335
472
  * @param subscription - Subscription configuration
336
- * @returns Subscription ID
337
- * @throws MovementError with code INVALID_EVENT_HANDLE if event handle is invalid
338
- */
339
- subscribe(subscription: EventSubscription): string;
473
+ * @returns Subscription ID for unsubscribing
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * // New format (recommended)
478
+ * const subId = events.subscribe({
479
+ * accountAddress: '0x1',
480
+ * eventType: '0x1::coin::DepositEvent',
481
+ * callback: (event) => console.log(event),
482
+ * });
483
+ *
484
+ * // Legacy format (backward compatible)
485
+ * const subId = events.subscribe({
486
+ * eventHandle: '0x1::coin::DepositEvent',
487
+ * callback: (event) => console.log(event),
488
+ * });
489
+ * ```
490
+ */
491
+ subscribe(subscription: EventSubscriptionConfig | LegacyEventSubscription): string;
340
492
  /**
341
493
  * Unsubscribes from events
342
494
  * @param subscriptionId - Subscription ID to remove
@@ -358,8 +510,8 @@ declare class EventListener {
358
510
  */
359
511
  hasSubscription(subscriptionId: string): boolean;
360
512
  /**
361
- * Polls for new events
362
- * @param subscriptionId - Subscription ID
513
+ * Polls for new events for a subscription
514
+ * @internal
363
515
  */
364
516
  private pollEvents;
365
517
  }
@@ -599,4 +751,4 @@ declare function isMovementError(error: unknown): error is MovementError;
599
751
  */
600
752
  declare function wrapError(error: unknown, code: ErrorCode, context?: string): MovementError;
601
753
 
602
- export { type BuildOptions, type ContractEvent, ContractInterface, type ContractOptions, DEFAULT_COIN_TYPE, type ErrorCode, type ErrorDetails, Errors, EventListener, type EventSubscription, Movement, type MovementConfig, MovementError, NETWORK_CONFIG, type NetworkConfig, type NetworkType, type ResolvedConfig, type Resource, type SignedTransaction, type Transaction, TransactionBuilder, type TransactionPayload, type TransactionResponse, type TransferOptions, type WalletEvents, WalletManager, type WalletState, type WalletType, getExplorerAccountUrl, getExplorerTxUrl, isMovementError, isValidAddress, isValidEventHandle, resolveConfig, wrapError };
754
+ export { type BuildOptions, type ContractEvent, ContractInterface, type ContractOptions, DEFAULT_COIN_TYPE, type ErrorCode, type ErrorDetails, Errors, EventListener, type EventSubscription, type EventSubscriptionConfig, type LegacyEventSubscription$1 as LegacyEventSubscription, Movement, type MovementConfig, MovementError, NETWORK_CONFIG, type NetworkConfig, type NetworkType, type ResolvedConfig, type Resource, type SignedTransaction, type Transaction, TransactionBuilder, type TransactionPayload, type TransactionResponse, type TransferOptions, type WalletEvents, WalletManager, type WalletState, type WalletType, getExplorerAccountUrl, getExplorerTxUrl, isMovementError, isValidAddress, isValidEventHandle, resolveConfig, wrapError };