@tomo-inc/chains-service 0.0.8 → 0.0.10
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.cjs +1309 -1055
- package/dist/index.d.cts +283 -90
- package/dist/index.d.ts +283 -90
- package/dist/index.js +1280 -1036
- package/package.json +2 -2
- package/src/api/network-data.ts +14 -0
- package/src/api/network.ts +2 -3
- package/src/api/token.ts +6 -6
- package/src/base/service.ts +1 -1
- package/src/base/token.ts +1 -1
- package/src/dogecoin/rpc.ts +10 -191
- package/src/dogecoin/service.ts +74 -40
- package/src/dogecoin/utils-doge.ts +19 -6
- package/src/evm/service.ts +5 -5
- package/src/index.ts +8 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ChainTypes, TomoStage } from '@tomo-inc/wallet-utils';
|
|
2
|
-
import
|
|
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,186 @@ 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<string[]>;
|
|
522
|
+
getAccounts(): Promise<string[]>;
|
|
523
|
+
getConnectionStatus(): Promise<{
|
|
524
|
+
connected: boolean;
|
|
525
|
+
address: string;
|
|
526
|
+
selectedWalletAddress: string;
|
|
527
|
+
}>;
|
|
528
|
+
getBalance(): Promise<{
|
|
529
|
+
confirmed: number;
|
|
530
|
+
unconfirmed: number;
|
|
531
|
+
total: number;
|
|
532
|
+
}>;
|
|
533
|
+
signMessage({ message, type }: {
|
|
534
|
+
message: string;
|
|
535
|
+
type?: string;
|
|
536
|
+
}): Promise<string>;
|
|
537
|
+
requestSignedMessage({ message, type, }: {
|
|
538
|
+
message: string;
|
|
539
|
+
type?: string;
|
|
540
|
+
}): Promise<{
|
|
541
|
+
signedMessage: string;
|
|
542
|
+
}>;
|
|
543
|
+
_queryGasInfo(txData: TransactionParams): Promise<QueryGasResponse>;
|
|
544
|
+
requestPsbt({ rawTx, signOnly, }: {
|
|
545
|
+
rawTx: string;
|
|
546
|
+
signOnly?: boolean;
|
|
547
|
+
}): Promise<{
|
|
548
|
+
signedRawTx: string;
|
|
549
|
+
txId?: string;
|
|
550
|
+
} | null>;
|
|
551
|
+
signPsbt({ psbtHex, options }: {
|
|
552
|
+
psbtHex: string;
|
|
553
|
+
options?: any;
|
|
554
|
+
}): Promise<string>;
|
|
555
|
+
signPsbts({ psbtHexs, options }: {
|
|
556
|
+
psbtHexs: string[];
|
|
557
|
+
options?: any;
|
|
558
|
+
}): Promise<string[]>;
|
|
559
|
+
requestTransaction(txData: DogeTxData): Promise<{
|
|
560
|
+
txId: string;
|
|
561
|
+
} | null>;
|
|
562
|
+
send({ toAddress, amount, fee, options, }: {
|
|
563
|
+
toAddress: string;
|
|
564
|
+
amount: number;
|
|
565
|
+
fee: number;
|
|
566
|
+
options?: {
|
|
567
|
+
feeRate: number;
|
|
568
|
+
memo?: string;
|
|
569
|
+
};
|
|
570
|
+
}): Promise<string>;
|
|
571
|
+
sendDogecoin({ toAddress, amount, options, fee, }: {
|
|
572
|
+
toAddress: string;
|
|
573
|
+
amount: number;
|
|
574
|
+
fee: number;
|
|
575
|
+
options?: {
|
|
576
|
+
feeRate: number;
|
|
577
|
+
memo?: string;
|
|
578
|
+
};
|
|
579
|
+
}): Promise<string>;
|
|
580
|
+
getTransactionStatus({ txId }: {
|
|
581
|
+
txId: string;
|
|
582
|
+
}): Promise<any>;
|
|
583
|
+
}
|
|
584
|
+
|
|
403
585
|
declare class EvmService extends BaseService {
|
|
404
586
|
private static instance;
|
|
405
587
|
chainType: ChainTypes | "";
|
|
@@ -416,7 +598,7 @@ declare class EvmService extends BaseService {
|
|
|
416
598
|
eth_getBalance([address, type]: [`0x${string}`, "latest"]): Promise<string>;
|
|
417
599
|
_queryGasInfo(txData: TransactionParams$1): Promise<QueryGasResponse>;
|
|
418
600
|
private createPublicClient;
|
|
419
|
-
eth_estimateGas(txs: Transaction[]): Promise<`0x${string}`>;
|
|
601
|
+
eth_estimateGas(txs: Transaction$1[]): Promise<`0x${string}`>;
|
|
420
602
|
eth_getTransactionCount([address, type]: [`0x${string}`, "latest" | "pending"]): Promise<number>;
|
|
421
603
|
eth_signTransaction(txParams: {
|
|
422
604
|
type?: "eip1559" | "legacy";
|
|
@@ -432,9 +614,9 @@ declare class EvmService extends BaseService {
|
|
|
432
614
|
maxFeePerGas?: `0x${string}`;
|
|
433
615
|
maxPriorityFeePerGas?: `0x${string}`;
|
|
434
616
|
accessList?: any[];
|
|
435
|
-
}[]): Promise<Transaction>;
|
|
617
|
+
}[]): Promise<Transaction$1>;
|
|
436
618
|
eth_sendRawTransaction([serializedTransaction]: [`0x${string}`], rpcUrl?: `https://${string}`): Promise<`0x${string}`>;
|
|
437
|
-
getTransaction(hash: `0x${string}`): Promise<Transaction>;
|
|
619
|
+
getTransaction(hash: `0x${string}`): Promise<Transaction$1>;
|
|
438
620
|
}
|
|
439
621
|
|
|
440
622
|
interface SolanaRentInfo {
|
|
@@ -492,101 +674,112 @@ declare class SolanaService extends BaseService {
|
|
|
492
674
|
private checkTokenAccount;
|
|
493
675
|
}
|
|
494
676
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
|
|
677
|
+
declare class TomoWallet extends BaseService {
|
|
678
|
+
private static instance;
|
|
679
|
+
private walletId;
|
|
680
|
+
constructor(walletId: string, tomoAppInfo: TomoAppInfo);
|
|
681
|
+
getInstance(walletId: string, tomoAppInfo: TomoAppInfo): TomoWallet;
|
|
682
|
+
supportedChains(chainType?: ChainTypes | ""): Promise<INetwork[]>;
|
|
683
|
+
getChainInfo(chainType: ChainTypes, chainId: string): Promise<INetwork>;
|
|
684
|
+
isChainSupported(chainType: ChainTypes, chainId: string): Promise<boolean>;
|
|
685
|
+
getTransactions({ tokenAddress, chainId, typeList, pageLimit, cursor, }: TransactionsParams): Promise<TransactionsResponse>;
|
|
686
|
+
}
|
|
687
|
+
|
|
688
|
+
declare function toSatoshi(bitcion: number | string): number;
|
|
689
|
+
declare function toBitcoin(satoshis: number | string): number;
|
|
690
|
+
declare function addUsedUtxos(newUsedUtxos: object): void;
|
|
691
|
+
declare function getUsedUtxos(): any;
|
|
692
|
+
declare function createPsbt({ from, to, amount, fee, spendableUtxos, }: {
|
|
507
693
|
from: string;
|
|
508
694
|
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
695
|
amount: number;
|
|
518
696
|
fee: number;
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
697
|
+
spendableUtxos: DogeSpendableUtxos[];
|
|
698
|
+
}): Promise<{
|
|
699
|
+
psbtBase64: string;
|
|
700
|
+
usingUtxos: any;
|
|
701
|
+
}>;
|
|
702
|
+
declare function decodePsbt(psbt: string, type?: string): Psbt;
|
|
703
|
+
declare class TransactionParser {
|
|
704
|
+
rawTx: string;
|
|
705
|
+
constructor(rawTx: string);
|
|
706
|
+
hexToText(hex: string): string;
|
|
707
|
+
extractOPReturnData(): any;
|
|
708
|
+
parseScript(): {
|
|
709
|
+
version: string;
|
|
710
|
+
inputCount: number;
|
|
711
|
+
inputs: {
|
|
712
|
+
txid: string;
|
|
713
|
+
vout: string;
|
|
714
|
+
scriptData: any;
|
|
715
|
+
}[];
|
|
716
|
+
opReturnData: any;
|
|
717
|
+
};
|
|
718
|
+
parseInputs(): {
|
|
719
|
+
txid: string;
|
|
720
|
+
vout: string;
|
|
721
|
+
scriptData: any;
|
|
722
|
+
}[];
|
|
525
723
|
}
|
|
526
724
|
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
getConnectionStatus(): Promise<{
|
|
540
|
-
connected: boolean;
|
|
541
|
-
address: string;
|
|
542
|
-
selectedWalletAddress: string;
|
|
725
|
+
/**
|
|
726
|
+
* UTXO Transaction type definition
|
|
727
|
+
* Replaces the utxoTx type from @okxweb3/coin-bitcoin
|
|
728
|
+
*/
|
|
729
|
+
interface utxoTx {
|
|
730
|
+
address: string;
|
|
731
|
+
inputs: Array<{
|
|
732
|
+
txId: string;
|
|
733
|
+
vOut: number;
|
|
734
|
+
amount: number;
|
|
735
|
+
nonWitnessUtxo?: string;
|
|
736
|
+
address?: string;
|
|
543
737
|
}>;
|
|
544
|
-
|
|
738
|
+
outputs: Array<{
|
|
545
739
|
address: string;
|
|
546
|
-
|
|
547
|
-
}>;
|
|
548
|
-
signMessage({ message, type }: {
|
|
549
|
-
message: string;
|
|
550
|
-
type?: string;
|
|
551
|
-
}): Promise<{
|
|
552
|
-
signedMessage: string;
|
|
740
|
+
amount: number;
|
|
553
741
|
}>;
|
|
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;
|
|
564
|
-
}>;
|
|
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
742
|
}
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
743
|
+
declare class DogecoinAddress {
|
|
744
|
+
static network: {
|
|
745
|
+
messagePrefix: string;
|
|
746
|
+
bech32: string;
|
|
747
|
+
bip44: number;
|
|
748
|
+
bip32: {
|
|
749
|
+
public: number;
|
|
750
|
+
private: number;
|
|
751
|
+
};
|
|
752
|
+
pubKeyHash: number;
|
|
753
|
+
scriptHash: number;
|
|
754
|
+
wif: number;
|
|
755
|
+
};
|
|
756
|
+
static generatePath(addressIndex: number): string;
|
|
757
|
+
static verifyAddress(address: string): boolean;
|
|
758
|
+
}
|
|
759
|
+
declare class DogecoinUtils {
|
|
760
|
+
/**
|
|
761
|
+
* Build the PSBT from the transaction
|
|
762
|
+
* @param tx utxoTx
|
|
763
|
+
* @param _maximumFeeRate number (optional, currently unused)
|
|
764
|
+
* @returns base64
|
|
765
|
+
*/
|
|
766
|
+
static buildPsbtToBase64(tx: utxoTx, _maximumFeeRate?: number): string;
|
|
767
|
+
/**
|
|
768
|
+
* Extract the transaction from the signed PSBT
|
|
769
|
+
* @param signedPsbt base64
|
|
770
|
+
* @param _maximumFeeRate number (optional, currently unused)
|
|
771
|
+
* @returns transaction hex
|
|
772
|
+
*/
|
|
773
|
+
static extractPsbtTransaction(signedPsbt: string, _maximumFeeRate?: number): string;
|
|
774
|
+
/**
|
|
775
|
+
* Convert raw transaction hex to PSBT base64
|
|
776
|
+
* This method converts an unsigned raw transaction to PSBT format.
|
|
777
|
+
* Note: The rawTx should be an unsigned transaction, and the nonWitnessUtxo
|
|
778
|
+
* for each input will need to be fetched separately from the blockchain.
|
|
779
|
+
* @param rawTx hex string of the raw transaction
|
|
780
|
+
* @returns base64 string of the PSBT
|
|
781
|
+
*/
|
|
782
|
+
static rawTxToPsbtBase64(rawTx: string): Promise<string>;
|
|
590
783
|
}
|
|
591
784
|
|
|
592
785
|
declare const ChainTypeServices: {
|
|
@@ -595,4 +788,4 @@ declare const ChainTypeServices: {
|
|
|
595
788
|
doge: typeof DogecoinService;
|
|
596
789
|
};
|
|
597
790
|
|
|
598
|
-
export { AccountType, type ChainAddress, ChainTypeServices, DogecoinService, EvmService, type IAccount, type IAccountInfo, SolanaService, type TomoAppInfo, TomoWallet, type TransactionItem, type TransactionsParams, type TransactionsResponse, TxTypes };
|
|
791
|
+
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 };
|