@tomo-inc/chains-service 0.0.9 → 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 CHANGED
@@ -2909,24 +2909,6 @@ var Transactions = class {
2909
2909
  return res?.data || {};
2910
2910
  }
2911
2911
  };
2912
- function getConfig(tomoStage) {
2913
- const domain = walletUtils.TomoApiDomains[tomoStage];
2914
- if (!domain) {
2915
- throw new Error("Invalid tomo stage");
2916
- }
2917
- return {
2918
- rpcBaseUrl: `${domain}`,
2919
- walletBaseUrl: `${domain}/wallet`,
2920
- txBaseUrl: `${domain}/quote`,
2921
- tokenBaseUrl: `${domain}/token`,
2922
- userBaseUrl: `${domain}/user/api`
2923
- };
2924
- }
2925
- var CONFIG = {
2926
- prod: getConfig("prod"),
2927
- pre: getConfig("pre"),
2928
- dev: getConfig("dev")
2929
- };
2930
2912
  function generateSignature(config) {
2931
2913
  const timestamp = Math.floor(Date.now() / 1e3).toString();
2932
2914
  const method = config.method.toUpperCase();
@@ -3915,6 +3897,24 @@ function tomoPublicApiService(publicApiBase, tomoAppInfo) {
3915
3897
  walletAPIs: WalletAPIs.getInstance(publicApiBase, tomoAppInfo)
3916
3898
  };
3917
3899
  }
3900
+ function getConfig(tomoStage) {
3901
+ const domain = walletUtils.TomoApiDomains[tomoStage];
3902
+ if (!domain) {
3903
+ throw new Error("Invalid tomo stage");
3904
+ }
3905
+ return {
3906
+ rpcBaseUrl: `${domain}`,
3907
+ walletBaseUrl: `${domain}/wallet`,
3908
+ txBaseUrl: `${domain}/quote`,
3909
+ tokenBaseUrl: `${domain}/token`,
3910
+ userBaseUrl: `${domain}/user/api`
3911
+ };
3912
+ }
3913
+ var CONFIG = {
3914
+ prod: getConfig("prod"),
3915
+ pre: getConfig("pre"),
3916
+ dev: getConfig("dev")
3917
+ };
3918
3918
 
3919
3919
  // src/base/service.ts
