turing-wallet-provider 1.2.9 → 1.3.1

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
@@ -1,6 +1,6 @@
1
1
  # connect
2
2
 
3
- ```tsx
3
+ ```ts
4
4
  npm install turing-wallet-provider@latest
5
5
 
6
6
  import { TuringProvider } from "turing-wallet-provider";
@@ -12,7 +12,7 @@ root.render(
12
12
  );
13
13
  ```
14
14
 
15
- ```tsx
15
+ ```ts
16
16
  import { useTuringsWallet } from "turing-wallet-provider";
17
17
 
18
18
  const wallet = useTuringsWallet();
@@ -21,77 +21,50 @@ await wallet.connect();
21
21
 
22
22
  ## disconnect
23
23
 
24
- ```tsx
24
+ ```ts
25
25
  const wallet = useTuringsWallet();
26
26
  await wallet.disconnect();
27
27
  ```
28
28
 
29
29
  ## isConnected
30
30
 
31
- ```tsx
31
+ ```ts
32
32
  const wallet = useTuringsWallet();
33
33
  const ture/false = await wallet.isConnected();
34
34
  ```
35
35
 
36
36
  ## getPubKey
37
37
 
38
- ```tsx
38
+ ```ts
39
39
  const wallet = useTuringsWallet();
40
40
  const { tbcPubKey } = await wallet.getPubKey(); //tbcPubKey为string类型
41
41
  ```
42
42
 
43
43
  ## getAddress
44
44
 
45
- ```tsx
45
+ ```ts
46
46
  const wallet = useTuringsWallet();
47
47
  const { tbcAddress } = await wallet.getAddress(); //tbcAddress为string类型
48
48
  ```
49
49
 
50
50
  ## getBalance
51
51
 
52
- ```tsx
52
+ ```ts
53
53
  const wallet = useTuringsWallet();
54
54
  const { tbc } = await wallet.getBalance(); //tbc为number类型,单位为tbc
55
55
  ```
56
56
 
57
57
  ## getInfo
58
58
 
59
- ```tsx
59
+ ```ts
60
60
  const wallet = useTuringsWallet();
61
61
  const {name,platform,version} = await wallet.getInfo();
62
62
  {Turing,android,1.0.0}示例的返回值
63
63
  ```
64
64
 
65
- ## getPaymentUtxos
66
-
67
- ```tsx
68
- const wallet = useTuringsWallet();
69
- try {
70
- const utxos = await wallet.getPaymentUtxos();
71
- console.log(utxos);
72
- } catch (err) {
73
- console.log(err);
74
- }
75
-
76
- [
77
- {
78
- satoshis: 205551
79
- script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
80
- txid: "c58e8b0dd25e56af0696b026c1961dccd0cab3fe42fb2f3ac934ebdc3accbb40"
81
- vout: 0
82
- },
83
- {
84
- satoshis: 19909
85
- script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
86
- txid: "4c52add57a2c9cda29501a810a1312eaee9423d28440a09acbf5d9d8d0467382"
87
- vout: 0
88
- }
89
- ]//模拟的输出
90
- ```
91
-
92
65
  ## signMessage
93
66
 
94
- ```tsx
67
+ ```ts
95
68
  const wallet = useTuringsWallet();
96
69
  try{
97
70
  const { address, pubKey, sig, message } = await wallet.signMessage({ message: "hello world", encoding: "base64" });//encoding可为utf-8,base64,hex
@@ -108,10 +81,10 @@ const true/false = tbc.Message.verify(msg_buf,address,sig);
108
81
 
109
82
  ## encrypt
110
83
 
111
- ```tsx
84
+ ```ts
112
85
  const wallet = useTuringsWallet();
113
86
  try {
114
- const encryptedMessage = await wallet.encrypt(message);
87
+ const { encryptedMessage } = await wallet.encrypt({ message });
115
88
  if (encryptedMessage) {
116
89
  console.log(encryptedMessage);
117
90
  }
@@ -125,7 +98,7 @@ try {
125
98
  ```ts
126
99
  const wallet = useTuringsWallet();
127
100
  try {
128
- const decryptedMessage = await wallet.decrypt(message);
101
+ const { decryptedMessage } = await wallet.decrypt({ message });
129
102
  if (decryptedMessage) {
130
103
  console.log(decryptedMessage);
131
104
  }
@@ -134,9 +107,73 @@ try {
134
107
  }
135
108
  ```
136
109
 
110
+ ## signTransaction
111
+
112
+ ```ts
113
+ //使用示例
114
+ const utxosA: tbc.Transaction.IUnspentOutput[] = [];
115
+ const utxosB: tbc.Transaction.IUnspentOutput[] = [];
116
+ const utxos_satoshis: number[][] = [[], []];
117
+ const script_pubkeys: string[][] = [[], []];
118
+ const txraws: string[] = [];
119
+ const txs: tbc.Transaction[] = [];
120
+ const tx0 = new tbc.Transaction()
121
+ .from(utxosA)
122
+ .to(address, 100000)
123
+ .change(address)
124
+ .fee(80);
125
+ const tx1 = new tbc.Transaction()
126
+ .from(utxosB)
127
+ .to(address, 100000)
128
+ .change(address)
129
+ .fee(80);
130
+ txraws.push(tx0.uncheckedSerialize(), tx1.uncheckedSerialize());
131
+ for (let i = 0; i < utxosA.length; i++) {
132
+ utxos_satoshis[0].push(utxosA[i].satoshis);
133
+ script_pubkeys[0].push(utxosA[i].script);
134
+ }
135
+ for (let i = 0; i < utxosB.length; i++) {
136
+ utxos_satoshis[1].push(utxosB[i].satoshis);
137
+ script_pubkeys[1].push(utxosB[i].script);
138
+ }
139
+ const wallet = useTuringsWallet();
140
+ const { sigs } = await wallet.signTransaction({
141
+ txraws,
142
+ utxos_satoshis,
143
+ script_pubkeys,
144
+ });
145
+ for (let i = 0; i < utxosA.length; i++) {
146
+ tx0.setInputScript({ inputIndex: i }, (tx) => {
147
+ const sig = sigs[0][i];
148
+ const sig_length = (sig.length / 2).toString(16);
149
+ const publicKey_length = (
150
+ publicKey.toBuffer().toString("hex").length / 2
151
+ ).toString(16);
152
+ return new tbc.Script(
153
+ sig_length + sig + publicKey_length + publicKey.toString()
154
+ );
155
+ });
156
+ txs.push(tx0);
157
+ }
158
+ for (let i = 0; i < utxosB.length; i++) {
159
+ tx1.setInputScript({ inputIndex: i }, (tx) => {
160
+ const sig = sigs[1][i]; // Use index 1 for the second transaction
161
+ const sig_length = (sig.length / 2).toString(16);
162
+ const publicKey_length = (
163
+ publicKey.toBuffer().toString("hex").length / 2
164
+ ).toString(16);
165
+ return new tbc.Script(
166
+ sig_length + sig + publicKey_length + publicKey.toString()
167
+ );
168
+ });
169
+ txs.push(tx1);
170
+ }
171
+ broadcastTXsraw(txs.map((tx) => ({ txHex: tx.uncheckedSerialize() })));
172
+ ```
173
+
137
174
  ## sendTransaction
138
175
 
139
- ```tsx
176
+ ```ts
140
177
  interface FTData {
141
178
  ​ name:string;
142
179
  symbol :string;
@@ -16,13 +16,6 @@ export type Info = {
16
16
  version: string;
17
17
  }
18
18
 
19
- export type SignedMessage = {
20
- address: string;
21
- pubKey: string;
22
- sig: string;
23
- message: string;
24
- };
25
-
26
19
  export type TransactionFlag =
27
20
  | "P2PKH"
28
21
  | "COLLECTION_CREATE"
@@ -54,8 +47,8 @@ export type SendTransaction = {
54
47
  merge_times?: number;
55
48
  with_lock?: boolean;
56
49
  lpCostAddress?: string;
57
- lpCostAmount?: number;
58
- pubKeyLock?: string[];
50
+ lpCostAmount?: number;
51
+ pubKeyLock?: string[];
59
52
  poolNFT_version?: number;
60
53
  serviceFeeRate?: number;
61
54
  serviceProvider_flag?: string;
@@ -63,20 +56,33 @@ export type SendTransaction = {
63
56
  domain?: string;
64
57
  };
65
58
 
66
- export type SignMessage = {
67
- message: string;
68
- encoding?: "utf8" | "hex" | "base64";
59
+ export type SendTransactionResponse = {
60
+ txid?: string;
61
+ error?: string;
69
62
  };
70
63
 
71
- export type Utxos = {
72
- satoshis: number;
73
- script: string;
74
- txid: string;
75
- vout: number;
64
+ export type SignTransaction = {
65
+ txraws: string[];
66
+ utxos_satoshis: number[][];
67
+ script_pubkeys: string[][];
76
68
  };
77
69
 
78
- export type SendTransactionResponse = {
79
- txid: string;
70
+ export type SignTransactionResponse = {
71
+ sig?: string[][];
72
+ error?: string;
73
+ };
74
+
75
+ export type SignMessage = {
76
+ message: string;
77
+ encoding: "utf8" | "hex" | "base64";
78
+ };
79
+
80
+ export type SignMessageResponse = {
81
+ maddress?: string;
82
+ pubkey?: string;
83
+ message?: string;
84
+ sig?: string;
85
+ error?: string;
80
86
  };
81
87
 
82
88
  export type Encrypt = {
@@ -88,11 +94,13 @@ export type Decrypt = {
88
94
  };
89
95
 
90
96
  export type EncryptResponse = {
91
- encryptedMessage: string;
97
+ encryptedMessage?: string;
98
+ error?: string;
92
99
  };
93
100
 
94
101
  export type DecryptResponse = {
95
- decryptedMessage: string;
102
+ decryptedMessage?: string;
103
+ error?: string;
96
104
  };
97
105
 
98
106
  export type TuringProviderType = {
@@ -107,8 +115,8 @@ export type TuringProviderType = {
107
115
  sendTransaction: (
108
116
  params: SendTransaction[]
109
117
  ) => Promise<SendTransactionResponse | undefined>;
110
- signMessage: (params: SignMessage) => Promise<SignedMessage | undefined>;
111
- getPaymentUtxos: () => Promise<Utxos[] | undefined>;
118
+ signTransaction: (params: SignTransaction) => Promise<SignTransactionResponse | undefined>;
119
+ signMessage: (params: SignMessage) => Promise<SignMessageResponse | undefined>;
112
120
  encrypt: (params: Encrypt) => Promise<EncryptResponse | undefined>;
113
121
  decrypt: (params: Decrypt) => Promise<DecryptResponse | undefined>;
114
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turing-wallet-provider",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [