turing-wallet-provider 1.4.16 → 1.5.0

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
@@ -276,7 +276,7 @@ interface FTData {
276
276
  name: string;
277
277
  symbol: string;
278
278
  decimal: number;
279
- amount: number | string; // 大数请使用 string
279
+ amount: number;
280
280
  }
281
281
 
282
282
  interface CollectionData {
@@ -802,6 +802,8 @@ const { txid } = await wallet.sendTransaction(params); // txid 为多个 Merge
802
802
 
803
803
  批量请求功能支持一次性提交多个独立的请求,每个请求独立执行,一个请求失败不会影响其他请求的执行。
804
804
 
805
+ 此外,当 `signMessage` 请求需要依赖 `signAssociatedTransaction` 的结果时,可以通过 `dependsOn` 字段将两者关联,详见下方[关联请求](#关联请求)章节。
806
+
805
807
  **限制:** 单次批量请求最多支持 5 个请求。
806
808
 
807
809
  ### 支持的方法
@@ -917,6 +919,142 @@ const mixedOperations = [
917
919
  const results = await wallet.sendBatchRequest(mixedOperations);
918
920
  ```
919
921
 
922
+ ### 关联请求
923
+
924
+ 在某些场景下,`signMessage` 的消息体中需要包含前一个请求生成的交易 txid。由于 txid 在请求前无法确定,因此可以在 `signMessage` 请求上添加 `dependsOn` 字段,让钱包自动完成 txid 的提取和注入。
925
+
926
+ 不添加 `dependsOn` 时,两个请求仍然作为独立请求各自执行,互不影响。
927
+
928
+ #### 支持的第一个方法
929
+
930
+ | 方法 | txid 提取方式 |
931
+ | --- | --- |
932
+ | `signAssociatedTransaction` | 从返回的 `txraws: string[]` 中计算每个 txraw 的 txid |
933
+ | `sendTransaction` | `broadcastEnabled: true` 时从返回的 `txid` 按逗号拆分;`broadcastEnabled: false` 时从返回的 `txraw` 按逗号拆分后计算 txid |
934
+
935
+ 无论哪种方法,最终注入到 `signMessage` 的 `message` JSON 中的都是一个 **txid 字符串数组**。
936
+
937
+ #### 用法
938
+
939
+ 批量请求固定为两个请求:第一个是 `signAssociatedTransaction` 或 `sendTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
940
+
941
+ #### 示例一:signAssociatedTransaction + signMessage
942
+
943
+ ```ts
944
+ const requests = [
945
+ {
946
+ method: "signAssociatedTransaction",
947
+ params: {
948
+ sourceTxraw: "...",
949
+ sourceUtxos: [
950
+ {
951
+ txId: "",
952
+ outputIndex: 0,
953
+ satoshis: 500,
954
+ script: ftcode,
955
+ scriptSigType: "tbc20",
956
+ },
957
+ {
958
+ txId: "",
959
+ outputIndex: 2,
960
+ satoshis: 10000,
961
+ script: p2pkh,
962
+ scriptSigType: "p2pkh",
963
+ },
964
+ ],
965
+ inputs: [
966
+ [
967
+ { outputIndex: 0, scriptSigType: "tbc20" },
968
+ { outputIndex: 2, scriptSigType: "p2pkh" },
969
+ ],
970
+ ],
971
+ outputs: [
972
+ [
973
+ { script: ftcode, satoshis: 500 },
974
+ { script: fttape, satoshis: 0 },
975
+ { script: p2pkh, satoshis: 8000 },
976
+ ],
977
+ ],
978
+ },
979
+ },
980
+ {
981
+ method: "signMessage",
982
+ params: {
983
+ message: JSON.stringify({
984
+ action: "mint",
985
+ amount: 100,
986
+ }),
987
+ encoding: "utf8",
988
+ },
989
+ dependsOn: "txids", // 将 txids 注入到 message JSON 的 "txids" 字段
990
+ },
991
+ ];
992
+
993
+ const results = await wallet.sendBatchRequest(requests);
994
+
995
+ // results[0] => signAssociatedTransaction 的结果: { txraws: string[] }
996
+ // results[1] => signMessage 的结果: { address, pubkey, sig, message }
997
+ // 其中 message 为包含 txids 的完整 JSON,例如:
998
+ // { "action": "mint", "amount": 100, "txids": ["txid1", "txid2", ...] }
999
+ ```
1000
+
1001
+ #### 示例二:sendTransaction + signMessage
1002
+
1003
+ ```ts
1004
+ const requests = [
1005
+ {
1006
+ method: "sendTransaction",
1007
+ params: {
1008
+ flag: "STABLECOIN_CREATE",
1009
+ ft_data: JSON.stringify({
1010
+ name: "USD Test",
1011
+ symbol: "USDT",
1012
+ decimal: 6,
1013
+ amount: 100000000,
1014
+ }),
1015
+ address: "",
1016
+ mint_message: "SourceChain: BSC, TXID: 34434...",
1017
+ broadcastEnabled: true,
1018
+ domain: "",
1019
+ },
1020
+ },
1021
+ {
1022
+ method: "signMessage",
1023
+ params: {
1024
+ message: JSON.stringify({
1025
+ action: "create_stablecoin",
1026
+ }),
1027
+ encoding: "utf8",
1028
+ },
1029
+ dependsOn: "txids", // 将 txids 注入到 message JSON 的 "txids" 字段
1030
+ },
1031
+ ];
1032
+
1033
+ const results = await wallet.sendBatchRequest(requests);
1034
+
1035
+ // results[0] => sendTransaction 的结果: { txid: "txid1,txid2" }
1036
+ // results[1] => signMessage 的结果: { address, pubkey, sig, message }
1037
+ // 其中 message 为包含 txids 的完整 JSON,例如:
1038
+ // { "action": "create_stablecoin", "txids": ["txid1", "txid2"] }
1039
+ ```
1040
+
1041
+ #### 执行流程
1042
+
1043
+ 1. 执行第一个请求(`signAssociatedTransaction` 或 `sendTransaction`)
1044
+ 2. 从结果中提取 txid 数组:
1045
+ - `signAssociatedTransaction`:从 `txraws` 计算每个 txraw 的 txid
1046
+ - `sendTransaction`(`broadcastEnabled: true`):将 `txid` 按逗号拆分
1047
+ - `sendTransaction`(`broadcastEnabled: false`):将 `txraw` 按逗号拆分后计算 txid
1048
+ 3. 解析 `signMessage` 的 `message` JSON,将 txid 数组注入到 `dependsOn` 指定的字段
1049
+ 4. 使用注入后的完整消息执行 `signMessage`
1050
+
1051
+ #### 约束
1052
+
1053
+ - 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction` 或 `sendTransaction`,第二个为 `signMessage`
1054
+ - `dependsOn` 的值为字符串,表示注入到 message JSON 中的字段名
1055
+ - 如果第一个请求执行失败,`signMessage` 也会失败
1056
+ - `signMessage` 的 `message` 参数必须是合法的 JSON 字符串
1057
+
920
1058
  ## evm.sendTransaction
921
1059
 
922
1060
  通过 `evm` 对象发送 EVM 链上的交易,支持原生币和 ERC20 标准代币转账。
@@ -157,6 +157,7 @@ export type BatchRequestMethod =
157
157
  export type BatchRequest = {
158
158
  method: BatchRequestMethod;
159
159
  params: SendTransaction | SignMessage | SignTransaction | SignAssociatedTransaction | Encrypt | Decrypt;
160
+ dependsOn?: string;
160
161
  };
161
162
 
162
163
  export type BatchResponse = Array<
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turing-wallet-provider",
3
- "version": "1.4.16",
3
+ "version": "1.5.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [