turing-wallet-provider 1.1.1 → 1.1.2

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,327 +1,328 @@
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
- ```
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
- address?: 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;
167
- };
168
-
169
- const params = [param:RequestParam] //目前参数里只能放一个对象,有批量发送需求再扩展
170
- ```
171
-
172
- #### P2PKH
173
-
174
- ```
175
- const params = [{
176
- flag:"P2PKH",
177
- satoshis: 1000,
178
- address: "",
179
- }] ;
180
- const { txid, rawtx } = await wallet.sendTransaction(params);
181
- ```
182
-
183
- #### COLLECTION_CREATE
184
-
185
- ```
186
- const params = [{
187
- flag:"COLLECTION_CREATE",
188
- collection_data:"",
189
- }];
190
- const { txid, rawtx } = await wallet.sendTransaction(params);
191
- ```
192
-
193
- #### NFT_CREATE
194
-
195
- ```
196
- const params = [{
197
- flag:"NFT_CREATE",
198
- nft_data:"",
199
- collection_id:""
200
- }];
201
- const { txid, rawtx } = await wallet.sendTransaction(params);
202
- ```
203
-
204
- #### NFT_TRANSFER
205
-
206
- ```ts
207
- const params = [{
208
- flag:"NFT_TRANSFER",
209
- nft_contract_address:"",
210
- address:""
211
- }];
212
- const { txid, rawtx } = await wallet.sendTransaction(params);
213
- ```
214
-
215
- #### FT_MINT
216
-
217
- ```
218
- const params = [{
219
- flag:"FT_MINT",
220
- ft_data:""
221
- }];
222
- const { txid, rawtx } = await wallet.sendTransaction(params);
223
- ```
224
-
225
- #### FT_TRANSFER
226
-
227
- ```
228
- const params = [{
229
- flag:"FT_TRANSFER",
230
- ft_contract_address:"",
231
- ft_amount:0.1,
232
- address::""
233
- }];
234
- const { txid, rawtx } = await wallet.sendTransaction(params);
235
- ```
236
-
237
- #### POOLNFT_MINT
238
-
239
- ```
240
- const params = [{
241
- flag:"POOLNFT_MINT",
242
- ft_contract_address:"",
243
- }];
244
- const { txid, rawtx } = await wallet.sendTransaction(params);
245
- ```
246
-
247
- #### POOLNFT_INIT
248
-
249
- ```
250
- const params = [{
251
- flag:"POOLNFT_INIT",
252
- nft_contract_address:"",
253
- address:"",
254
- tbc_amount:30,
255
- ft_amount:1000
256
- }];
257
- const { txid, rawtx } = await wallet.sendTransaction(params);
258
- ```
259
-
260
- #### POOLNFT_LP_INCREASE
261
-
262
- ```
263
- const params = [{
264
- flag:"POOLNFT_LP_INCREASE",
265
- nft_contract_address:"",
266
- address:"",
267
- tbc_amount:3
268
- }];
269
- const { txid, rawtx } = await wallet.sendTransaction(params);
270
- ```
271
-
272
- #### POOLNFT_LP_CONSUME
273
-
274
- ```
275
- const params = [{
276
- flag:"POOLNFT_LP_CONSUME",
277
- nft_contract_address:"",
278
- address:""
279
- ft_amount:100
280
- }];
281
- const { txid, rawtx } = await wallet.sendTransaction(params);
282
- ```
283
-
284
- #### POOLNFT_SWAP_TO_TOKEN
285
-
286
- ```
287
- const params = [{
288
- flag:"POOLNFT_SWAP_TO_TOKEN",
289
- nft_contract_address:"",
290
- address:"",
291
- tbc_amount:10
292
- }];
293
- const { txid, rawtx } = await wallet.sendTransaction(params);
294
- ```
295
-
296
- #### POOLNFT_SWAP_TO_TBC
297
-
298
- ```
299
- const params = [{
300
- flag:"POOLNFT_SWAP_TO_TBC",
301
- nft_contract_address:"",
302
- address:"",
303
- ft_amount:10
304
- }];
305
- const { txid, rawtx } = await wallet.sendTransaction(params);
306
- ```
307
-
308
- #### POOLNFT_MERGE
309
-
310
- ```
311
- const params = [{
312
- flag:"POOLNFT_MERGE",
313
- nft_contract_address:"",
314
- merge_times:1; //1-10次
315
- }];
316
- const { txid, rawtx } = await wallet.sendTransaction(params);
317
- ```
318
-
319
- #### FTLP_MERGE
320
-
321
- ```
322
- const params = [{
323
- flag:"FTLP_MERGE",
324
- nft_contract_address:""
325
- }];
326
- const { txid, rawtx } = await wallet.sendTransaction(params);
327
- ```
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
+ ```
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
+ address?: 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;
167
+ };
168
+
169
+ const params = [param:RequestParam] //目前参数里只能放一个对象,有批量发送需求再扩展
170
+ ```
171
+
172
+ #### P2PKH
173
+
174
+ ```
175
+ const params = [{
176
+ flag:"P2PKH",
177
+ satoshis: 1000,
178
+ address: "",
179
+ }] ;
180
+ const { txid, rawtx } = await wallet.sendTransaction(params);
181
+ ```
182
+
183
+ #### COLLECTION_CREATE
184
+
185
+ ```
186
+ const params = [{
187
+ flag:"COLLECTION_CREATE",
188
+ collection_data:"",
189
+ }];
190
+ const { txid, rawtx } = await wallet.sendTransaction(params);
191
+ ```
192
+
193
+ #### NFT_CREATE
194
+
195
+ ```
196
+ const params = [{
197
+ flag:"NFT_CREATE",
198
+ nft_data:"",
199
+ collection_id:""
200
+ }];
201
+ const { txid, rawtx } = await wallet.sendTransaction(params);
202
+ ```
203
+
204
+ #### NFT_TRANSFER
205
+
206
+ ```ts
207
+ const params = [{
208
+ flag:"NFT_TRANSFER",
209
+ nft_contract_address:"",
210
+ address:""
211
+ }];
212
+ const { txid, rawtx } = await wallet.sendTransaction(params);
213
+ ```
214
+
215
+ #### FT_MINT
216
+
217
+ ```
218
+ const params = [{
219
+ flag:"FT_MINT",
220
+ ft_data:""
221
+ }];
222
+ const { txid, rawtx } = await wallet.sendTransaction(params);
223
+ ```
224
+
225
+ #### FT_TRANSFER
226
+
227
+ ```
228
+ const params = [{
229
+ flag:"FT_TRANSFER",
230
+ ft_contract_address:"",
231
+ ft_amount:0.1,
232
+ address::""
233
+ }];
234
+ const { txid, rawtx } = await wallet.sendTransaction(params);
235
+ ```
236
+
237
+ #### POOLNFT_MINT
238
+
239
+ ```
240
+ const params = [{
241
+ flag:"POOLNFT_MINT",
242
+ ft_contract_address:"",
243
+ with_lock?:false //默认值为false,为true则创建带哈希锁的poolNFT
244
+ }];
245
+ const { txid, rawtx } = await wallet.sendTransaction(params);
246
+ ```
247
+
248
+ #### POOLNFT_INIT
249
+
250
+ ```
251
+ const params = [{
252
+ flag:"POOLNFT_INIT",
253
+ nft_contract_address:"",
254
+ address:"",
255
+ tbc_amount:30,
256
+ ft_amount:1000
257
+ }];
258
+ const { txid, rawtx } = await wallet.sendTransaction(params);
259
+ ```
260
+
261
+ #### POOLNFT_LP_INCREASE
262
+
263
+ ```
264
+ const params = [{
265
+ flag:"POOLNFT_LP_INCREASE",
266
+ nft_contract_address:"",
267
+ address:"",
268
+ tbc_amount:3
269
+ }];
270
+ const { txid, rawtx } = await wallet.sendTransaction(params);
271
+ ```
272
+
273
+ #### POOLNFT_LP_CONSUME
274
+
275
+ ```
276
+ const params = [{
277
+ flag:"POOLNFT_LP_CONSUME",
278
+ nft_contract_address:"",
279
+ address:""
280
+ ft_amount:100
281
+ }];
282
+ const { txid, rawtx } = await wallet.sendTransaction(params);
283
+ ```
284
+
285
+ #### POOLNFT_SWAP_TO_TOKEN
286
+
287
+ ```
288
+ const params = [{
289
+ flag:"POOLNFT_SWAP_TO_TOKEN",
290
+ nft_contract_address:"",
291
+ address:"",
292
+ tbc_amount:10
293
+ }];
294
+ const { txid, rawtx } = await wallet.sendTransaction(params);
295
+ ```
296
+
297
+ #### POOLNFT_SWAP_TO_TBC
298
+
299
+ ```
300
+ const params = [{
301
+ flag:"POOLNFT_SWAP_TO_TBC",
302
+ nft_contract_address:"",
303
+ address:"",
304
+ ft_amount:10
305
+ }];
306
+ const { txid, rawtx } = await wallet.sendTransaction(params);
307
+ ```
308
+
309
+ #### POOLNFT_MERGE
310
+
311
+ ```
312
+ const params = [{
313
+ flag:"POOLNFT_MERGE",
314
+ nft_contract_address:"",
315
+ merge_times:1; //1-10次
316
+ }];
317
+ const { txid, rawtx } = await wallet.sendTransaction(params);
318
+ ```
319
+
320
+ #### FTLP_MERGE
321
+
322
+ ```
323
+ const params = [{
324
+ flag:"FTLP_MERGE",
325
+ nft_contract_address:""
326
+ }];
327
+ const { txid, rawtx } = await wallet.sendTransaction(params);
328
+ ```
@@ -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,84 +1,84 @@
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 = "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";
21
-
22
- export type SendTransaction = {
23
- flag: TransactionFlag;
24
- satoshis?: number;
25
- address?: string;
26
- collection_data?: string;
27
- ft_data?: string;
28
- nft_data?: string;
29
- collection_id?: string;
30
- nft_contract_address?: string;
31
- ft_contract_address?: string;
32
- tbc_amount?: number;
33
- ft_amount?: number;
34
- merge_times?: number;
35
- };
36
-
37
- export type SignMessage = {
38
- message: string;
39
- encoding?: "utf8" | "hex" | "base64";
40
- };
41
-
42
- export type Utxos = {
43
- satoshis: number;
44
- script: string;
45
- txid: string;
46
- vout: number;
47
- };
48
-
49
- export type SendTransactionResponse = {
50
- txid: string;
51
- rawtx: string;
52
- };
53
-
54
- export type Encrypt = {
55
- message: string;
56
- };
57
-
58
- export type Decrypt = {
59
- message: string;
60
- };
61
-
62
- export type EncryptResponse = {
63
- encryptedMessage: string;
64
- };
65
-
66
- export type DecryptResponse = {
67
- decryptedMessage: string;
68
- };
69
-
70
-
71
- export type TuringProviderType = {
72
- isReady: boolean;
73
- connect: () => Promise<string | undefined>;
74
- disconnect: () => Promise<boolean>;
75
- isConnected: () => Promise<boolean>;
76
- getPubKey: () => Promise<PubKey | undefined>;
77
- getAddress: () => Promise<Address | undefined>;
78
- getBalance: () => Promise<Balance | undefined>;
79
- sendTransaction: (params: SendTransaction[]) => Promise<SendTransactionResponse | undefined>;
80
- signMessage: (params: SignMessage) => Promise<SignedMessage | undefined>;
81
- getPaymentUtxos: () => Promise<Utxos[] | undefined>;
82
- encrypt: (params: Encrypt) => Promise<EncryptResponse | undefined>;
83
- decrypt: (params: Decrypt) => Promise<DecryptResponse | undefined>;
84
- }
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 = "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";
21
+
22
+ export type SendTransaction = {
23
+ flag: TransactionFlag;
24
+ satoshis?: number;
25
+ address?: string;
26
+ collection_data?: string;
27
+ ft_data?: string;
28
+ nft_data?: string;
29
+ collection_id?: string;
30
+ nft_contract_address?: string;
31
+ ft_contract_address?: string;
32
+ tbc_amount?: number;
33
+ ft_amount?: number;
34
+ merge_times?: number;
35
+ };
36
+
37
+ export type SignMessage = {
38
+ message: string;
39
+ encoding?: "utf8" | "hex" | "base64";
40
+ };
41
+
42
+ export type Utxos = {
43
+ satoshis: number;
44
+ script: string;
45
+ txid: string;
46
+ vout: number;
47
+ };
48
+
49
+ export type SendTransactionResponse = {
50
+ txid: string;
51
+ rawtx: string;
52
+ };
53
+
54
+ export type Encrypt = {
55
+ message: string;
56
+ };
57
+
58
+ export type Decrypt = {
59
+ message: string;
60
+ };
61
+
62
+ export type EncryptResponse = {
63
+ encryptedMessage: string;
64
+ };
65
+
66
+ export type DecryptResponse = {
67
+ decryptedMessage: string;
68
+ };
69
+
70
+
71
+ export type TuringProviderType = {
72
+ isReady: boolean;
73
+ connect: () => Promise<string | undefined>;
74
+ disconnect: () => Promise<boolean>;
75
+ isConnected: () => Promise<boolean>;
76
+ getPubKey: () => Promise<PubKey | undefined>;
77
+ getAddress: () => Promise<Address | undefined>;
78
+ getBalance: () => Promise<Balance | undefined>;
79
+ sendTransaction: (params: SendTransaction[]) => Promise<SendTransactionResponse | undefined>;
80
+ signMessage: (params: SignMessage) => Promise<SignedMessage | undefined>;
81
+ getPaymentUtxos: () => Promise<Utxos[] | undefined>;
82
+ encrypt: (params: Encrypt) => Promise<EncryptResponse | undefined>;
83
+ decrypt: (params: Decrypt) => Promise<DecryptResponse | undefined>;
84
+ }
@@ -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,31 +1,31 @@
1
- {
2
- "name": "turing-wallet-provider",
3
- "version": "1.1.1",
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
- "turing",
24
- "tbc",
25
- "bitcoin",
26
- "turing wallet"
27
- ],
28
- "author": "Joe",
29
- "license": "ISC",
30
- "description": "A provider that makes interacting with Turing Wallet a walk in the park."
1
+ {
2
+ "name": "turing-wallet-provider",
3
+ "version": "1.1.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
+ "turing",
24
+ "tbc",
25
+ "bitcoin",
26
+ "turing wallet"
27
+ ],
28
+ "author": "Joe",
29
+ "license": "ISC",
30
+ "description": "A provider that makes interacting with Turing Wallet a walk in the park."
31
31
  }