turing-wallet-provider 1.4.13 → 1.4.15

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/README.md CHANGED
@@ -18,21 +18,25 @@ root.render(
18
18
  import { useTuringWallet } from "turing-wallet-provider";
19
19
 
20
20
  const wallet = useTuringWallet();
21
- await wallet.connect();
21
+ const addresses = await wallet.connect();
22
+ // 返回地址对象,根据账户类型不同返回不同字段:
23
+ // BVM账户: { tbcAddress, btcAddress }
24
+ // EVM账户: { ethAddress, bnbAddress }
25
+ // 全部账户: { tbcAddress, btcAddress, ethAddress, bnbAddress }
22
26
  ```
23
27
 
24
28
  ## disconnect
25
29
 
26
30
  ```ts
27
31
  const wallet = useTuringWallet();
28
- await wallet.disconnect();
32
+ const result = await wallet.disconnect(); // 返回 true/false
29
33
  ```
30
34
 
31
35
  ## isConnected
32
36
 
33
37
  ```ts
34
38
  const wallet = useTuringWallet();
35
- const ture/false = await wallet.isConnected();
39
+ const result = await wallet.isConnected(); // 返回 true/false
36
40
  ```
37
41
 
38
42
  ## getPubKey
@@ -46,7 +50,11 @@ const { tbcPubKey } = await wallet.getPubKey(); //tbcPubKey为string类型
46
50
 
47
51
  ```ts
48
52
  const wallet = useTuringWallet();
49
- const { tbcAddress } = await wallet.getAddress(); //tbcAddress为string类型
53
+ const addresses = await wallet.getAddress();
54
+ // 返回地址对象,根据账户类型不同返回不同字段:
55
+ // BVM账户: { tbcAddress, btcAddress }
56
+ // EVM账户: { ethAddress, bnbAddress }
57
+ // 全部账户: { tbcAddress, btcAddress, ethAddress, bnbAddress }
50
58
  ```
51
59
 
52
60
  ## getInfo
@@ -719,3 +727,316 @@ const mixedOperations = [
719
727
 
720
728
  const results = await wallet.sendBatchRequest(mixedOperations);
721
729
  ```
730
+
731
+ ## evm.sendTransaction
732
+
733
+ 通过 `evm` 对象发送 EVM 链上的交易,支持原生币和 ERC20 标准代币转账。
734
+
735
+ > **当前支持范围:**
736
+ >
737
+ > - 支持链: 以太坊主网(ETH)、BSC 主网(BNB)
738
+ > - 支持代币: USDT、USDC
739
+
740
+ ### 参数说明
741
+
742
+ ```ts
743
+ interface EvmSendTransaction {
744
+ chainId: number; // EVM 链 ID: 1(以太坊主网) 或 56(BSC主网)
745
+ contractAddress?: string; // ERC20 合约地址,如果为空则转账原生币(ETH/BNB)
746
+ toAddress: string; // 接收地址
747
+ amount: string; // 转账金额,字符串格式,单位为 token 的最小单位
748
+ broadcastEnabled?: boolean; // 是否广播交易,默认为 true
749
+ }
750
+
751
+ interface EvmSendTransactionResponse {
752
+ txid?: string; // 交易哈希(广播成功时返回)
753
+ txraw?: string; // 交易原始数据(broadcastEnabled为false时返回)
754
+ error?: string; // 错误信息
755
+ }
756
+ ```
757
+
758
+ ### 支持的链和代币
759
+
760
+ | 链 | chainId | 原生币 | USDT 合约地址 | USDC 合约地址 |
761
+ | ---------- | ------- | ------ | ------------------------------------------ | ------------------------------------------ |
762
+ | 以太坊主网 | 1 | ETH | 0xdAC17F958D2ee523a2206206994597C13D831ec7 | 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48 |
763
+ | BSC 主网 | 56 | BNB | 0x55d398326f99059fF775485246999027B3197955 | 0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d |
764
+
765
+ ### 使用示例
766
+
767
+ #### 转账原生币
768
+
769
+ ```ts
770
+ const wallet = useTuringWallet();
771
+
772
+ // 以太坊转账 ETH
773
+ const result = await wallet.evm.sendTransaction({
774
+ chainId: 1,
775
+ toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
776
+ amount: "1000000000000000000", // 1 ETH (18位小数)
777
+ broadcastEnabled: true,
778
+ });
779
+
780
+ if (result.txid) {
781
+ console.log("交易哈希:", result.txid);
782
+ } else if (result.error) {
783
+ console.error("交易失败:", result.error);
784
+ }
785
+ ```
786
+
787
+ #### 转账 ERC20 代币
788
+
789
+ ```ts
790
+ const wallet = useTuringWallet();
791
+
792
+ // BSC 上转账 USDT
793
+ const result = await wallet.evm.sendTransaction({
794
+ chainId: 56,
795
+ contractAddress: "0x55d398326f99059fF775485246999027B3197955", // BSC USDT 合约
796
+ toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
797
+ amount: "1000000000000000000", // 1 USDT (18位小数)
798
+ broadcastEnabled: true,
799
+ });
800
+
801
+ // 以太坊主网转账 USDC
802
+ const result2 = await wallet.evm.sendTransaction({
803
+ chainId: 1,
804
+ contractAddress: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // ETH USDC 合约
805
+ toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
806
+ amount: "1000000", // 1 USDC (6位小数)
807
+ broadcastEnabled: true,
808
+ });
809
+
810
+ if (result.txid) {
811
+ console.log("交易哈希:", result.txid);
812
+ } else if (result.error) {
813
+ console.error("交易失败:", result.error);
814
+ }
815
+ ```
816
+
817
+ #### 不广播,仅返回签名交易
818
+
819
+ ```ts
820
+ const wallet = useTuringWallet();
821
+
822
+ const result = await wallet.evm.sendTransaction({
823
+ chainId: 1,
824
+ toAddress: "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
825
+ amount: "1000000000000000000",
826
+ broadcastEnabled: false, // 不广播
827
+ });
828
+
829
+ if (result.txraw) {
830
+ console.log("交易原始数据:", result.txraw);
831
+ // 可以自行广播这个交易
832
+ }
833
+ ```
834
+
835
+ ## btc.sendTransaction
836
+
837
+ 通过 `btc` 对象发送 BTC 链上的交易。
838
+
839
+ ### 参数说明
840
+
841
+ ```ts
842
+ interface BtcSendTransaction {
843
+ toAddress: string; // 接收地址
844
+ amount: string; // 转账金额,字符串格式,单位为 satoshis
845
+ broadcastEnabled?: boolean; // 是否广播交易,默认为 true
846
+ }
847
+
848
+ interface BtcSendTransactionResponse {
849
+ txid?: string; // 交易哈希(广播成功时返回)
850
+ txraw?: string; // 交易原始数据(broadcastEnabled为false时返回)
851
+ error?: string; // 错误信息
852
+ }
853
+ ```
854
+
855
+ ### 使用示例
856
+
857
+ #### 转账 BTC
858
+
859
+ ```ts
860
+ const wallet = useTuringWallet();
861
+
862
+ const result = await wallet.btc.sendTransaction({
863
+ toAddress: "bc1qxyz...",
864
+ amount: "100000", // 100000 satoshis
865
+ broadcastEnabled: true,
866
+ });
867
+
868
+ if (result.txid) {
869
+ console.log("交易哈希:", result.txid);
870
+ } else if (result.error) {
871
+ console.error("交易失败:", result.error);
872
+ }
873
+ ```
874
+
875
+ #### 不广播,仅返回签名交易
876
+
877
+ ```ts
878
+ const wallet = useTuringWallet();
879
+
880
+ const result = await wallet.btc.sendTransaction({
881
+ toAddress: "bc1qxyz...",
882
+ amount: "100000",
883
+ broadcastEnabled: false,
884
+ });
885
+
886
+ if (result.txraw) {
887
+ console.log("交易原始数据:", result.txraw);
888
+ }
889
+ ```
890
+
891
+ ## btc.signTransaction
892
+
893
+ 通过 `btc` 对象对单个 BTC 裸交易进行签名,支持 legacy、segwit_v0、taproot 三种签名类型。taproot 类型下通过 `leafHashesHex` 区分 key path 和 script path:对应输入为 `undefined` 则走 key path,有值则走 script path。
894
+
895
+ ### 参数说明
896
+
897
+ ```ts
898
+ type BtcSigHashType = "legacy" | "segwit_v0" | "taproot";
899
+
900
+ interface BtcSignTransaction {
901
+ txHex: string; // 裸交易 hex
902
+ type: BtcSigHashType; // 签名哈希类型
903
+ prevOutScriptsHex: string[]; // 每个输入对应的前置输出脚本 hex
904
+ values?: number[]; // 每个输入对应的金额(satoshis),segwit_v0/taproot 必填
905
+ leafHashesHex?: (string | undefined)[]; // 每个输入对应的叶子哈希,仅 taproot 类型使用,undefined 表示 key path,有值表示 script path
906
+ }
907
+
908
+ interface BtcSignTransactionResponse {
909
+ sigs?: string[]; // 每个输入对应的签名 hex
910
+ error?: string; // 错误信息
911
+ }
912
+ ```
913
+
914
+ ### 使用示例
915
+
916
+ #### Legacy (P2PKH) 签名
917
+
918
+ ```ts
919
+ const wallet = useTuringWallet();
920
+
921
+ const result = await wallet.btc.signTransaction({
922
+ txHex: "0200000001...",
923
+ type: "legacy",
924
+ prevOutScriptsHex: ["76a914...88ac"],
925
+ });
926
+
927
+ if (result.sigs) {
928
+ console.log("签名列表:", result.sigs);
929
+ } else if (result.error) {
930
+ console.error("签名失败:", result.error);
931
+ }
932
+ ```
933
+
934
+ #### SegWit V0 (P2WPKH) 签名
935
+
936
+ ```ts
937
+ const wallet = useTuringWallet();
938
+
939
+ const result = await wallet.btc.signTransaction({
940
+ txHex: "0200000001...",
941
+ type: "segwit_v0",
942
+ prevOutScriptsHex: ["76a914...88ac"],
943
+ values: [100000],
944
+ });
945
+
946
+ if (result.sigs) {
947
+ console.log("签名列表:", result.sigs);
948
+ }
949
+ ```
950
+
951
+ #### Taproot Key Path 签名
952
+
953
+ ```ts
954
+ const wallet = useTuringWallet();
955
+
956
+ const result = await wallet.btc.signTransaction({
957
+ txHex: "0200000001...",
958
+ type: "taproot",
959
+ prevOutScriptsHex: ["5120..."],
960
+ values: [100000],
961
+ // leafHashesHex 不传或对应位置为 undefined,走 key path
962
+ });
963
+
964
+ if (result.sigs) {
965
+ console.log("签名列表:", result.sigs);
966
+ }
967
+ ```
968
+
969
+ #### Taproot Script Path 签名
970
+
971
+ ```ts
972
+ const wallet = useTuringWallet();
973
+
974
+ const result = await wallet.btc.signTransaction({
975
+ txHex: "0200000001...",
976
+ type: "taproot",
977
+ prevOutScriptsHex: ["5120..."],
978
+ values: [100000],
979
+ leafHashesHex: ["ab12cd34..."], // 对应输入有 leafHash,走 script path
980
+ });
981
+
982
+ if (result.sigs) {
983
+ console.log("签名列表:", result.sigs);
984
+ }
985
+ ```
986
+
987
+ ## btc.sendBatchRequest
988
+
989
+ 通过 `btc` 对象批量提交 BTC 相关请求,每个请求独立执行,一个失败不影响其他请求。
990
+
991
+ ### 支持的方法
992
+
993
+ - `sendTransaction` - 发送交易
994
+ - `signTransaction` - 签名交易
995
+
996
+ ### 参数说明
997
+
998
+ ```ts
999
+ type BtcBatchRequestMethod = "sendTransaction" | "signTransaction";
1000
+
1001
+ interface BtcBatchRequest {
1002
+ method: BtcBatchRequestMethod;
1003
+ params: BtcSendTransaction | BtcSignTransaction;
1004
+ }
1005
+
1006
+ type BtcBatchResponse = Array<BtcSendTransactionResponse | BtcSignTransactionResponse>;
1007
+ ```
1008
+
1009
+ ### 使用示例
1010
+
1011
+ ```ts
1012
+ const wallet = useTuringWallet();
1013
+
1014
+ const requests = [
1015
+ {
1016
+ method: "sendTransaction",
1017
+ params: {
1018
+ toAddress: "bc1qxyz...",
1019
+ amount: "100000",
1020
+ broadcastEnabled: true,
1021
+ },
1022
+ },
1023
+ {
1024
+ method: "signTransaction",
1025
+ params: {
1026
+ txHex: "0200000001...",
1027
+ type: "legacy",
1028
+ prevOutScriptsHex: ["76a914...88ac"],
1029
+ },
1030
+ },
1031
+ ];
1032
+
1033
+ const results = await wallet.btc.sendBatchRequest(requests);
1034
+
1035
+ results.forEach((result, index) => {
1036
+ if (result.error) {
1037
+ console.error(`Request ${index + 1} failed:`, result.error);
1038
+ } else {
1039
+ console.log(`Request ${index + 1} success:`, result);
1040
+ }
1041
+ });
1042
+ ```
@@ -3,9 +3,14 @@ export type PubKey = {
3
3
  };
4
4
 
5
5
  export type Address = {
6
- tbcAddress: string;
6
+ tbcAddress?: string;
7
+ btcAddress?: string;
8
+ ethAddress?: string;
9
+ bnbAddress?: string;
7
10
  };
8
11
 
12
+ export type ConnectResponse = Address;
13
+
9
14
  export type Info = {
10
15
  name: string;
11
16
  platform: string;
@@ -156,9 +161,71 @@ export type BatchResponse = Array<
156
161
  | DecryptResponse
157
162
  >;
158
163
 
164
+ export type EvmSendTransaction = {
165
+ chainId: number;
166
+ contractAddress?: string;
167
+ toAddress: string;
168
+ amount: string;
169
+ broadcastEnabled?: boolean;
170
+ };
171
+
172
+ export type EvmSendTransactionResponse = {
173
+ txid?: string;
174
+ txraw?: string;
175
+ error?: string;
176
+ };
177
+
178
+ export type EvmProvider = {
179
+ sendTransaction: (params: EvmSendTransaction) => Promise<EvmSendTransactionResponse | undefined>;
180
+ };
181
+
182
+ export type BtcSendTransaction = {
183
+ toAddress: string;
184
+ amount: string;
185
+ broadcastEnabled?: boolean;
186
+ };
187
+
188
+ export type BtcSendTransactionResponse = {
189
+ txid?: string;
190
+ txraw?: string;
191
+ error?: string;
192
+ };
193
+
194
+ export type BtcSigHashType = "legacy" | "segwit_v0" | "taproot";
195
+
196
+ export type BtcSignTransaction = {
197
+ txHex: string;
198
+ type: BtcSigHashType;
199
+ prevOutScriptsHex: string[];
200
+ values?: number[];
201
+ leafHashesHex?: (string | undefined)[];
202
+ };
203
+
204
+ export type BtcSignTransactionResponse = {
205
+ sigs?: string[];
206
+ error?: string;
207
+ };
208
+
209
+ export type BtcBatchRequestMethod = "sendTransaction" | "signTransaction";
210
+
211
+ export type BtcBatchRequest = {
212
+ method: BtcBatchRequestMethod;
213
+ params: BtcSendTransaction | BtcSignTransaction;
214
+ };
215
+
216
+ export type BtcBatchResponse = Array<
217
+ BtcSendTransactionResponse | BtcSignTransactionResponse
218
+ >;
219
+
220
+ export type BtcProvider = {
221
+ sendTransaction: (params: BtcSendTransaction) => Promise<BtcSendTransactionResponse | undefined>;
222
+ signTransaction: (params: BtcSignTransaction) => Promise<BtcSignTransactionResponse | undefined>;
223
+ sendBatchRequest: (requests: BtcBatchRequest[]) => Promise<BtcBatchResponse | undefined>;
224
+ };
225
+
159
226
  export type TuringProviderType = {
160
227
  isReady: boolean;
161
- connect: () => Promise<string | undefined>;
228
+ connect: () => Promise<ConnectResponse | undefined>;
162
229
  disconnect: () => Promise<boolean>;
163
230
  isConnected: () => Promise<boolean>;
164
231
  getPubKey: () => Promise<PubKey | undefined>;
@@ -179,4 +246,6 @@ export type TuringProviderType = {
179
246
  params: SignAssociatedTransaction
180
247
  ) => Promise<SignAssociatedTransactionResponse | undefined>;
181
248
  sendBatchRequest: (requests: BatchRequest[]) => Promise<BatchResponse | undefined>;
249
+ evm: EvmProvider;
250
+ btc: BtcProvider;
182
251
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turing-wallet-provider",
3
- "version": "1.4.13",
3
+ "version": "1.4.15",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [