turing-wallet-provider 1.2.2 → 1.2.4

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,343 +1,347 @@
1
- # connect
2
-
3
- ```tsx
4
- npm install turing-wallet-provider@latest
5
-
6
- import { TuringProvider } from "turing-wallet-provider";
7
-
8
- root.render(
9
- <TuringProvider>
10
- <App />
11
- </TuringProvider>
12
- );
13
- ```
14
-
15
- ```tsx
16
- import { useTuringsWallet } from 'turing-wallet-provider';
17
-
18
- const wallet = useTuringsWallet();
19
- await wallet.connect();
20
- ```
21
-
22
- ## disconnect
23
-
24
- ```tsx
25
- const wallet = useTuringsWallet();
26
- await wallet.disconnect();
27
- ```
28
-
29
- ## isConnected
30
-
31
- ```tsx
32
- const wallet = useTuringsWallet();
33
- const ture/false = await wallet.isConnected();
34
- ```
35
-
36
- ## getPubKey
37
-
38
- ```tsx
39
- const wallet = useTuringsWallet();
40
- const {tbcPubKey} = await wallet.getPubKey(); //tbcPubKey为string类型
41
- ```
42
-
43
- ## getAddress
44
-
45
- ```tsx
46
- const wallet = useTuringsWallet();
47
- const {tbcAddress} = await wallet.getAddress(); //tbcAddress为string类型
48
- ```
49
-
50
- ## getBalance
51
-
52
- ```tsx
53
- const wallet = useTuringsWallet();
54
- const {tbc} = await wallet.getBalance();//tbc为number类型,单位为tbc
55
- ```
56
-
57
- ## getPaymentUtxos
58
-
59
- ```tsx
60
- const wallet = useTuringsWallet();
61
- try {
62
- const utxos = await wallet.getPaymentUtxos();
63
- console.log(utxos);
64
- } catch (err) {
65
- console.log(err);
66
- }
67
-
68
- [
69
- {
70
- satoshis: 205551
71
- script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
72
- txid: "c58e8b0dd25e56af0696b026c1961dccd0cab3fe42fb2f3ac934ebdc3accbb40"
73
- vout: 0
74
- },
75
- {
76
- satoshis: 19909
77
- script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
78
- txid: "4c52add57a2c9cda29501a810a1312eaee9423d28440a09acbf5d9d8d0467382"
79
- vout: 0
80
- }
81
- ]//模拟的输出
82
- ```
83
-
84
- ## signMessage
85
-
86
- ```tsx
87
- const wallet = useTuringsWallet();
88
- try{
89
- const { address, pubKey, sig, message } = await wallet.signMessage({ message: "hello world", encoding: "base64" });//encoding可为utf-8,base64,hex
90
- }catch(error){
91
- console.log(error);
92
- }
93
-
94
- //本地验证签名
95
- import * as tbc from "tbc-lib-js"
96
-
97
- const msg_buf = Buffer.from(message,encoding);
98
- const true/false = tbc.Message.verify(msg_buf,address,sig);
99
- ```
100
-
101
- ## encrypt
102
-
103
- ```tsx
104
- const wallet = useTuringsWallet();
105
- try{
106
- const encryptedMessage = await wallet.encrypt(message);
107
- if(encryptedMessage){
108
- console.log(encryptedMessage)
109
- }
110
- }catch(error){
111
- console.log(error);
112
- }
113
- ```
114
-
115
- ## decrypt
116
-
117
- ```ts
118
- const wallet = useTuringsWallet();
119
- try{
120
- const decryptedMessage = await wallet.decrypt(message);
121
- if(decryptedMessage){
122
- console.log(decryptedMessage)
123
- }
124
- }catch(error){
125
- console.log(error);
126
- }
127
- ```
128
-
129
- ## sendTransaction
130
-
131
- ```tsx
132
- interface FTData {
133
- ​ name:string;
134
- symbol :string;
135
- ​ decimal :number;
136
- ​ amount :number;
137
- };
138
-
139
- interface CollectionData {
140
- collectionName: string;
141
- description: string;
142
- supply: number;
143
- file: string;//file为图片base64编码后数据
144
- };
145
-
146
- interface NFTData {
147
- nftName: string;
148
- symbol: string;
149
- description: string;
150
- attributes: string;
151
- file?: string;//file为图片base64编码后数据,若无则为引用合集图片
152
- };
153
-
154
- interface RequestParam = {
155
- flag: "P2PKH" | "COLLECTION_CREATE" | "NFT_CREATE" | "NFT_TRANSFER" | "FT_MINT" | "FT_TRANSFER" | "POOLNFT_MINT" | "POOLNFT_INIT" | "POOLNFT_LP_INCREASE" |"POOLNFT_LP_CONSUME"| "POOLNFT_SWAP_TO_TOKEN" | "POOLNFT_SWAP_TO_TBC" | "POOLNFT_MERGE"|"FTLP_MERGE";
156
- addres?: string;//交易接收者地址
157
- satoshis?: number;//单位为satoshis
158
- collection_data?: string; //json格式传
159
- ft_data?: string; //json格式传
160
- nft_data?: string; //json格式传
161
- collection_id?: string;
162
- nft_contract_address?: string;
163
- ft_contract_address?: string;
164
- tbc_amount?: number;
165
- ft_amount?: number;
166
- merge_times?:number; //可选字段 不提供默认为10
167
- with_lock? boolean;
168
- poolNFT_version?: number; // 1或2 不提供默认为2
169
- serviceFeeRate?: number; // 0-100 poolNFT_version为2有效 不提供默认为25
170
- serverProvider_tag?:string; //poolNFT_version为2时为必需字段 poolNFT_version为1无效
171
- };
172
-
173
- const params = [param:RequestParam] //目前参数里只能放一个对象,有批量发送需求再扩展
174
- ```
175
-
176
- ### P2PKH
177
-
178
- ```ts
179
- const params = [{
180
- flag:"P2PKH",
181
- satoshis: 1000,
182
- address: "",
183
- }] ;
184
- const { txid } = await wallet.sendTransaction(params);
185
- ```
186
-
187
- ### COLLECTION_CREATE
188
-
189
- ```ts
190
- const params = [{
191
- flag:"COLLECTION_CREATE",
192
- collection_data:"",
193
- }];
194
- const { txid } = await wallet.sendTransaction(params);
195
- ```
196
-
197
- ### NFT_CREATE
198
-
199
- ```ts
200
- const params = [{
201
- flag:"NFT_CREATE",
202
- nft_data:"",
203
- collection_id:""
204
- }];
205
- const { txid } = await wallet.sendTransaction(params);
206
- ```
207
-
208
- ### NFT_TRANSFER
209
-
210
- ```ts
211
- const params = [{
212
- flag:"NFT_TRANSFER",
213
- nft_contract_address:"",
214
- address:""
215
- }];
216
- const { txid } = await wallet.sendTransaction(params);
217
- ```
218
-
219
- ### FT_MINT
220
-
221
- ```ts
222
- const params = [{
223
- flag:"FT_MINT",
224
- ft_data:""
225
- }];
226
- const { txid } = await wallet.sendTransaction(params);
227
- ```
228
-
229
- ### FT_TRANSFER
230
-
231
- ```ts
232
- const params = [{
233
- flag:"FT_TRANSFER",
234
- ft_contract_address:"",
235
- ft_amount:0.1,
236
- address:""
237
- }];
238
- const { txid } = await wallet.sendTransaction(params);
239
- ```
240
-
241
- ### POOLNFT_MINT
242
-
243
- ```ts
244
- const params = [{
245
- flag:"POOLNFT_MINT",
246
- ft_contract_address:"",
247
- poolNFT_version?:2,
248
- serverProvider_tag?:"",
249
- serviceFeeRate?:25, // poolNFT_version2时此参数有效,默认为25
250
- with_lock?:false //默认值为false,为true则创建带哈希锁的poolNFT
251
-
252
- }];
253
- const { txid } = await wallet.sendTransaction(params);
254
- ```
255
-
256
- ### POOLNFT_INIT
257
-
258
- ```ts
259
- const params = [{
260
- flag:"POOLNFT_INIT",
261
- nft_contract_address:"",
262
- address:"",
263
- tbc_amount:30,
264
- ft_amount:1000,
265
- poolNFT_version?:2
266
- }];
267
- const { txid, rawtx } = await wallet.sendTransaction(params);
268
- ```
269
-
270
- ### POOLNFT_LP_INCREASE
271
-
272
- ```ts
273
- const params = [{
274
- flag:"POOLNFT_LP_INCREASE",
275
- nft_contract_address:"",
276
- address:"",
277
- tbc_amount:3,
278
- poolNFT_version?:2
279
- }];
280
- const { txid, rawtx } = await wallet.sendTransaction(params);
281
- ```
282
-
283
- ### POOLNFT_LP_CONSUME
284
-
285
- ```ts
286
- const params = [{
287
- flag:"POOLNFT_LP_CONSUME",
288
- nft_contract_address:"",
289
- address:"",
290
- ft_amount:100,
291
- poolNFT_version?:2
292
- }];
293
- const { txid } = await wallet.sendTransaction(params);
294
- ```
295
-
296
- ### POOLNFT_SWAP_TO_TOKEN
297
-
298
- ```ts
299
- const params = [{
300
- flag:"POOLNFT_SWAP_TO_TOKEN",
301
- nft_contract_address:"",
302
- address:"",
303
- tbc_amount:10,
304
- poolNFT_version?:2
305
- }];
306
- const { txid } = await wallet.sendTransaction(params);
307
- ```
308
-
309
- ### POOLNFT_SWAP_TO_TBC
310
-
311
- ```ts
312
- const params = [{
313
- flag:"POOLNFT_SWAP_TO_TBC",
314
- nft_contract_address:"",
315
- address:"",
316
- ft_amount:10,
317
- poolNFT_version?:2
318
- }];
319
- const { txid } = await wallet.sendTransaction(params);
320
- ```
321
-
322
- ### POOLNFT_MERGE
323
-
324
- ```ts
325
- const params = [{
326
- flag:"POOLNFT_MERGE",
327
- nft_contract_address:"",
328
- poolNFT_version?:2,
329
- merge_times?:1, //1-10次 默认为10次 不足10次会提前终止
330
- }];
331
- const { txid } = await wallet.sendTransaction(params);
332
- ```
333
-
334
- ### FTLP_MERGE
335
-
336
- ```ts
337
- const params = [{
338
- flag:"FTLP_MERGE",
339
- nft_contract_address:"",
340
- poolNFT_version?:2
341
- }];
342
- const { txid } = await wallet.sendTransaction(params);
343
- ```
1
+ # connect
2
+
3
+ ```tsx
4
+ npm install turing-wallet-provider@latest
5
+
6
+ import { TuringProvider } from "turing-wallet-provider";
7
+
8
+ root.render(
9
+ <TuringProvider>
10
+ <App />
11
+ </TuringProvider>
12
+ );
13
+ ```
14
+
15
+ ```tsx
16
+ import { useTuringsWallet } from 'turing-wallet-provider';
17
+
18
+ const wallet = useTuringsWallet();
19
+ await wallet.connect();
20
+ ```
21
+
22
+ ## disconnect
23
+
24
+ ```tsx
25
+ const wallet = useTuringsWallet();
26
+ await wallet.disconnect();
27
+ ```
28
+
29
+ ## isConnected
30
+
31
+ ```tsx
32
+ const wallet = useTuringsWallet();
33
+ const ture/false = await wallet.isConnected();
34
+ ```
35
+
36
+ ## getPubKey
37
+
38
+ ```tsx
39
+ const wallet = useTuringsWallet();
40
+ const {tbcPubKey} = await wallet.getPubKey(); //tbcPubKey为string类型
41
+ ```
42
+
43
+ ## getAddress
44
+
45
+ ```tsx
46
+ const wallet = useTuringsWallet();
47
+ const {tbcAddress} = await wallet.getAddress(); //tbcAddress为string类型
48
+ ```
49
+
50
+ ## getBalance
51
+
52
+ ```tsx
53
+ const wallet = useTuringsWallet();
54
+ const {tbc} = await wallet.getBalance();//tbc为number类型,单位为tbc
55
+ ```
56
+
57
+ ## getPaymentUtxos
58
+
59
+ ```tsx
60
+ const wallet = useTuringsWallet();
61
+ try {
62
+ const utxos = await wallet.getPaymentUtxos();
63
+ console.log(utxos);
64
+ } catch (err) {
65
+ console.log(err);
66
+ }
67
+
68
+ [
69
+ {
70
+ satoshis: 205551
71
+ script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
72
+ txid: "c58e8b0dd25e56af0696b026c1961dccd0cab3fe42fb2f3ac934ebdc3accbb40"
73
+ vout: 0
74
+ },
75
+ {
76
+ satoshis: 19909
77
+ script: "76a914b681d8032b448405d44e82807fab2c8894eed57788ac"
78
+ txid: "4c52add57a2c9cda29501a810a1312eaee9423d28440a09acbf5d9d8d0467382"
79
+ vout: 0
80
+ }
81
+ ]//模拟的输出
82
+ ```
83
+
84
+ ## signMessage
85
+
86
+ ```tsx
87
+ const wallet = useTuringsWallet();
88
+ try{
89
+ const { address, pubKey, sig, message } = await wallet.signMessage({ message: "hello world", encoding: "base64" });//encoding可为utf-8,base64,hex
90
+ }catch(error){
91
+ console.log(error);
92
+ }
93
+
94
+ //本地验证签名
95
+ import * as tbc from "tbc-lib-js"
96
+
97
+ const msg_buf = Buffer.from(message,encoding);
98
+ const true/false = tbc.Message.verify(msg_buf,address,sig);
99
+ ```
100
+
101
+ ## encrypt
102
+
103
+ ```tsx
104
+ const wallet = useTuringsWallet();
105
+ try{
106
+ const encryptedMessage = await wallet.encrypt(message);
107
+ if(encryptedMessage){
108
+ console.log(encryptedMessage)
109
+ }
110
+ }catch(error){
111
+ console.log(error);
112
+ }
113
+ ```
114
+
115
+ ## decrypt
116
+
117
+ ```ts
118
+ const wallet = useTuringsWallet();
119
+ try{
120
+ const decryptedMessage = await wallet.decrypt(message);
121
+ if(decryptedMessage){
122
+ console.log(decryptedMessage)
123
+ }
124
+ }catch(error){
125
+ console.log(error);
126
+ }
127
+ ```
128
+
129
+ ## sendTransaction
130
+
131
+ ```tsx
132
+ interface FTData {
133
+ ​ name:string;
134
+ symbol :string;
135
+ ​ decimal :number;
136
+ ​ amount :number;
137
+ };
138
+
139
+ interface CollectionData {
140
+ collectionName: string;
141
+ description: string;
142
+ supply: number;
143
+ file: string;//file为图片base64编码后数据
144
+ };
145
+
146
+ interface NFTData {
147
+ nftName: string;
148
+ symbol: string;
149
+ description: string;
150
+ attributes: string;
151
+ file?: string;//file为图片base64编码后数据,若无则为引用合集图片
152
+ };
153
+
154
+ interface RequestParam = {
155
+ flag: "P2PKH" | "COLLECTION_CREATE" | "NFT_CREATE" | "NFT_TRANSFER" | "FT_MINT" | "FT_TRANSFER" | "POOLNFT_MINT" | "POOLNFT_INIT" | "POOLNFT_LP_INCREASE" |"POOLNFT_LP_CONSUME"| "POOLNFT_SWAP_TO_TOKEN" | "POOLNFT_SWAP_TO_TBC" | "POOLNFT_MERGE"|"FTLP_MERGE";
156
+ addres?: string;//交易接收者地址
157
+ satoshis?: number;//单位为satoshis
158
+ collection_data?: string; //json格式传
159
+ ft_data?: string; //json格式传
160
+ nft_data?: string; //json格式传
161
+ collection_id?: string;
162
+ nft_contract_address?: string;
163
+ ft_contract_address?: string;
164
+ tbc_amount?: number;
165
+ ft_amount?: number;
166
+ merge_times?:number; //可选字段 不提供默认为10
167
+ with_lock? boolean;
168
+ poolNFT_version?: number; // 1或2 不提供默认为2
169
+ serviceFeeRate?: number; // 0-100 poolNFT_version为2有效 不提供默认为25
170
+ serverProvider_tag?:string; //poolNFT_version为2时为必需字段 poolNFT_version为1无效
171
+ lpPlan?:number //1或2 不提供默认为2 lp手续费方案, 方案1: LP 0.25% swap服务商 0.09% 协议0.01%; 方案2: LP 0.05% swap服务商 0.29% 协议0.01%
172
+ };
173
+
174
+ const params = [param:RequestParam] //目前参数里只能放一个对象,有批量发送需求再扩展
175
+ ```
176
+
177
+ ### P2PKH
178
+
179
+ ```ts
180
+ const params = [{
181
+ flag:"P2PKH",
182
+ satoshis: 1000,
183
+ address: "",
184
+ }] ;
185
+ const { txid } = await wallet.sendTransaction(params);
186
+ ```
187
+
188
+ ### COLLECTION_CREATE
189
+
190
+ ```ts
191
+ const params = [{
192
+ flag:"COLLECTION_CREATE",
193
+ collection_data:"",
194
+ }];
195
+ const { txid } = await wallet.sendTransaction(params);
196
+ ```
197
+
198
+ ### NFT_CREATE
199
+
200
+ ```ts
201
+ const params = [{
202
+ flag:"NFT_CREATE",
203
+ nft_data:"",
204
+ collection_id:""
205
+ }];
206
+ const { txid } = await wallet.sendTransaction(params);
207
+ ```
208
+
209
+ ### NFT_TRANSFER
210
+
211
+ ```ts
212
+ const params = [{
213
+ flag:"NFT_TRANSFER",
214
+ nft_contract_address:"",
215
+ address:""
216
+ }];
217
+ const { txid } = await wallet.sendTransaction(params);
218
+ ```
219
+
220
+ ### FT_MINT
221
+
222
+ ```ts
223
+ const params = [{
224
+ flag:"FT_MINT",
225
+ ft_data:""
226
+ }];
227
+ const { txid } = await wallet.sendTransaction(params);
228
+ ```
229
+
230
+ ### FT_TRANSFER
231
+
232
+ ```ts
233
+ const params = [{
234
+ flag:"FT_TRANSFER",
235
+ ft_contract_address:"",
236
+ ft_amount:0.1,
237
+ tbc_amount?: 1, //同时转ft和tbc时候可提供参数
238
+ address:"",
239
+ }];
240
+ const { txid } = await wallet.sendTransaction(params);
241
+ ```
242
+
243
+ ### POOLNFT_MINT
244
+
245
+ ```ts
246
+ const params = [{
247
+ flag:"POOLNFT_MINT",
248
+ ft_contract_address:"",
249
+ poolNFT_version?:2,
250
+ serverProvider_tag?:"",
251
+ serviceFeeRate?:25, // poolNFT_version为2时此参数有效,默认为25
252
+ with_lock?:false //默认值为false,为true则创建带哈希锁的poolNFT
253
+ lpPlan?:2 //默认值为2
254
+ }];
255
+ const { txid } = await wallet.sendTransaction(params);
256
+ ```
257
+
258
+ ### POOLNFT_INIT
259
+
260
+ ```ts
261
+ const params = [{
262
+ flag:"POOLNFT_INIT",
263
+ nft_contract_address:"",
264
+ address:"",
265
+ tbc_amount:30,
266
+ ft_amount:1000,
267
+ poolNFT_version?:2
268
+ }];
269
+ const { txid, rawtx } = await wallet.sendTransaction(params);
270
+ ```
271
+
272
+ ### POOLNFT_LP_INCREASE
273
+
274
+ ```ts
275
+ const params = [{
276
+ flag:"POOLNFT_LP_INCREASE",
277
+ nft_contract_address:"",
278
+ address:"",
279
+ tbc_amount:3,
280
+ poolNFT_version?:2
281
+ }];
282
+ const { txid, rawtx } = await wallet.sendTransaction(params);
283
+ ```
284
+
285
+ ### POOLNFT_LP_CONSUME
286
+
287
+ ```ts
288
+ const params = [{
289
+ flag:"POOLNFT_LP_CONSUME",
290
+ nft_contract_address:"",
291
+ address:"",
292
+ ft_amount:100,
293
+ poolNFT_version?:2
294
+ }];
295
+ const { txid } = await wallet.sendTransaction(params);
296
+ ```
297
+
298
+ ### POOLNFT_SWAP_TO_TOKEN
299
+
300
+ ```ts
301
+ const params = [{
302
+ flag:"POOLNFT_SWAP_TO_TOKEN",
303
+ nft_contract_address:"",
304
+ address:"",
305
+ tbc_amount:10,
306
+ poolNFT_version?:2
307
+ lpPlan?:2 //默认值为2
308
+ }];
309
+ const { txid } = await wallet.sendTransaction(params);
310
+ ```
311
+
312
+ ### POOLNFT_SWAP_TO_TBC
313
+
314
+ ```ts
315
+ const params = [{
316
+ flag:"POOLNFT_SWAP_TO_TBC",
317
+ nft_contract_address:"",
318
+ address:"",
319
+ ft_amount:10,
320
+ poolNFT_version?:2
321
+ lpPlan?:2 //默认值为2
322
+ }];
323
+ const { txid } = await wallet.sendTransaction(params);
324
+ ```
325
+
326
+ ### POOLNFT_MERGE
327
+
328
+ ```ts
329
+ const params = [{
330
+ flag:"POOLNFT_MERGE",
331
+ nft_contract_address:"",
332
+ poolNFT_version?:2,
333
+ merge_times?:1, //1-10次 默认为10次 不足10次会提前终止
334
+ }];
335
+ const { txid } = await wallet.sendTransaction(params);
336
+ ```
337
+
338
+ ### FTLP_MERGE
339
+
340
+ ```ts
341
+ const params = [{
342
+ flag:"FTLP_MERGE",
343
+ nft_contract_address:"",
344
+ poolNFT_version?:2
345
+ }];
346
+ const { txid } = await wallet.sendTransaction(params);
347
+ ```
@@ -1,8 +1,8 @@
1
- import { ReactNode } from "react";
2
- import { TuringProviderType } from "../types/providerTypes"
3
- export declare const TuringContext: import("react").Context<TuringProviderType | undefined>;
4
- interface TuringProviderProps {
5
- children: ReactNode;
6
- }
7
- export declare const TuringProvider: (props: TuringProviderProps) => import("react/jsx-runtime").JSX.Element;
8
- export { };
1
+ import { ReactNode } from "react";
2
+ import { TuringProviderType } from "../types/providerTypes"
3
+ export declare const TuringContext: import("react").Context<TuringProviderType | undefined>;
4
+ interface TuringProviderProps {
5
+ children: ReactNode;
6
+ }
7
+ export declare const TuringProvider: (props: TuringProviderProps) => import("react/jsx-runtime").JSX.Element;
8
+ export { };
@@ -1,24 +1,24 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TuringProvider = exports.TuringContext = void 0;
4
- var jsx_runtime_1 = require("react/jsx-runtime");
5
- var react_1 = require("react");
6
- exports.TuringContext = (0, react_1.createContext)(undefined);
7
- var TuringProvider = function (props) {
8
- var children = props.children;
9
- // It takes a moment for the Turing wallet to get injected into the DOM. To use context we need an initial state;
10
- var _a = (0, react_1.useState)({ isReady: false }), TuringWallet = _a[0], setTuringWallet = _a[1];
11
- (0, react_1.useEffect)(function () {
12
- var checkTuringWallet = function () {
13
- var _a;
14
- if ("Turing" in window && ((_a = window.Turing) === null || _a === void 0 ? void 0 : _a.isReady)) {
15
- setTuringWallet(window.Turing);
16
- }
17
- };
18
- checkTuringWallet();
19
- var intervalId = setInterval(checkTuringWallet, 1000);
20
- return function () { return clearInterval(intervalId); };
21
- }, []);
22
- return ((0, jsx_runtime_1.jsx)(exports.TuringContext.Provider, { value: TuringWallet, children: children }));
23
- };
24
- exports.TuringProvider = TuringProvider;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TuringProvider = exports.TuringContext = void 0;
4
+ var jsx_runtime_1 = require("react/jsx-runtime");
5
+ var react_1 = require("react");
6
+ exports.TuringContext = (0, react_1.createContext)(undefined);
7
+ var TuringProvider = function (props) {
8
+ var children = props.children;
9
+ // It takes a moment for the Turing wallet to get injected into the DOM. To use context we need an initial state;
10
+ var _a = (0, react_1.useState)({ isReady: false }), TuringWallet = _a[0], setTuringWallet = _a[1];
11
+ (0, react_1.useEffect)(function () {
12
+ var checkTuringWallet = function () {
13
+ var _a;
14
+ if ("Turing" in window && ((_a = window.Turing) === null || _a === void 0 ? void 0 : _a.isReady)) {
15
+ setTuringWallet(window.Turing);
16
+ }
17
+ };
18
+ checkTuringWallet();
19
+ var intervalId = setInterval(checkTuringWallet, 1000);
20
+ return function () { return clearInterval(intervalId); };
21
+ }, []);
22
+ return ((0, jsx_runtime_1.jsx)(exports.TuringContext.Provider, { value: TuringWallet, children: children }));
23
+ };
24
+ exports.TuringProvider = TuringProvider;
@@ -1 +1 @@
1
- export declare const useTuringWallet: () => import("..").TuringProviderType;
1
+ export declare const useTuringWallet: () => import("..").TuringProviderType;
@@ -1,13 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.useTuringWallet = void 0;
4
- var react_1 = require("react");
5
- var TuringWalletContext_1 = require("../context/TuringWalletContext");
6
- var useTuringWallet = function () {
7
- var context = (0, react_1.useContext)(TuringWalletContext_1.TuringContext);
8
- if (!context) {
9
- throw new Error("useTuringWallet must be used within a TuringProvider");
10
- }
11
- return context;
12
- };
13
- exports.useTuringWallet = useTuringWallet;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useTuringWallet = void 0;
4
+ var react_1 = require("react");
5
+ var TuringWalletContext_1 = require("../context/TuringWalletContext");
6
+ var useTuringWallet = function () {
7
+ var context = (0, react_1.useContext)(TuringWalletContext_1.TuringContext);
8
+ if (!context) {
9
+ throw new Error("useTuringWallet must be used within a TuringProvider");
10
+ }
11
+ return context;
12
+ };
13
+ exports.useTuringWallet = useTuringWallet;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export * from "./context/TuringWalletContext";
2
- export * from "./hook/useTuringWallet";
3
- export * from "./types/providerTypes";
1
+ export * from "./context/TuringWalletContext";
2
+ export * from "./hook/useTuringWallet";
3
+ export * from "./types/providerTypes";
package/dist/index.js CHANGED
@@ -1,19 +1,19 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./context/TuringWalletContext"), exports);
18
- __exportStar(require("./hook/useTuringWallet"), exports);
19
- __exportStar(require("./types/providerTypes"), exports);
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./context/TuringWalletContext"), exports);
18
+ __exportStar(require("./hook/useTuringWallet"), exports);
19
+ __exportStar(require("./types/providerTypes"), exports);
@@ -1,102 +1,103 @@
1
- export type PubKey = {
2
- tbcPubKey: string;
3
- };
4
-
5
- export type Address = {
6
- tbcAddress: string;
7
- };
8
-
9
- export type Balance = {
10
- tbc: number;
11
- };
12
-
13
- export type SignedMessage = {
14
- address: string;
15
- pubKey: string;
16
- sig: string;
17
- message: string;
18
- };
19
-
20
- export type TransactionFlag =
21
- | "P2PKH"
22
- | "COLLECTION_CREATE"
23
- | "NFT_CREATE"
24
- | "NFT_TRANSFER"
25
- | "FT_MINT"
26
- | "FT_TRANSFER"
27
- | "POOLNFT_MINT"
28
- | "POOLNFT_INIT"
29
- | "POOLNFT_LP_INCREASE"
30
- | "POOLNFT_LP_CONSUME"
31
- | "POOLNFT_SWAP_TO_TOKEN"
32
- | "POOLNFT_SWAP_TO_TBC"
33
- | "POOLNFT_MERGE"
34
- | "FTLP_MERGE";
35
-
36
- export type SendTransaction = {
37
- flag: TransactionFlag;
38
- satoshis?: number;
39
- address?: string;
40
- collection_data?: string;
41
- ft_data?: string;
42
- nft_data?: string;
43
- collection_id?: string;
44
- nft_contract_address?: string;
45
- ft_contract_address?: string;
46
- tbc_amount?: number;
47
- ft_amount?: number;
48
- merge_times?: number;
49
- with_lock?: boolean;
50
- poolNFT_version?: number;
51
- serviceFeeRate?: number;
52
- serviceProvider_flag?: string;
53
- };
54
-
55
- export type SignMessage = {
56
- message: string;
57
- encoding?: "utf8" | "hex" | "base64";
58
- };
59
-
60
- export type Utxos = {
61
- satoshis: number;
62
- script: string;
63
- txid: string;
64
- vout: number;
65
- };
66
-
67
- export type SendTransactionResponse = {
68
- txid: string;
69
- };
70
-
71
- export type Encrypt = {
72
- message: string;
73
- };
74
-
75
- export type Decrypt = {
76
- message: string;
77
- };
78
-
79
- export type EncryptResponse = {
80
- encryptedMessage: string;
81
- };
82
-
83
- export type DecryptResponse = {
84
- decryptedMessage: string;
85
- };
86
-
87
- export type TuringProviderType = {
88
- isReady: boolean;
89
- connect: () => Promise<string | undefined>;
90
- disconnect: () => Promise<boolean>;
91
- isConnected: () => Promise<boolean>;
92
- getPubKey: () => Promise<PubKey | undefined>;
93
- getAddress: () => Promise<Address | undefined>;
94
- getBalance: () => Promise<Balance | undefined>;
95
- sendTransaction: (
96
- params: SendTransaction[]
97
- ) => Promise<SendTransactionResponse | undefined>;
98
- signMessage: (params: SignMessage) => Promise<SignedMessage | undefined>;
99
- getPaymentUtxos: () => Promise<Utxos[] | undefined>;
100
- encrypt: (params: Encrypt) => Promise<EncryptResponse | undefined>;
101
- decrypt: (params: Decrypt) => Promise<DecryptResponse | undefined>;
102
- };
1
+ export type PubKey = {
2
+ tbcPubKey: string;
3
+ };
4
+
5
+ export type Address = {
6
+ tbcAddress: string;
7
+ };
8
+
9
+ export type Balance = {
10
+ tbc: number;
11
+ };
12
+
13
+ export type SignedMessage = {
14
+ address: string;
15
+ pubKey: string;
16
+ sig: string;
17
+ message: string;
18
+ };
19
+
20
+ export type TransactionFlag =
21
+ | "P2PKH"
22
+ | "COLLECTION_CREATE"
23
+ | "NFT_CREATE"
24
+ | "NFT_TRANSFER"
25
+ | "FT_MINT"
26
+ | "FT_TRANSFER"
27
+ | "POOLNFT_MINT"
28
+ | "POOLNFT_INIT"
29
+ | "POOLNFT_LP_INCREASE"
30
+ | "POOLNFT_LP_CONSUME"
31
+ | "POOLNFT_SWAP_TO_TOKEN"
32
+ | "POOLNFT_SWAP_TO_TBC"
33
+ | "POOLNFT_MERGE"
34
+ | "FTLP_MERGE";
35
+
36
+ export type SendTransaction = {
37
+ flag: TransactionFlag;
38
+ satoshis?: number;
39
+ address?: string;
40
+ collection_data?: string;
41
+ ft_data?: string;
42
+ nft_data?: string;
43
+ collection_id?: string;
44
+ nft_contract_address?: string;
45
+ ft_contract_address?: string;
46
+ tbc_amount?: number;
47
+ ft_amount?: number;
48
+ merge_times?: number;
49
+ with_lock?: boolean;
50
+ poolNFT_version?: number;
51
+ serviceFeeRate?: number;
52
+ serviceProvider_flag?: string;
53
+ lpPlan?: number;
54
+ };
55
+
56
+ export type SignMessage = {
57
+ message: string;
58
+ encoding?: "utf8" | "hex" | "base64";
59
+ };
60
+
61
+ export type Utxos = {
62
+ satoshis: number;
63
+ script: string;
64
+ txid: string;
65
+ vout: number;
66
+ };
67
+
68
+ export type SendTransactionResponse = {
69
+ txid: string;
70
+ };
71
+
72
+ export type Encrypt = {
73
+ message: string;
74
+ };
75
+
76
+ export type Decrypt = {
77
+ message: string;
78
+ };
79
+
80
+ export type EncryptResponse = {
81
+ encryptedMessage: string;
82
+ };
83
+
84
+ export type DecryptResponse = {
85
+ decryptedMessage: string;
86
+ };
87
+
88
+ export type TuringProviderType = {
89
+ isReady: boolean;
90
+ connect: () => Promise<string | undefined>;
91
+ disconnect: () => Promise<boolean>;
92
+ isConnected: () => Promise<boolean>;
93
+ getPubKey: () => Promise<PubKey | undefined>;
94
+ getAddress: () => Promise<Address | undefined>;
95
+ getBalance: () => Promise<Balance | undefined>;
96
+ sendTransaction: (
97
+ params: SendTransaction[]
98
+ ) => Promise<SendTransactionResponse | undefined>;
99
+ signMessage: (params: SignMessage) => Promise<SignedMessage | undefined>;
100
+ getPaymentUtxos: () => Promise<Utxos[] | undefined>;
101
+ encrypt: (params: Encrypt) => Promise<EncryptResponse | undefined>;
102
+ decrypt: (params: Decrypt) => Promise<DecryptResponse | undefined>;
103
+ };
@@ -1,9 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Tbc20Status = void 0;
4
- var Tbc20Status;
5
- (function (Tbc20Status) {
6
- Tbc20Status[Tbc20Status["Invalid"] = -1] = "Invalid";
7
- Tbc20Status[Tbc20Status["Pending"] = 0] = "Pending";
8
- Tbc20Status[Tbc20Status["Valid"] = 1] = "Valid";
9
- })(Tbc20Status || (exports.Tbc20Status = Tbc20Status = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tbc20Status = void 0;
4
+ var Tbc20Status;
5
+ (function (Tbc20Status) {
6
+ Tbc20Status[Tbc20Status["Invalid"] = -1] = "Invalid";
7
+ Tbc20Status[Tbc20Status["Pending"] = 0] = "Pending";
8
+ Tbc20Status[Tbc20Status["Valid"] = 1] = "Valid";
9
+ })(Tbc20Status || (exports.Tbc20Status = Tbc20Status = {}));
package/package.json CHANGED
@@ -1,27 +1,27 @@
1
- {
2
- "name": "turing-wallet-provider",
3
- "version": "1.2.2",
4
- "main": "dist/index.js",
5
- "types": "dist/index.d.ts",
6
- "files": [
7
- "dist"
8
- ],
9
- "scripts": {
10
- "build": "tsc"
11
- },
12
- "peerDependencies": {
13
- "react": ">=17.0.0",
14
- "react-dom": ">=17.0.0"
15
- },
16
- "devDependencies": {
17
- "typescript": "^4.5.0",
18
- "@types/react": "^17.0.0",
19
- "@types/react-dom": "^17.0.0"
20
- },
21
- "keywords": [
22
- "wallet",
23
- "tbc",
24
- "turing wallet"
25
- ],
26
- "description": "A provider help to connect Turing Wallet."
1
+ {
2
+ "name": "turing-wallet-provider",
3
+ "version": "1.2.4",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "scripts": {
10
+ "build": "tsc"
11
+ },
12
+ "peerDependencies": {
13
+ "react": ">=17.0.0",
14
+ "react-dom": ">=17.0.0"
15
+ },
16
+ "devDependencies": {
17
+ "typescript": "^4.5.0",
18
+ "@types/react": "^17.0.0",
19
+ "@types/react-dom": "^17.0.0"
20
+ },
21
+ "keywords": [
22
+ "wallet",
23
+ "tbc",
24
+ "turing wallet"
25
+ ],
26
+ "description": "A provider help to connect Turing Wallet."
27
27
  }