@tomo-inc/chains-service 0.0.8 → 0.0.9

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
@@ -1,6 +1,8 @@
1
1
  import { ChainTypes, TomoStage } from '@tomo-inc/wallet-utils';
2
- import { Transaction } from 'viem';
2
+ import * as axios from 'axios';
3
3
  import { AxiosInstance } from 'axios';
4
+ import { Transaction as Transaction$1 } from 'viem';
5
+ import { Psbt } from 'bitcoinjs-lib';
4
6
 
5
7
  declare enum AccountType {
6
8
  EOA = "EOA",
@@ -400,6 +402,166 @@ declare class BaseService {
400
402
  setApproveParams(params: any): Promise<void>;
401
403
  }
402
404
 
405
+ type DogeSpendableUtxos = {
406
+ txid: string;
407
+ vout: number;
408
+ outputValue: number;
409
+ script: string;
410
+ tx?: {
411
+ txid: string;
412
+ vout: number;
413
+ };
414
+ };
415
+ interface TransactionParams {
416
+ accountId?: string;
417
+ from: string;
418
+ to: string;
419
+ fee?: string;
420
+ amount: number;
421
+ decimals?: number;
422
+ chainId?: number | string;
423
+ tokenAddress?: string;
424
+ }
425
+ interface DogeTxData {
426
+ amountMismatch?: boolean;
427
+ amount: number;
428
+ fee: number;
429
+ to: string;
430
+ from: string;
431
+ senderAddress?: string;
432
+ sender?: string;
433
+ fromAddress?: string;
434
+ spendableUtxos?: DogeSpendableUtxos[];
435
+ }
436
+
437
+ declare const mydoge: axios.AxiosInstance;
438
+ declare function getBalance(address?: string): Promise<any>;
439
+ type Transaction = {
440
+ blockHash: string;
441
+ blockHeight: number;
442
+ blockTime: number;
443
+ confirmations: number;
444
+ fees: string;
445
+ hex: string;
446
+ size: number;
447
+ txid: string;
448
+ value: string;
449
+ valueIn: string;
450
+ version: number;
451
+ vin: {
452
+ addresses: string[];
453
+ hex: string;
454
+ isAddress: boolean;
455
+ n: number;
456
+ sequence: number;
457
+ txid: string;
458
+ value: string;
459
+ }[];
460
+ vout: {
461
+ addresses: string[];
462
+ value: string;
463
+ n: number;
464
+ hex: string;
465
+ isAddress: boolean;
466
+ }[];
467
+ };
468
+ declare function getTxDetail(txId: string): Promise<Transaction>;
469
+ declare function getInscriptionsUtxos(address: string): Promise<any[]>;
470
+ declare function getSpendableUtxos(address: string): Promise<any[]>;
471
+ declare function getUnSpentUtxos(address: string): Promise<any>;
472
+ declare function getInscriptionsUtxo(address: string, tx: any): Promise<any>;
473
+ declare function sendTransaction({ signed, senderAddress }: any): Promise<any>;
474
+ declare function estimateSmartFee({ senderAddress }: {
475
+ senderAddress: string;
476
+ }): Promise<{
477
+ feePerKB: number;
478
+ }>;
479
+ declare function onCreateTransaction({ data, sendResponse }: {
480
+ data: any;
481
+ sendResponse: any;
482
+ }): Promise<void>;
483
+ type TransactionResponse = {
484
+ transactions: Transaction[];
485
+ txIds: string[];
486
+ totalPages: number;
487
+ page: number;
488
+ };
489
+ declare function getTransactions(address: string, config?: {
490
+ pageSize: number;
491
+ pageNumber: number;
492
+ }): Promise<TransactionResponse>;
493
+ declare const getDogeFeeByBlock: (address?: string, n?: number) => Promise<number>;
494
+ declare const sendDogeTx: (rawTx: string) => Promise<any>;
495
+
496
+ type API_Transaction = Transaction;
497
+ type API_TransactionResponse = TransactionResponse;
498
+ declare const API_estimateSmartFee: typeof estimateSmartFee;
499
+ declare const API_getBalance: typeof getBalance;
500
+ declare const API_getDogeFeeByBlock: typeof getDogeFeeByBlock;
501
+ declare const API_getInscriptionsUtxo: typeof getInscriptionsUtxo;
502
+ declare const API_getInscriptionsUtxos: typeof getInscriptionsUtxos;
503
+ declare const API_getSpendableUtxos: typeof getSpendableUtxos;
504
+ declare const API_getTransactions: typeof getTransactions;
505
+ declare const API_getTxDetail: typeof getTxDetail;
506
+ declare const API_getUnSpentUtxos: typeof getUnSpentUtxos;
507
+ declare const API_mydoge: typeof mydoge;
508
+ declare const API_onCreateTransaction: typeof onCreateTransaction;
509
+ declare const API_sendDogeTx: typeof sendDogeTx;
510
+ declare const API_sendTransaction: typeof sendTransaction;
511
+ declare namespace API {
512
+ export { type API_Transaction as Transaction, type API_TransactionResponse as TransactionResponse, API_estimateSmartFee as estimateSmartFee, API_getBalance as getBalance, API_getDogeFeeByBlock as getDogeFeeByBlock, API_getInscriptionsUtxo as getInscriptionsUtxo, API_getInscriptionsUtxos as getInscriptionsUtxos, API_getSpendableUtxos as getSpendableUtxos, API_getTransactions as getTransactions, API_getTxDetail as getTxDetail, API_getUnSpentUtxos as getUnSpentUtxos, API_mydoge as mydoge, API_onCreateTransaction as onCreateTransaction, API_sendDogeTx as sendDogeTx, API_sendTransaction as sendTransaction };
513
+ }
514
+
515
+ declare class DogecoinService extends BaseService {
516
+ private static instance;
517
+ chainType: ChainTypes | "";
518
+ rpcService: typeof API;
519
+ constructor(chainType: ChainTypes, accountInfo: IAccountInfo, tomoAppInfo: TomoAppInfo);
520
+ static getInstance(chainType: ChainTypes, accountInfo: IAccountInfo, tomoAppInfo: TomoAppInfo): DogecoinService;
521
+ requestAccounts(): Promise<{
522
+ address: string;
523
+ balance: number;
524
+ approved: boolean;
525
+ publicKey: string;
526
+ }>;
527
+ getAccounts(): Promise<string[]>;
528
+ getConnectionStatus(): Promise<{
529
+ connected: boolean;
530
+ address: string;
531
+ selectedWalletAddress: string;
532
+ }>;
533
+ getBalance(): Promise<{
534
+ address: string;
535
+ balance: number;
536
+ }>;
537
+ signMessage({ message, type }: {
538
+ message: string;
539
+ type?: string;
540
+ }): Promise<{
541
+ signedMessage: string;
542
+ }>;
543
+ requestSignedMessage({ message, type, }: {
544
+ message: string;
545
+ type?: string;
546
+ }): Promise<{
547
+ signedMessage: string;
548
+ }>;
549
+ _queryGasInfo(txData: TransactionParams): Promise<QueryGasResponse>;
550
+ requestPsbt({ rawTx, signOnly, }: {
551
+ rawTx: string;
552
+ signOnly?: boolean;
553
+ }): Promise<{
554
+ signedRawTx: string;
555
+ txId?: string;
556
+ } | null>;
557
+ requestTransaction(txData: DogeTxData): Promise<{
558
+ txId: string;
559
+ } | null>;
560
+ getTransactionStatus({ txId }: {
561
+ txId: string;
562
+ }): Promise<any>;
563
+ }
564
+
403
565
  declare class EvmService extends BaseService {
404
566
  private static instance;
405
567
  chainType: ChainTypes | "";
@@ -416,7 +578,7 @@ declare class EvmService extends BaseService {
416
578
  eth_getBalance([address, type]: [`0x${string}`, "latest"]): Promise<string>;
417
579
  _queryGasInfo(txData: TransactionParams$1): Promise<QueryGasResponse>;
418
580
  private createPublicClient;
419
- eth_estimateGas(txs: Transaction[]): Promise<`0x${string}`>;
581
+ eth_estimateGas(txs: Transaction$1[]): Promise<`0x${string}`>;
420
582
  eth_getTransactionCount([address, type]: [`0x${string}`, "latest" | "pending"]): Promise<number>;
421
583
  eth_signTransaction(txParams: {
422
584
  type?: "eip1559" | "legacy";
@@ -432,9 +594,9 @@ declare class EvmService extends BaseService {
432
594
  maxFeePerGas?: `0x${string}`;
433
595
  maxPriorityFeePerGas?: `0x${string}`;
434
596
  accessList?: any[];
435
- }[]): Promise<Transaction>;
597
+ }[]): Promise<Transaction$1>;
436
598
  eth_sendRawTransaction([serializedTransaction]: [`0x${string}`], rpcUrl?: `https://${string}`): Promise<`0x${string}`>;
437
- getTransaction(hash: `0x${string}`): Promise<Transaction>;
599
+ getTransaction(hash: `0x${string}`): Promise<Transaction$1>;
438
600
  }
439
601
 
440
602
  interface SolanaRentInfo {
@@ -492,101 +654,112 @@ declare class SolanaService extends BaseService {
492
654
  private checkTokenAccount;
493
655
  }
494
656
 
495
- type DogeSpendableUtxos = {
496
- txid: string;
497
- vout: number;
498
- outputValue: number;
499
- script: string;
500
- tx?: {
501
- txid: string;
502
- vout: number;
503
- };
504
- };
505
- interface TransactionParams {
506
- accountId?: string;
657
+ declare class TomoWallet extends BaseService {
658
+ private static instance;
659
+ private walletId;
660
+ constructor(walletId: string, tomoAppInfo: TomoAppInfo);
661
+ getInstance(walletId: string, tomoAppInfo: TomoAppInfo): TomoWallet;
662
+ supportedChains(chainType?: ChainTypes | ""): Promise<INetwork[]>;
663
+ getChainInfo(chainType: ChainTypes, chainId: string): Promise<INetwork>;
664
+ isChainSupported(chainType: ChainTypes, chainId: string): Promise<boolean>;
665
+ getTransactions({ tokenAddress, chainId, typeList, pageLimit, cursor, }: TransactionsParams): Promise<TransactionsResponse>;
666
+ }
667
+
668
+ declare function toSatoshi(bitcion: number | string): number;
669
+ declare function toBitcoin(satoshis: number | string): number;
670
+ declare function addUsedUtxos(newUsedUtxos: object): void;
671
+ declare function getUsedUtxos(): any;
672
+ declare function createPsbt({ from, to, amount, fee, spendableUtxos, }: {
507
673
  from: string;
508
674
  to: string;
509
- fee?: string;
510
- amount: number;
511
- decimals?: number;
512
- chainId?: number | string;
513
- tokenAddress?: string;
514
- }
515
- interface DogeTxData {
516
- amountMismatch?: boolean;
517
675
  amount: number;
518
676
  fee: number;
519
- to: string;
520
- from: string;
521
- senderAddress?: string;
522
- sender?: string;
523
- fromAddress?: string;
524
- spendableUtxos?: DogeSpendableUtxos[];
677
+ spendableUtxos: DogeSpendableUtxos[];
678
+ }): Promise<{
679
+ psbtBase64: string;
680
+ usingUtxos: any;
681
+ }>;
682
+ declare function decodePsbt(psbt: string, type?: string): Psbt;
683
+ declare class TransactionParser {
684
+ rawTx: string;
685
+ constructor(rawTx: string);
686
+ hexToText(hex: string): string;
687
+ extractOPReturnData(): any;
688
+ parseScript(): {
689
+ version: string;
690
+ inputCount: number;
691
+ inputs: {
692
+ txid: string;
693
+ vout: string;
694
+ scriptData: any;
695
+ }[];
696
+ opReturnData: any;
697
+ };
698
+ parseInputs(): {
699
+ txid: string;
700
+ vout: string;
701
+ scriptData: any;
702
+ }[];
525
703
  }
526
704
 
527
- declare class DogecoinService extends BaseService {
528
- private static instance;
529
- chainType: ChainTypes | "";
530
- constructor(chainType: ChainTypes, accountInfo: IAccountInfo, tomoAppInfo: TomoAppInfo);
531
- static getInstance(chainType: ChainTypes, accountInfo: IAccountInfo, tomoAppInfo: TomoAppInfo): DogecoinService;
532
- requestAccounts(): Promise<{
533
- address: string;
534
- balance: number;
535
- approved: boolean;
536
- publicKey: string;
537
- }>;
538
- getAccounts(): Promise<string[]>;
539
- getConnectionStatus(): Promise<{
540
- connected: boolean;
541
- address: string;
542
- selectedWalletAddress: string;
705
+ /**
706
+ * UTXO Transaction type definition
707
+ * Replaces the utxoTx type from @okxweb3/coin-bitcoin
708
+ */
709
+ interface utxoTx {
710
+ address: string;
711
+ inputs: Array<{
712
+ txId: string;
713
+ vOut: number;
714
+ amount: number;
715
+ nonWitnessUtxo?: string;
716
+ address?: string;
543
717
  }>;
544
- getBalance(): Promise<{
718
+ outputs: Array<{
545
719
  address: string;
546
- balance: number;
547
- }>;
548
- signMessage({ message, type }: {
549
- message: string;
550
- type?: string;
551
- }): Promise<{
552
- signedMessage: string;
553
- }>;
554
- requestSignedMessage({ message, type, }: {
555
- message: string;
556
- type?: string;
557
- }): Promise<{
558
- signedMessage: string;
559
- }>;
560
- requestDecryptedMessage({ message }: {
561
- message: string;
562
- }): Promise<{
563
- decryptedMessage: string;
720
+ amount: number;
564
721
  }>;
565
- _queryGasInfo(txData: TransactionParams): Promise<QueryGasResponse>;
566
- requestPsbt({ rawTx, signOnly, }: {
567
- rawTx: string;
568
- signOnly?: boolean;
569
- }): Promise<{
570
- signedRawTx: string;
571
- txId?: string;
572
- } | null>;
573
- requestTransaction(txData: DogeTxData): Promise<{
574
- txId: string;
575
- } | null>;
576
- getTransactionStatus({ txId }: {
577
- txId: string;
578
- }): Promise<any>;
579
722
  }
580
-
581
- declare class TomoWallet extends BaseService {
582
- private static instance;
583
- private walletId;
584
- constructor(walletId: string, tomoAppInfo: TomoAppInfo);
585
- getInstance(walletId: string, tomoAppInfo: TomoAppInfo): TomoWallet;
586
- supportedChains(chainType?: ChainTypes | ""): Promise<INetwork[]>;
587
- getChainInfo(chainType: ChainTypes, chainId: string): Promise<INetwork>;
588
- isChainSupported(chainType: ChainTypes, chainId: string): Promise<boolean>;
589
- getTransactions({ tokenAddress, chainId, typeList, pageLimit, cursor, }: TransactionsParams): Promise<TransactionsResponse>;
723
+ declare class DogecoinAddress {
724
+ static network: {
725
+ messagePrefix: string;
726
+ bech32: string;
727
+ bip44: number;
728
+ bip32: {
729
+ public: number;
730
+ private: number;
731
+ };
732
+ pubKeyHash: number;
733
+ scriptHash: number;
734
+ wif: number;
735
+ };
736
+ static generatePath(addressIndex: number): string;
737
+ static verifyAddress(address: string): boolean;
738
+ }
739
+ declare class DogecoinUtils {
740
+ /**
741
+ * Build the PSBT from the transaction
742
+ * @param tx utxoTx
743
+ * @param _maximumFeeRate number (optional, currently unused)
744
+ * @returns base64
745
+ */
746
+ static buildPsbtToBase64(tx: utxoTx, _maximumFeeRate?: number): string;
747
+ /**
748
+ * Extract the transaction from the signed PSBT
749
+ * @param signedPsbt base64
750
+ * @param _maximumFeeRate number (optional, currently unused)
751
+ * @returns transaction hex
752
+ */
753
+ static extractPsbtTransaction(signedPsbt: string, _maximumFeeRate?: number): string;
754
+ /**
755
+ * Convert raw transaction hex to PSBT base64
756
+ * This method converts an unsigned raw transaction to PSBT format.
757
+ * Note: The rawTx should be an unsigned transaction, and the nonWitnessUtxo
758
+ * for each input will need to be fetched separately from the blockchain.
759
+ * @param rawTx hex string of the raw transaction
760
+ * @returns base64 string of the PSBT
761
+ */
762
+ static rawTxToPsbtBase64(rawTx: string): Promise<string>;
590
763
  }
591
764
 
592
765
  declare const ChainTypeServices: {
@@ -595,4 +768,4 @@ declare const ChainTypeServices: {
595
768
  doge: typeof DogecoinService;
596
769
  };
597
770
 
598
- export { AccountType, type ChainAddress, ChainTypeServices, DogecoinService, EvmService, type IAccount, type IAccountInfo, SolanaService, type TomoAppInfo, TomoWallet, type TransactionItem, type TransactionsParams, type TransactionsResponse, TxTypes };
771
+ export { AccountType, type ChainAddress, ChainTypeServices, API as DogecoinAPI, DogecoinAddress, DogecoinService, DogecoinUtils, EvmService, type IAccount, type IAccountInfo, SolanaService, type TomoAppInfo, TomoWallet, type TransactionItem, TransactionParser, type TransactionsParams, type TransactionsResponse, TxTypes, addUsedUtxos, createPsbt, decodePsbt, getUsedUtxos, toBitcoin, toSatoshi, type utxoTx };