turing-wallet-provider 1.5.4 → 1.5.6
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 +18 -130
- package/dist/types/providerTypes.d.ts +1 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -270,8 +270,8 @@ interface Input {
|
|
|
270
270
|
| "tbc20_coin_contract" // 稳定币在合约/swap 场景下的解锁(FT.getFTunlockSwap + isCoin)
|
|
271
271
|
| "other"; // 脚本签名类型
|
|
272
272
|
unfinishedScriptSig?: string; // "other" 类型的自定义脚本模板(hex 格式),签名部分用 097369676e6174757265 替代
|
|
273
|
-
ftVersion?: 1 | 2;
|
|
274
|
-
contractTxId?: string; // "tbc20_contract"/"tbc20_coin_contract" 类型的合约交易 ID
|
|
273
|
+
ftVersion?: 1 | 2 | 3; // "tbc20_contract" / "tbc20_coin_contract" 类型的 FT 版本
|
|
274
|
+
contractTxId?: string; // "tbc20_contract" / "tbc20_coin_contract" 类型的合约交易 ID
|
|
275
275
|
}
|
|
276
276
|
|
|
277
277
|
interface Output {
|
|
@@ -394,16 +394,16 @@ const { txraws } = await Turing.signAssociatedTransaction({
|
|
|
394
394
|
});
|
|
395
395
|
```
|
|
396
396
|
|
|
397
|
-
###
|
|
397
|
+
### 稳定币转移 (tbc20_coin)
|
|
398
398
|
|
|
399
|
-
稳定币是一种特殊的 FT
|
|
399
|
+
稳定币是一种特殊的 FT,转移时的解锁脚本与普通 FT 不同,所以提供了专用的 `scriptSigType`:
|
|
400
400
|
|
|
401
401
|
- `"tbc20_coin"`:稳定币普通转账解锁
|
|
402
|
-
- `"tbc20_coin_contract"
|
|
402
|
+
- `"tbc20_coin_contract"`:稳定币在合约/swap 场景下的解锁(需额外提供 `contractTxId` 和 `ftVersion`)
|
|
403
403
|
|
|
404
404
|
#### 子交易 (`inputs` / `outputs`)
|
|
405
405
|
|
|
406
|
-
只要把对应输入的 `scriptSigType` 标成 `"tbc20_coin"
|
|
406
|
+
只要把对应输入的 `scriptSigType` 标成 `"tbc20_coin"`(合约场景用 `"tbc20_coin_contract"` 并补充 `contractTxId` / `ftVersion`)即可,**其它字段与普通 FT 写法完全一致**,无需关心 sequence / nLockTime。
|
|
407
407
|
|
|
408
408
|
#### 源交易 (`sourceTxraw`)
|
|
409
409
|
|
|
@@ -437,7 +437,7 @@ tx.setLockTime(lockTimeMax);
|
|
|
437
437
|
const sourceTxraw = tx.uncheckedSerialize();
|
|
438
438
|
```
|
|
439
439
|
|
|
440
|
-
> 对应的 `sourceUtxos` 条目仍要填 `"tbc20_coin"
|
|
440
|
+
> 对应的 `sourceUtxos` 条目仍要填 `"tbc20_coin"`。
|
|
441
441
|
|
|
442
442
|
#### 稳定币示例
|
|
443
443
|
|
|
@@ -484,17 +484,6 @@ const { txraws } = await Turing.signAssociatedTransaction({
|
|
|
484
484
|
});
|
|
485
485
|
```
|
|
486
486
|
|
|
487
|
-
如果稳定币要走合约 / swap 路径,把 `scriptSigType` 改成 `"tbc20_coin_contract"`,并附上 `contractTxId` 与 `ftVersion`:
|
|
488
|
-
|
|
489
|
-
```ts
|
|
490
|
-
{
|
|
491
|
-
outputIndex: 0,
|
|
492
|
-
scriptSigType: "tbc20_coin_contract",
|
|
493
|
-
contractTxId: "<合约交易 ID>",
|
|
494
|
-
ftVersion: 2,
|
|
495
|
-
}
|
|
496
|
-
```
|
|
497
|
-
|
|
498
487
|
## sendTransaction
|
|
499
488
|
|
|
500
489
|
使用钱包发送交易。支持多种交易类型,包括 P2PKH、NFT 操作、FT 操作和 PoolNFT 操作。
|
|
@@ -525,7 +514,7 @@ interface NFTData {
|
|
|
525
514
|
}
|
|
526
515
|
|
|
527
516
|
interface RequestParam {
|
|
528
|
-
flag: "P2PKH" | "COLLECTION_CREATE" | "NFT_CREATE" | "NFT_TRANSFER" | "FT_MINT" | "FT_TRANSFER" | "FT_MERGE" | "POOLNFT_MINT" | "POOLNFT_INIT" | "POOLNFT_LP_INCREASE" | "POOLNFT_LP_CONSUME" | "POOLNFT_LP_BURN" | "POOLNFT_SWAP_TO_TOKEN" | "POOLNFT_SWAP_TO_TBC" | "POOLNFT_MERGE" | "FTLP_MERGE" | "
|
|
517
|
+
flag: "P2PKH" | "COLLECTION_CREATE" | "NFT_CREATE" | "NFT_TRANSFER" | "FT_MINT" | "FT_TRANSFER" | "FT_MERGE" | "POOLNFT_MINT" | "POOLNFT_INIT" | "POOLNFT_LP_INCREASE" | "POOLNFT_LP_CONSUME" | "POOLNFT_LP_BURN" | "POOLNFT_SWAP_TO_TOKEN" | "POOLNFT_SWAP_TO_TBC" | "POOLNFT_MERGE" | "FTLP_MERGE" | "STABLECOIN_TRANSFER" | "STABLECOIN_MERGE";
|
|
529
518
|
address?: string;
|
|
530
519
|
satoshis?: number | string; // 单位为 satoshis,大数请使用 string
|
|
531
520
|
collection_data?: string;
|
|
@@ -533,7 +522,7 @@ interface RequestParam {
|
|
|
533
522
|
nft_data?: string;
|
|
534
523
|
collection_id?: string;
|
|
535
524
|
nft_contract_address?: string;
|
|
536
|
-
ft_contract_address?: string; // FT 或稳定币合约交易 ID
|
|
525
|
+
ft_contract_address?: string; // FT 或稳定币合约交易 ID
|
|
537
526
|
tbc_amount?: number | string; // 大数请使用 string
|
|
538
527
|
ft_amount?: number | string; // 大数请使用 string
|
|
539
528
|
merge_times?: number;
|
|
@@ -547,11 +536,8 @@ interface RequestParam {
|
|
|
547
536
|
lpPlan?: 1 | 2 | 3 | 4 | 5; // 默认 1
|
|
548
537
|
domain?: string;
|
|
549
538
|
isLockTime?: boolean;
|
|
550
|
-
lockTime?: number | string; // 锁仓至指定区块高度(POOLNFT
|
|
539
|
+
lockTime?: number | string; // 锁仓至指定区块高度(POOLNFT 相关),大数请使用 string
|
|
551
540
|
broadcastEnabled?: boolean;
|
|
552
|
-
mint_message?: string; // 铸造/增发跨链信息(STABLECOIN_CREATE / STABLECOIN_MINT 使用)
|
|
553
|
-
utxo_txid?: string; // 目标 UTXO 的交易 ID(STABLECOIN_FREEZE / STABLECOIN_UNFREEZE 使用)
|
|
554
|
-
utxo_index?: number; // 目标 UTXO 的输出索引(STABLECOIN_FREEZE / STABLECOIN_UNFREEZE 使用)
|
|
555
541
|
}
|
|
556
542
|
|
|
557
543
|
const params = [param: RequestParam];
|
|
@@ -902,54 +888,6 @@ const { txid } = await wallet.sendTransaction(params); // txid 为多个 Merge
|
|
|
902
888
|
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
903
889
|
```
|
|
904
890
|
|
|
905
|
-
### STABLECOIN_CREATE
|
|
906
|
-
|
|
907
|
-
发行稳定币合约(仅需执行一次)。稳定币继承自 FT,构造方式与 FT 相同。
|
|
908
|
-
|
|
909
|
-
```ts
|
|
910
|
-
const params = [
|
|
911
|
-
{
|
|
912
|
-
flag: "STABLECOIN_CREATE", // 必填
|
|
913
|
-
ft_data: JSON.stringify({ // 必填,JSON 格式的 FTData
|
|
914
|
-
name: "USD Test",
|
|
915
|
-
symbol: "USDT",
|
|
916
|
-
decimal: 6,
|
|
917
|
-
amount: 100000000,
|
|
918
|
-
}),
|
|
919
|
-
address: "", // 必填,初始接收地址(一般是管理员自身)
|
|
920
|
-
mint_message: "SourceChain: BSC, TXID: 34434...", // 必填,跨链信息,起始链名称和交易 id
|
|
921
|
-
broadcastEnabled: true, // 可选,默认 true
|
|
922
|
-
domain: "", // 可选
|
|
923
|
-
},
|
|
924
|
-
];
|
|
925
|
-
|
|
926
|
-
const { txid } = await wallet.sendTransaction(params); // txid 有两个,用逗号隔开,第一个 txid 即为稳定币合约 ID
|
|
927
|
-
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时,返回的 txraw 有两个,用逗号隔开,第一个 txraw 对应的 txid 即为稳定币合约 ID,需批量广播,保证前面的 txraw 先广播
|
|
928
|
-
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
929
|
-
```
|
|
930
|
-
|
|
931
|
-
### STABLECOIN_MINT
|
|
932
|
-
|
|
933
|
-
增发稳定币(仅管理员可操作)。
|
|
934
|
-
|
|
935
|
-
```ts
|
|
936
|
-
const params = [
|
|
937
|
-
{
|
|
938
|
-
flag: "STABLECOIN_MINT", // 必填
|
|
939
|
-
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
940
|
-
address: "", // 必填,接收新铸稳定币的地址
|
|
941
|
-
ft_amount: 50000, // 必填,增发数量,大数请使用 string
|
|
942
|
-
mint_message: "SourceChain: BSC, TXID: 34434...", // 必填,跨链信息,起始链名称和交易 id
|
|
943
|
-
broadcastEnabled: true, // 可选,默认 true
|
|
944
|
-
domain: "", // 可选
|
|
945
|
-
},
|
|
946
|
-
];
|
|
947
|
-
|
|
948
|
-
const { txid } = await wallet.sendTransaction(params);
|
|
949
|
-
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
950
|
-
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
951
|
-
```
|
|
952
|
-
|
|
953
891
|
### STABLECOIN_TRANSFER
|
|
954
892
|
|
|
955
893
|
转移稳定币。
|
|
@@ -958,7 +896,7 @@ const { txid } = await wallet.sendTransaction(params);
|
|
|
958
896
|
const params = [
|
|
959
897
|
{
|
|
960
898
|
flag: "STABLECOIN_TRANSFER", // 必填
|
|
961
|
-
ft_contract_address: "", // 必填,稳定币合约交易 ID
|
|
899
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID
|
|
962
900
|
address: "", // 必填,接收地址
|
|
963
901
|
ft_amount: 1000, // 必填,转移数量,大数请使用 string
|
|
964
902
|
tbc_amount: 0, // 可选,同时转 TBC 和稳定币时设置此值
|
|
@@ -972,51 +910,6 @@ const { txid } = await wallet.sendTransaction(params);
|
|
|
972
910
|
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
973
911
|
```
|
|
974
912
|
|
|
975
|
-
### STABLECOIN_FREEZE
|
|
976
|
-
|
|
977
|
-
冻结指定地址的稳定币 UTXO(仅管理员可操作)。冻结后,持有者须等到冻结到期才能使用该 UTXO。
|
|
978
|
-
|
|
979
|
-
```ts
|
|
980
|
-
const params = [
|
|
981
|
-
{
|
|
982
|
-
flag: "STABLECOIN_FREEZE", // 必填
|
|
983
|
-
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
984
|
-
address: "", // 必填,被冻结的目标地址
|
|
985
|
-
utxo_txid: "", // 必填,目标稳定币 UTXO 的交易 ID
|
|
986
|
-
utxo_index: 0, // 必填,目标稳定币 UTXO 的输出索引
|
|
987
|
-
lockTime: 1774410989, // 必填,冻结至指定 unix 时间戳
|
|
988
|
-
broadcastEnabled: true, // 可选,默认 true
|
|
989
|
-
domain: "", // 可选
|
|
990
|
-
},
|
|
991
|
-
];
|
|
992
|
-
|
|
993
|
-
const { txid } = await wallet.sendTransaction(params);
|
|
994
|
-
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
995
|
-
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
996
|
-
```
|
|
997
|
-
|
|
998
|
-
### STABLECOIN_UNFREEZE
|
|
999
|
-
|
|
1000
|
-
解冻指定地址的稳定币 UTXO(仅管理员可操作)。
|
|
1001
|
-
|
|
1002
|
-
```ts
|
|
1003
|
-
const params = [
|
|
1004
|
-
{
|
|
1005
|
-
flag: "STABLECOIN_UNFREEZE", // 必填
|
|
1006
|
-
ft_contract_address: "", // 必填,稳定币合约交易 ID(STABLECOIN_CREATE 返回的第一个 txid)
|
|
1007
|
-
address: "", // 必填,被解冻的目标地址
|
|
1008
|
-
utxo_txid: "", // 必填,目标稳定币 UTXO 的交易 ID
|
|
1009
|
-
utxo_index: 0, // 必填,目标稳定币 UTXO 的输出索引
|
|
1010
|
-
broadcastEnabled: true, // 可选,默认 true
|
|
1011
|
-
domain: "", // 可选
|
|
1012
|
-
},
|
|
1013
|
-
];
|
|
1014
|
-
|
|
1015
|
-
const { txid } = await wallet.sendTransaction(params);
|
|
1016
|
-
// const { txraw } = await wallet.sendTransaction(params); // broadcastEnabled 为 false 时
|
|
1017
|
-
// const { error } = await wallet.sendTransaction(params); // 发生错误时
|
|
1018
|
-
```
|
|
1019
|
-
|
|
1020
913
|
### STABLECOIN_MERGE
|
|
1021
914
|
|
|
1022
915
|
合并稳定币 UTXO(要求所有 coinutxo 均已上链)。
|
|
@@ -1025,7 +918,7 @@ const { txid } = await wallet.sendTransaction(params);
|
|
|
1025
918
|
const params = [
|
|
1026
919
|
{
|
|
1027
920
|
flag: "STABLECOIN_MERGE", // 必填
|
|
1028
|
-
ft_contract_address: "", // 必填,稳定币合约交易 ID
|
|
921
|
+
ft_contract_address: "", // 必填,稳定币合约交易 ID
|
|
1029
922
|
domain: "", // 可选
|
|
1030
923
|
},
|
|
1031
924
|
];
|
|
@@ -1241,15 +1134,10 @@ const requests = [
|
|
|
1241
1134
|
{
|
|
1242
1135
|
method: "sendTransaction",
|
|
1243
1136
|
params: {
|
|
1244
|
-
flag: "
|
|
1245
|
-
|
|
1246
|
-
name: "USD Test",
|
|
1247
|
-
symbol: "USDT",
|
|
1248
|
-
decimal: 6,
|
|
1249
|
-
amount: 100000000,
|
|
1250
|
-
}),
|
|
1137
|
+
flag: "STABLECOIN_TRANSFER",
|
|
1138
|
+
ft_contract_address: "",
|
|
1251
1139
|
address: "",
|
|
1252
|
-
|
|
1140
|
+
ft_amount: 1000,
|
|
1253
1141
|
broadcastEnabled: true,
|
|
1254
1142
|
domain: "",
|
|
1255
1143
|
},
|
|
@@ -1258,7 +1146,7 @@ const requests = [
|
|
|
1258
1146
|
method: "signMessage",
|
|
1259
1147
|
params: {
|
|
1260
1148
|
message: JSON.stringify({
|
|
1261
|
-
action: "
|
|
1149
|
+
action: "transfer_stablecoin",
|
|
1262
1150
|
}),
|
|
1263
1151
|
encoding: "utf8",
|
|
1264
1152
|
},
|
|
@@ -1268,10 +1156,10 @@ const requests = [
|
|
|
1268
1156
|
|
|
1269
1157
|
const results = await wallet.sendBatchRequest(requests);
|
|
1270
1158
|
|
|
1271
|
-
// results[0] => sendTransaction 的结果: { txid: "txid1
|
|
1159
|
+
// results[0] => sendTransaction 的结果: { txid: "txid1" }
|
|
1272
1160
|
// results[1] => signMessage 的结果: { address, pubkey, sig, message }
|
|
1273
1161
|
// 其中 message 为包含 txids 的完整 JSON,例如:
|
|
1274
|
-
// { "action": "
|
|
1162
|
+
// { "action": "transfer_stablecoin", "txids": ["txid1"] }
|
|
1275
1163
|
```
|
|
1276
1164
|
|
|
1277
1165
|
#### 执行流程
|
|
@@ -43,11 +43,7 @@ export type TransactionFlag =
|
|
|
43
43
|
| "POOLNFT_SWAP_TO_TBC"
|
|
44
44
|
| "POOLNFT_MERGE"
|
|
45
45
|
| "FTLP_MERGE"
|
|
46
|
-
| "STABLECOIN_CREATE"
|
|
47
|
-
| "STABLECOIN_MINT"
|
|
48
46
|
| "STABLECOIN_TRANSFER"
|
|
49
|
-
| "STABLECOIN_FREEZE"
|
|
50
|
-
| "STABLECOIN_UNFREEZE"
|
|
51
47
|
| "STABLECOIN_MERGE";
|
|
52
48
|
|
|
53
49
|
|
|
@@ -76,9 +72,6 @@ export type SendTransaction = {
|
|
|
76
72
|
isLockTime?: boolean;
|
|
77
73
|
lockTime?: number | string;
|
|
78
74
|
broadcastEnabled?: boolean;
|
|
79
|
-
mint_message?: string;
|
|
80
|
-
utxo_txid?: string;
|
|
81
|
-
utxo_index?: number;
|
|
82
75
|
};
|
|
83
76
|
|
|
84
77
|
export type SendTransactionResponse = {
|
|
@@ -136,7 +129,7 @@ export type Input = {
|
|
|
136
129
|
outputIndex: number;
|
|
137
130
|
scriptSigType: "p2pkh" | "tbc20" | "tbc20_contract" | "tbc20_coin" | "tbc20_coin_contract" | "other";
|
|
138
131
|
unfinishedScriptSig?: string;
|
|
139
|
-
ftVersion?: 1 | 2;
|
|
132
|
+
ftVersion?: 1 | 2 | 3;
|
|
140
133
|
contractTxId?: string;
|
|
141
134
|
};
|
|
142
135
|
|