3920
3920
  var BaseService = class {
@@ -4489,21 +4489,10 @@ var DogecoinService = class _DogecoinService extends BaseService {
4489
4489
  }
4490
4490
  async requestAccounts() {
4491
4491
  const addresses = await this.accountInfo.getCurrent();
4492
- const { publicKey, address } = addresses?.[0] || {};
4493
- if (!address) {
4494
- throw new Error("address is not set");
4495
- }
4496
- const { balance = 0 } = await getBalance(address);
4497
- return {
4498
- address,
4499
- balance,
4500
- approved: true,
4501
- publicKey
4502
- };
4492
+ return addresses.map((account) => account.address);
4503
4493
  }
4504
4494
  async getAccounts() {
4505
- const accounts = await this.accountInfo.getCurrent();
4506
- return accounts.map((account) => account.address);
4495
+ return await this.requestAccounts();
4507
4496
  }
4508
4497
  async getConnectionStatus() {
4509
4498
  const addresses = await this.accountInfo.getCurrent();
@@ -4525,8 +4514,9 @@ var DogecoinService = class _DogecoinService extends BaseService {
4525
4514
  }
4526
4515
  const { balance = 0 } = await getBalance(address);
4527
4516
  return {
4528
- address,
4529
- balance
4517
+ confirmed: balance,
4518
+ unconfirmed: 0,
4519
+ total: balance
4530
4520
  };
4531
4521
  }
4532
4522
  async signMessage({ message, type }) {
@@ -4534,18 +4524,19 @@ var DogecoinService = class _DogecoinService extends BaseService {
4534
4524
  throw new Error("bip322simple not support.");
4535
4525
  }
4536
4526
  const signature = await this.accountInfo.signMessage(message);
4537
- return {
4538
- signedMessage: signature
4539
- };
4527
+ return signature;
4540
4528
  }
4541
4529
  async requestSignedMessage({
4542
4530
  message,
4543
4531
  type
4544
4532
  }) {
4545
- return await this.signMessage({
4533
+ const signedMessage = await this.signMessage({
4546
4534
  message,
4547
4535
  type
4548
4536
  });
4537
+ return {
4538
+ signedMessage
4539
+ };
4549
4540
  }
4550
4541
  async _queryGasInfo(txData) {
4551
4542
  const { chainId, amount = 0, decimals = 8 } = txData;
@@ -4613,6 +4604,18 @@ var DogecoinService = class _DogecoinService extends BaseService {
4613
4604
  signedRawTx
4614
4605
  };
4615
4606
  }
4607
+ async signPsbt({ psbtHex, options }) {
4608
+ const psbtBase64 = toBase64(fromHex(psbtHex));
4609
+ const signedPsbt = await this.accountInfo.signTransaction(JSON.stringify({ psbtBase64 }));
4610
+ if (!signedPsbt) {
4611
+ throw new Error("error psbtHex:" + psbtHex);
4612
+ }
4613
+ const signedRawTx = DogecoinUtils.extractPsbtTransaction(signedPsbt, 1e5);
4614
+ return signedRawTx;
4615
+ }
4616
+ async signPsbts({ psbtHexs, options }) {
4617
+ throw new Error("not implemented");
4618
+ }
4616
4619
  async requestTransaction(txData) {
4617
4620
  const spendableUtxos = txData?.spendableUtxos;
4618
4621
  if (txData.amountMismatch) {
@@ -4635,6 +4638,34 @@ var DogecoinService = class _DogecoinService extends BaseService {
4635
4638
  throw new Error("Error: send transaction err." + JSON.stringify(err));
4636
4639
  }
4637
4640
  }
4641
+ async send({
4642
+ toAddress,
4643
+ amount,
4644
+ fee = 0,
4645
+ options
4646
+ }) {
4647
+ if (fee <= 0) {
4648
+ throw new Error("fee is required");
4649
+ }
4650
+ const addresses = await this.accountInfo.getCurrent();
4651
+ const { address } = addresses?.[0] || {};
4652
+ const txData = {
4653
+ to: toAddress,
4654
+ amount: toBitcoin(amount),
4655
+ fee: toBitcoin(fee || 0),
4656
+ from: address
4657
+ };
4658
+ const res = await this.requestTransaction(txData);
4659
+ return res?.txId || "";
4660
+ }
4661
+ async sendDogecoin({
4662
+ toAddress,
4663
+ amount,
4664
+ options,
4665
+ fee
4666
+ }) {
4667
+ return await this.send({ toAddress, amount, options, fee });
4668
+ }
4638
4669
  async getTransactionStatus({ txId }) {
4639
4670
  const transaction = await getTxDetail(txId);
4640
4671
  if (!transaction?.txid) {
package/dist/index.d.cts CHANGED
@@ -518,12 +518,7 @@ declare class DogecoinService extends BaseService {
518
518
  rpcService: typeof API;
519
519
  constructor(chainType: ChainTypes, accountInfo: IAccountInfo, tomoAppInfo: TomoAppInfo);
520
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
- }>;
521
+ requestAccounts(): Promise<string[]>;
527
522
  getAccounts(): Promise<string[]>;
528
523
  getConnectionStatus(): Promise<{
529
524
  connected: boolean;
@@ -531,15 +526,14 @@ declare class DogecoinService extends BaseService {
531
526
  selectedWalletAddress: string;
532
527
  }>;
533
528
  getBalance(): Promise<{
534
- address: string;
535
- balance: number;
529
+ confirmed: number;
530
+ unconfirmed: number;
531
+ total: number;
536
532
  }>;
537
533
  signMessage({ message, type }: {
538
534
  message: string;
539
535
  type?: string;
540
- }): Promise<{
541
- signedMessage: string;
542
- }>;
536
+ }): Promise<string>;
543
537
  requestSignedMessage({ message, type, }: {
544
538
  message: string;
545
539
  type?: string;
@@ -554,9 +548,35 @@ declare class DogecoinService extends BaseService {
554
548
  signedRawTx: string;
555
549
  txId?: string;
556
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[]>;
557
559
  requestTransaction(txData: DogeTxData): Promise<{
558
560
  txId: string;
559
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>;
560
580
  getTransactionStatus({ txId }: {
561
581
  txId: string;
562
582
  }): Promise<any>;
package/dist/index.d.ts CHANGED
@@ -518,12 +518,7 @@ declare class DogecoinService extends BaseService {
518
518
  rpcService: typeof API;
519
519
  constructor(chainType: ChainTypes, accountInfo: IAccountInfo, tomoAppInfo: TomoAppInfo);
520
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
- }>;
521
+ requestAccounts(): Promise<string[]>;
527
522
  getAccounts(): Promise<string[]>;
528
523
  getConnectionStatus(): Promise<{
529
524
  connected: boolean;
@@ -531,15 +526,14 @@ declare class DogecoinService extends BaseService {
531
526
  selectedWalletAddress: string;
532
527
  }>;
533
528
  getBalance(): Promise<{
534
- address: string;
535
- balance: number;
529
+ confirmed: number;
530
+ unconfirmed: number;
531
+ total: number;
536
532
  }>;
537
533
  signMessage({ message, type }: {
538
534
  message: string;
539
535
  type?: string;
540
- }): Promise<{
541
- signedMessage: string;
542
- }>;
536
+ }): Promise<string>;
543
537
  requestSignedMessage({ message, type, }: {
544
538
  message: string;
545
539
  type?: string;
@@ -554,9 +548,35 @@ declare class DogecoinService extends BaseService {
554
548
  signedRawTx: string;
555
549
  txId?: string;
556
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[]>;
557
559
  requestTransaction(txData: DogeTxData): Promise<{
558
560
  txId: string;
559
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>;
560
580
  getTransactionStatus({ txId }: {
561
581
  txId: string;
562
582
  }): Promise<any>;
package/dist/index.js CHANGED
@@ -2901,24 +2901,6 @@ var Transactions = class {
2901
2901
  return res?.data || {};
2902
2902
  }
2903
2903
  };
2904
- function getConfig(tomoStage) {
2905
- const domain = TomoApiDomains[tomoStage];
2906
- if (!domain) {
2907
- throw new Error("Invalid tomo stage");
2908
- }
2909
- return {
2910
- rpcBaseUrl: `${domain}`,
2911
- walletBaseUrl: `${domain}/wallet`,
2912
- txBaseUrl: `${domain}/quote`,
2913
- tokenBaseUrl: `${domain}/token`,
2914
- userBaseUrl: `${domain}/user/api`
2915
- };
2916
- }
2917
- var CONFIG = {
2918
- prod: getConfig("prod"),
2919
- pre: getConfig("pre"),
2920
- dev: getConfig("dev")
2921
- };
2922
2904
  function generateSignature(config) {
2923
2905
  const timestamp = Math.floor(Date.now() / 1e3).toString();
2924
2906
  const method = config.method.toUpperCase();
@@ -3907,6 +3889,24 @@ function tomoPublicApiService(publicApiBase, tomoAppInfo) {
3907
3889
  walletAPIs: WalletAPIs.getInstance(publicApiBase, tomoAppInfo)
3908
3890
  };
3909
3891
  }
3892
+ function getConfig(tomoStage) {
3893
+ const domain = TomoApiDomains[tomoStage];
3894
+ if (!domain) {
3895
+ throw new Error("Invalid tomo stage");
3896
+ }
3897
+ return {
3898
+ rpcBaseUrl: `${domain}`,
3899
+ walletBaseUrl: `${domain}/wallet`,
3900
+ txBaseUrl: `${domain}/quote`,
3901
+ tokenBaseUrl: `${domain}/token`,
3902
+ userBaseUrl: `${domain}/user/api`
3903
+ };
3904
+ }
3905
+ var CONFIG = {
3906
+ prod: getConfig("prod"),
3907
+ pre: getConfig("pre"),
3908
+ dev: getConfig("dev")
3909
+ };
3910
3910
 
3911
3911
  // src/base/service.ts
3912
3912
  var BaseService = class {
@@ -4481,21 +4481,10 @@ var DogecoinService = class _DogecoinService extends BaseService {
4481
4481
  }
4482
4482
  async requestAccounts() {
4483
4483
  const addresses = await this.accountInfo.getCurrent();
4484
- const { publicKey, address } = addresses?.[0] || {};
4485
- if (!address) {
4486
- throw new Error("address is not set");
4487
- }
4488
- const { balance = 0 } = await getBalance(address);
4489
- return {
4490
- address,
4491
- balance,
4492
- approved: true,
4493
- publicKey
4494
- };
4484
+ return addresses.map((account) => account.address);
4495
4485
  }
4496
4486
  async getAccounts() {
4497
- const accounts = await this.accountInfo.getCurrent();
4498
- return accounts.map((account) => account.address);
4487
+ return await this.requestAccounts();
4499
4488
  }
4500
4489
  async getConnectionStatus() {
4501
4490
  const addresses = await this.accountInfo.getCurrent();
@@ -4517,8 +4506,9 @@ var DogecoinService = class _DogecoinService extends BaseService {
4517
4506
  }
4518
4507
  const { balance = 0 } = await getBalance(address);
4519
4508
  return {
4520
- address,
4521
- balance
4509
+ confirmed: balance,
4510
+ unconfirmed: 0,
4511
+ total: balance
4522
4512
  };
4523
4513
  }
4524
4514
  async signMessage({ message, type }) {
@@ -4526,18 +4516,19 @@ var DogecoinService = class _DogecoinService extends BaseService {
4526
4516
  throw new Error("bip322simple not support.");
4527
4517
  }
4528
4518
  const signature = await this.accountInfo.signMessage(message);
4529
- return {
4530
- signedMessage: signature
4531
- };
4519
+ return signature;
4532
4520
  }
4533
4521
  async requestSignedMessage({
4534
4522
  message,
4535
4523
  type
4536
4524
  }) {
4537
- return await this.signMessage({
4525
+ const signedMessage = await this.signMessage({
4538
4526
  message,
4539
4527
  type
4540
4528
  });
4529
+ return {
4530
+ signedMessage
4531
+ };
4541
4532
  }
4542
4533
  async _queryGasInfo(txData) {
4543
4534
  const { chainId, amount = 0, decimals = 8 } = txData;
@@ -4605,6 +4596,18 @@ var DogecoinService = class _DogecoinService extends BaseService {
4605
4596
  signedRawTx
4606
4597
  };
4607
4598
  }
4599
+ async signPsbt({ psbtHex, options }) {
4600
+ const psbtBase64 = toBase64(fromHex(psbtHex));
4601
+ const signedPsbt = await this.accountInfo.signTransaction(JSON.stringify({ psbtBase64 }));
4602
+ if (!signedPsbt) {
4603
+ throw new Error("error psbtHex:" + psbtHex);
4604
+ }
4605
+ const signedRawTx = DogecoinUtils.extractPsbtTransaction(signedPsbt, 1e5);
4606
+ return signedRawTx;
4607
+ }
4608
+ async signPsbts({ psbtHexs, options }) {
4609
+ throw new Error("not implemented");
4610
+ }
4608
4611
  async requestTransaction(txData) {
4609
4612
  const spendableUtxos = txData?.spendableUtxos;
4610
4613
  if (txData.amountMismatch) {
@@ -4627,6 +4630,34 @@ var DogecoinService = class _DogecoinService extends BaseService {
4627
4630
  throw new Error("Error: send transaction err." + JSON.stringify(err));
4628
4631
  }
4629
4632
  }
4633
+ async send({
4634
+ toAddress,
4635
+ amount,
4636
+ fee = 0,
4637
+ options
4638
+ }) {
4639
+ if (fee <= 0) {
4640
+ throw new Error("fee is required");
4641
+ }
4642
+ const addresses = await this.accountInfo.getCurrent();
4643
+ const { address } = addresses?.[0] || {};
4644
+ const txData = {
4645
+ to: toAddress,
4646
+ amount: toBitcoin(amount),
4647
+ fee: toBitcoin(fee || 0),
4648
+ from: address
4649
+ };
4650
+ const res = await this.requestTransaction(txData);
4651
+ return res?.txId || "";
4652
+ }
4653
+ async sendDogecoin({
4654
+ toAddress,
4655
+ amount,
4656
+ options,
4657
+ fee
4658
+ }) {
4659
+ return await this.send({ toAddress, amount, options, fee });
4660
+ }
4630
4661
  async getTransactionStatus({ txId }) {
4631
4662
  const transaction = await getTxDetail(txId);
4632
4663
  if (!transaction?.txid) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/chains-service",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "author": "tomo.inc",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -23,7 +23,7 @@
23
23
  "bitcoinjs-lib": "^7.0.0",
24
24
  "crypto-js": "4.2.0",
25
25
  "viem": "2.21.54",
26
- "@tomo-inc/wallet-utils": "0.0.8"
26
+ "@tomo-inc/wallet-utils": "0.0.9"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@types/supertest": "^2.0.12",
@@ -1,8 +1,8 @@
1
1
  import { ChainTypes, SupportedChainTypes } from "@tomo-inc/wallet-utils";
2
- import { loadNetworks } from "./network-data";
2
+ import { INetwork, TomoAppInfo } from "../types";
3
3
  import { BasePublicService } from "./base";
4
+ import { loadNetworks } from "./network-data";
4
5
  import { IPublicApiBaseConfig } from "./types";
5
- import { INetwork, TomoAppInfo } from "../types";
6
6
 
7
7
  import { cache } from "@tomo-inc/wallet-utils";
8
8
 
@@ -29,7 +29,6 @@ export class NetworkAPIs extends BasePublicService {
29
29
  nativeCurrency,
30
30
  };
31
31
  });
32
-
33
32
  this.currentChainId = "1";
34
33
  }
35
34
 
package/src/api/token.ts CHANGED
@@ -1,16 +1,16 @@
1
+ import { TomoAppInfo } from "../types";
2
+ import { BasePublicService } from "./base";
1
3
  import {
2
- GetTokenInfoParams,
3
- RemoteResponse,
4
- RemoteTokenInfo,
5
4
  AddCustomTokenParams,
6
5
  DeleteCustomTokenParams,
7
- SyncCustomTokenParams,
8
6
  GetTokenBalanceParams,
9
7
  GetTokenBalanceResponse,
8
+ GetTokenInfoParams,
10
9
  IPublicApiBaseConfig,
10
+ RemoteResponse,
11
+ RemoteTokenInfo,
12
+ SyncCustomTokenParams,
11
13
  } from "./types";
12
- import { BasePublicService } from "./base";
13
- import { TomoAppInfo } from "../types";
14
14
 
15
15
  export class TokenAPIs extends BasePublicService {
16
16
  private static instance: TokenAPIs;
@@ -2,8 +2,8 @@ import { Networks } from "./network";
2
2
  import { Tokens } from "./token";
3
3
  import { Transactions } from "./transaction";
4
4
 
5
- import { CONFIG } from "../config";
6
5
  import { tomoPublicApiService } from "../api";
6
+ import { CONFIG } from "../config";
7
7
  import { IAccountInfo, TomoAppInfo } from "../types";
8
8
 
9
9
  export class BaseService {
package/src/base/token.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  //types
2
- import { TokenInfo } from "../types";
3
2
  import { TokenAPIs } from "../api/token";
4
3
  import { GetTokenInfoParams } from "../api/types";
4
+ import { TokenInfo } from "../types";
5
5
 
6
6
  export class Tokens {
7
7
  public tokenAPIs: TokenAPIs;
@@ -12,9 +12,10 @@ import { TransactionParams } from "./type";
12
12
  import * as API from "./rpc";
13
13
  import * as utils from "./utils";
14
14
  import { DogeTxData } from "./type";
15
+ import * as base from "./base";
15
16
 
16
17
  import { BaseConfig } from "./config";
17
- import { createPsbt, addUsedUtxos } from "./utils";
18
+ import { createPsbt, addUsedUtxos, toBitcoin } from "./utils";
18
19
 
19
20
  export class DogecoinService extends BaseService {
20
21
  private static instance: DogecoinService;
@@ -34,25 +35,14 @@ export class DogecoinService extends BaseService {
34
35
  }
35
36
  return DogecoinService.instance;
36
37
  }
37
- public async requestAccounts(): Promise<{ address: string; balance: number; approved: boolean; publicKey: string }> {
38
- const addresses = await this.accountInfo.getCurrent();
39
- const { publicKey, address } = addresses?.[0] || {};
40
- if (!address) {
41
- throw new Error("address is not set");
42
- }
43
- const { balance = 0 } = await API.getBalance(address);
44
38
 
45
- return {
46
- address,
47
- balance,
48
- approved: true,
49
- publicKey,
50
- };
39
+ public async requestAccounts(): Promise<string[]> {
40
+ const addresses = await this.accountInfo.getCurrent();
41
+ return addresses.map((account: { address: string }) => account.address);
51
42
  }
52
43
 
53
44
  public async getAccounts(): Promise<string[]> {
54
- const accounts = await this.accountInfo.getCurrent();
55
- return accounts.map((account: { address: string }) => account.address);
45
+ return await this.requestAccounts();
56
46
  }
57
47
 
58
48
  public async getConnectionStatus(): Promise<{ connected: boolean; address: string; selectedWalletAddress: string }> {
@@ -68,7 +58,7 @@ export class DogecoinService extends BaseService {
68
58
  };
69
59
  }
70
60
 
71
- public async getBalance(): Promise<{ address: string; balance: number }> {
61
+ public async getBalance(): Promise<{ confirmed: number; unconfirmed: number; total: number }> {
72
62
  const addresses = await this.accountInfo.getCurrent();
73
63
  const { address } = addresses?.[0] || {};
74
64
  if (!address) {
@@ -78,21 +68,20 @@ export class DogecoinService extends BaseService {
78
68
  const { balance = 0 } = await API.getBalance(address);
79
69
 
80
70
  return {
81
- address,
82
- balance,
71
+ confirmed: balance,
72
+ unconfirmed: 0,
73
+ total: balance,
83
74
  };
84
75
  }
85
76
 
86
- public async signMessage({ message, type }: { message: string; type?: string }): Promise<{ signedMessage: string }> {
77
+ public async signMessage({ message, type }: { message: string; type?: string }): Promise<string> {
87
78
  if (type) {
88
79
  throw new Error("bip322simple not support.");
89
80
  }
90
81
 
91
82
  const signature = await this.accountInfo.signMessage(message);
92
83
 
93
- return {
94
- signedMessage: signature,
95
- };
84
+ return signature;
96
85
  }
97
86
 
98
87
  public async requestSignedMessage({
@@ -102,10 +91,13 @@ export class DogecoinService extends BaseService {
102
91
  message: string;
103
92
  type?: string;
104
93
  }): Promise<{ signedMessage: string }> {
105
- return await this.signMessage({
94
+ const signedMessage = await this.signMessage({
106
95
  message,
107
96
  type,
108
97
  });
98
+ return {
99
+ signedMessage,
100
+ };
109
101
  }
110
102
 
111
103
  public async _queryGasInfo(txData: TransactionParams): Promise<QueryGasResponse> {
@@ -187,6 +179,22 @@ export class DogecoinService extends BaseService {
187
179
  };
188
180
  }
189
181
 
182
+ public async signPsbt({ psbtHex, options }: { psbtHex: string; options?: any }): Promise<string> {
183
+ const psbtBase64 = base.toBase64(base.fromHex(psbtHex));
184
+ const signedPsbt = await this.accountInfo.signTransaction(JSON.stringify({ psbtBase64 }));
185
+
186
+ if (!signedPsbt) {
187
+ throw new Error("error psbtHex:" + psbtHex);
188
+ }
189
+
190
+ const signedRawTx = DogecoinUtils.extractPsbtTransaction(signedPsbt, 100000);
191
+ return signedRawTx;
192
+ }
193
+
194
+ public async signPsbts({ psbtHexs, options }: { psbtHexs: string[]; options?: any }): Promise<string[]> {
195
+ throw new Error("not implemented");
196
+ }
197
+
190
198
  public async requestTransaction(txData: DogeTxData): Promise<{ txId: string } | null> {
191
199
  //txData = createTx;
192
200
  const spendableUtxos = txData?.spendableUtxos;
@@ -213,6 +221,46 @@ export class DogecoinService extends BaseService {
213
221
  }
214
222
  }
215
223
 
224
+ public async send({
225
+ toAddress,
226
+ amount,
227
+ fee = 0,
228
+ options,
229
+ }: {
230
+ toAddress: string;
231
+ amount: number; //satoshis
232
+ fee: number; //satoshis
233
+ options?: { feeRate: number; memo?: string };
234
+ }): Promise<string> {
235
+ if (fee <= 0) {
236
+ throw new Error("fee is required");
237
+ }
238
+ const addresses = await this.accountInfo.getCurrent();
239
+ const { address } = addresses?.[0] || {};
240
+ const txData: DogeTxData = {
241
+ to: toAddress,
242
+ amount: toBitcoin(amount),
243
+ fee: toBitcoin(fee || 0),
244
+ from: address,
245
+ };
246
+ const res: any = await this.requestTransaction(txData);
247
+ return res?.txId || "";
248
+ }
249
+
250
+ public async sendDogecoin({
251
+ toAddress,
252
+ amount,
253
+ options,
254
+ fee,
255
+ }: {
256
+ toAddress: string;
257
+ amount: number;
258
+ fee: number;
259
+ options?: { feeRate: number; memo?: string };
260
+ }): Promise<string> {
261
+ return await this.send({ toAddress, amount, options, fee });
262
+ }
263
+
216
264
  public async getTransactionStatus({ txId }: { txId: string }): Promise<any> {
217
265
  const transaction = await API.getTxDetail(txId);
218
266
  if (!transaction?.txid) {
@@ -6,26 +6,26 @@ import {
6
6
  fromHex,
7
7
  hexToBigInt,
8
8
  http,
9
+ isAddressEqual,
9
10
  isHex,
10
11
  numberToHex,
11
12
  parseTransaction,
12
13
  parseUnits,
13
14
  toHex,
14
15
  Transaction,
15
- isAddressEqual,
16
16
  } from "viem";
17
17
 
18
18
  import { BaseService } from "../base/service";
19
19
  import { getRPCClient } from "./rpc";
20
20
 
21
21
  import {
22
- QueryGasParams,
23
- ITypedData,
22
+ IAccountInfo,
24
23
  INetwork,
24
+ ITypedData,
25
+ QueryGasParams,
26
+ QueryGasResponse,
25
27
  TomoAppInfo,
26
- IAccountInfo,
27
28
  TransactionParams,
28
- QueryGasResponse,
29
29
  } from "../types";
30
30
  import { createErc20TxData, getAllTypeChainIds, isEvmChain } from "./utils";
31
31