turing-wallet-provider 1.4.16 → 1.4.17

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,88 @@ const mixedOperations = [
917
919
  const results = await wallet.sendBatchRequest(mixedOperations);
918
920
  ```
919
921
 
922
+ ### 关联请求
923
+
924
+ 在某些场景下,`signMessage` 的消息体中需要包含 `signAssociatedTransaction` 生成的交易 txid。由于 txid 需要从签名后的 `txraws` 中计算得出,无法提前填写,因此可以在 `signMessage` 请求上添加 `dependsOn` 字段,让钱包自动完成 txid 的计算和注入。
925
+
926
+ 不添加 `dependsOn` 时,`signAssociatedTransaction` 和 `signMessage` 仍然作为独立请求各自执行,互不影响。
927
+
928
+ #### 用法
929
+
930
+ 批量请求固定为两个请求:第一个是 `signAssociatedTransaction`,第二个是 `signMessage`。在 `signMessage` 上添加 `dependsOn` 字段,指定将 txids 注入到消息 JSON 的哪个字段名即可。
931
+
932
+ ```ts
933
+ const requests = [
934
+ {
935
+ method: "signAssociatedTransaction",
936
+ params: {
937
+ sourceTxraw: "...",
938
+ sourceUtxos: [
939
+ {
940
+ txId: "",
941
+ outputIndex: 0,
942
+ satoshis: 500,
943
+ script: ftcode,
944
+ scriptSigType: "tbc20",
945
+ },
946
+ {
947
+ txId: "",
948
+ outputIndex: 2,
949
+ satoshis: 10000,
950
+ script: p2pkh,
951
+ scriptSigType: "p2pkh",
952
+ },
953
+ ],
954
+ inputs: [
955
+ [
956
+ { outputIndex: 0, scriptSigType: "tbc20" },
957
+ { outputIndex: 2, scriptSigType: "p2pkh" },
958
+ ],
959
+ ],
960
+ outputs: [
961
+ [
962
+ { script: ftcode, satoshis: 500 },
963
+ { script: fttape, satoshis: 0 },
964
+ { script: p2pkh, satoshis: 8000 },
965
+ ],
966
+ ],
967
+ },
968
+ },
969
+ {
970
+ method: "signMessage",
971
+ params: {
972
+ message: JSON.stringify({
973
+ action: "mint",
974
+ amount: 100,
975
+ }),
976
+ encoding: "utf8",
977
+ },
978
+ dependsOn: "txids", // 将 txids 注入到 message JSON 的 "txids" 字段
979
+ },
980
+ ];
981
+
982
+ const results = await wallet.sendBatchRequest(requests);
983
+
984
+ // results[0] => signAssociatedTransaction 的结果: { txraws: string[] }
985
+ // results[1] => signMessage 的结果: { address, pubkey, sig, message }
986
+ // 其中 message 为包含 txids 的完整 JSON,例如:
987
+ // { "action": "mint", "amount": 100, "txids": ["txid1", "txid2", ...] }
988
+ ```
989
+
990
+ #### 执行流程
991
+
992
+ 1. 执行 `signAssociatedTransaction`,得到 `txraws`
993
+ 2. 从 `txraws` 计算出 txid 数组
994
+ 3. 解析 `signMessage` 的 `message` JSON,将 txid 数组注入到 `dependsOn` 指定的字段
995
+ 4. 使用注入后的完整消息执行 `signMessage`
996
+
997
+ #### 约束
998
+
999
+ - 批量请求必须恰好包含两个请求:第一个为 `signAssociatedTransaction`,第二个为 `signMessage`
1000
+ - `dependsOn` 的值为字符串,表示注入到 message JSON 中的字段名
1001
+ - 如果 `signAssociatedTransaction` 执行失败,`signMessage` 也会失败
1002
+ - `signMessage` 的 `message` 参数必须是合法的 JSON 字符串
1003
+
920
1004
  ## evm.sendTransaction
921
1005
 
922
1006
  通过 `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.4.17",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [