turing-wallet-provider 1.0.10 → 1.0.12

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 ADDED
@@ -0,0 +1,300 @@
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(err);
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
+ ### sendTransaction
102
+
103
+ ```tsx
104
+ interface FTData {
105
+ ​ name :string;
106
+ symbol :string;
107
+ ​ decimal :number;
108
+ ​ amount :number;
109
+ };
110
+
111
+ interface CollectionData {
112
+ collectionName: string;
113
+ description: string;
114
+ supply: number;
115
+ file: string;//file为图片base64编码后数据
116
+ };
117
+
118
+ interface NFTData {
119
+ nftName: string;
120
+ symbol: string;
121
+ discription: string;
122
+ attributes: string;
123
+ file?: string;//file为图片base64编码后数据,若无则为引用合集图片
124
+ };
125
+
126
+ interface RequestParam = {
127
+ 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";
128
+ address?: string;//交易接收者地址
129
+ satoshis?: number;//单位为satoshis
130
+ collection_data?: string; //json格式传
131
+ ft_data?: string; //json格式传
132
+ nft_data?: string; //json格式传
133
+ collection_id?: string;
134
+ nft_contract_address?: string;
135
+ ft_contract_address?: string;
136
+ tbc_amount?: number;
137
+ ft_amount?: number;
138
+ merge_times?:number;
139
+ };
140
+
141
+ const params = [param:RequestParam] //目前参数里只能放一个对象,有批量发送需求再扩展
142
+ ```
143
+
144
+ #### P2PKH
145
+
146
+ ```
147
+ const params = [{
148
+ flag:"P2PKH",
149
+ satoshis: 1000,
150
+ address: "",
151
+ }] ;
152
+ const { txid, rawtx } = await wallet.sendTransaction(params);
153
+ ```
154
+
155
+ #### COLLECTION_CREATE
156
+
157
+ ```
158
+ const params = [{
159
+ flag:"COLLECTION_CREATE",
160
+ collection_data:"",
161
+ }];
162
+ const { txid, rawtx } = await wallet.sendTransaction(params);
163
+ ```
164
+
165
+ #### NFT_CREATE
166
+
167
+ ```
168
+ const params = [{
169
+ flag:"NFT_CREATE",
170
+ nft_data:"",
171
+ collection_id:""
172
+ }];
173
+ const { txid, rawtx } = await wallet.sendTransaction(params);
174
+ ```
175
+
176
+ #### NFT_TRANSFER
177
+
178
+ ```ts
179
+ const params = [{
180
+ flag:"NFT_TRANSFER",
181
+ nft_contract_address:"",
182
+ address:""
183
+ }];
184
+ const { txid, rawtx } = await wallet.sendTransaction(params);
185
+ ```
186
+
187
+ #### FT_MINT
188
+
189
+ ```
190
+ const params = [{
191
+ flag:"FT_MINT",
192
+ ft_data:""
193
+ }];
194
+ const { txid, rawtx } = await wallet.sendTransaction(params);
195
+ ```
196
+
197
+ #### FT_TRANSFER
198
+
199
+ ```
200
+ const params = [{
201
+ flag:"FT_TRANSFER",
202
+ ft_contract_address:"",
203
+ ft_amount:0.1,
204
+ address::""
205
+ }];
206
+ const { txid, rawtx } = await wallet.sendTransaction(params);
207
+ ```
208
+
209
+ #### POOLNFT_MINT
210
+
211
+ ```
212
+ const params = [{
213
+ flag:"POOLNFT_MINT",
214
+ ft_contract_address:"",
215
+ }];
216
+ const { txid, rawtx } = await wallet.sendTransaction(params);
217
+ ```
218
+
219
+ #### POOLNFT_INIT
220
+
221
+ ```
222
+ const params = [{
223
+ flag:"POOLNFT_INIT",
224
+ nft_contract_address:"",
225
+ address:"",
226
+ tbc_amount:30,
227
+ ft_amount:1000
228
+ }];
229
+ const { txid, rawtx } = await wallet.sendTransaction(params);
230
+ ```
231
+
232
+ #### POOLNFT_LP_INCREASE
233
+
234
+ ```
235
+ const params = [{
236
+ flag:"POOLNFT_LP_INCREASE",
237
+ nft_contract_address:"",
238
+ address:"",
239
+ tbc_amount:3
240
+ }];
241
+ const { txid, rawtx } = await wallet.sendTransaction(params);
242
+ ```
243
+
244
+ #### POOLNFT_LP_CONSUME
245
+
246
+ ```
247
+ const params = [{
248
+ flag:"POOLNFT_LP_CONSUME",
249
+ nft_contract_address:"",
250
+ address:""
251
+ ft_amount:100
252
+ }];
253
+ const { txid, rawtx } = await wallet.sendTransaction(params);
254
+ ```
255
+
256
+ #### POOLNFT_SWAP_TO_TOKEN
257
+
258
+ ```
259
+ const params = [{
260
+ flag:"POOLNFT_SWAP_TO_TOKEN",
261
+ nft_contract_address:"",
262
+ address:"",
263
+ tbc_amount:10
264
+ }];
265
+ const { txid, rawtx } = await wallet.sendTransaction(params);
266
+ ```
267
+
268
+ #### POOLNFT_SWAP_TO_TBC
269
+
270
+ ```
271
+ const params = [{
272
+ flag:"POOLNFT_SWAP_TO_TBC",
273
+ nft_contract_address:"",
274
+ address:"",
275
+ ft_amount:10
276
+ }];
277
+ const { txid, rawtx } = await wallet.sendTransaction(params);
278
+ ```
279
+
280
+ #### POOLNFT_MERGE
281
+
282
+ ```
283
+ const params = [{
284
+ flag:"POOLNFT_MERGE",
285
+ nft_contract_address:"",
286
+ merge_times:1; //1-10次
287
+ }];
288
+ const { txid, rawtx } = await wallet.sendTransaction(params);
289
+ ```
290
+
291
+ #### FTLP_MERGE
292
+
293
+ ```
294
+ const params = [{
295
+ flag:"POOLNFT_MERGE",
296
+ nft_contract_address:""
297
+ }];
298
+ const { txid, rawtx } = await wallet.sendTransaction(params);
299
+ ```
300
+
@@ -1,98 +1,24 @@
1
1
  export type PubKey = {
2
2
  tbcPubKey: string;
3
- // ordPubKey: string;
4
- // identityPubKey: string;
5
3
  };
4
+
6
5
  export type Address = {
7
6
  tbcAddress: string;
8
- // ordAddress: string;
9
- // identityAddress: string;
10
7
  };
8
+
11
9
  export type Balance = {
12
10
  tbc: number;
13
- // satoshis: number;
14
- // usdInCents: number;
15
- };
16
- export type SocialProfile = {
17
- displayName: string;
18
- avatar: string;
19
- };
20
- export type OrdinalData = {
21
- types?: string[];
22
- insc?: Inscription;
23
- map?: {
24
- [key: string]: any;
25
- };
26
- b?: File;
27
- sigma?: Sigma[];
28
- list?: Listing;
29
- tbc20?: Tbc20;
30
- lock?: Lock;
31
- };
32
- export type Lock = {
33
- address: string;
34
- until: number;
35
- };
36
- export type Sigma = {
37
- algorithm: string;
38
- address: string;
39
- signature: string;
40
- vin: number;
41
- };
42
- export type Listing = {
43
- price: number;
44
- payout: string;
45
- };
46
- export type Tbc20 = {
47
- id?: string;
48
- p: string;
49
- op: string;
50
- tick?: string;
51
- amt: string;
52
- status?: Tbc20Status;
53
- };
54
- export type Origin = {
55
- outpoint: string;
56
- data?: OrdinalData;
57
- num?: number;
58
- };
59
- export declare enum Tbc20Status {
60
- Invalid = -1,
61
- Pending = 0,
62
- Valid = 1
63
- }
64
- export type File = {
65
- type: string;
66
- size: number;
67
- hash: string;
68
- };
69
- export type Inscription = {
70
- json?: any;
71
- text?: string;
72
- words?: string[];
73
- file: File;
74
- };
75
- export type Ordinal = {
76
- txid: string;
77
- vout: number;
78
- outpoint: string;
79
- satoshis: number;
80
- owner: string;
81
- script: string;
82
- spend: string;
83
- origin: Origin;
84
- height: number;
85
- idx: number;
86
- data: OrdinalData;
87
11
  };
12
+
88
13
  export type SignedMessage = {
89
14
  address: string;
90
15
  pubKey: string;
91
16
  sig: string;
92
17
  message: string;
93
- derivationTag: DerivationTag;
94
18
  };
19
+
95
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
+
96
22
  export type SendTransaction = {
97
23
  flag: TransactionFlag;
98
24
  satoshis?: number;
@@ -107,135 +33,24 @@ export type SendTransaction = {
107
33
  ft_amount?: number;
108
34
  merge_times?: number;
109
35
  };
110
- export type TransferOrdinal = {
111
- address: string;
112
- origin: string;
113
- outpoint: string;
114
- };
115
- export type InternalTuringTags = {
116
- label: "Turing";
117
- id: "tbc";
118
- domain: "";
119
- meta: {};
120
- } | {
121
- label: "Turing";
122
- id: "ord";
123
- domain: "";
124
- meta: {};
125
- } | {
126
- label: "Turing";
127
- id: "identity";
128
- domain: "";
129
- meta: {};
130
- };
131
- export type DerivationTag = InternalTuringTags | {
132
- label: string;
133
- id: string;
134
- domain: string;
135
- meta?: Record<string, any>;
136
- };
36
+
137
37
  export type SignMessage = {
138
38
  message: string;
139
39
  encoding?: "utf8" | "hex" | "base64";
140
40
  };
141
- export type KeyTypes = "tbc" | "ord";
142
- export type Broadcast = {
143
- rawtx: string;
144
- fund?: boolean;
145
- };
146
- export type PurchaseOrdinal = {
147
- outpoint: string;
148
- marketplaceRate?: number;
149
- marketplaceAddress?: string;
150
- };
41
+
151
42
  export type Utxos = {
152
43
  satoshis: number;
153
44
  script: string;
154
45
  txid: string;
155
46
  vout: number;
156
47
  };
157
- /**
158
- * `SignatureRequest` contains required informations for a signer to sign a certain input of a transaction.
159
- */
160
- export type SignatureRequest = {
161
- prevTxid: string;
162
- outputIndex: number;
163
- /** The index of input to sign. */
164
- inputIndex: number;
165
- /** The previous output satoshis value of the input to spend. */
166
- satoshis: number;
167
- /** The address(es) of corresponding private key(s) required to sign the input. */
168
- address: string | string[];
169
- /** The previous output script of input, default value is a P2PKH locking script for the `address` if omitted. */
170
- script?: string;
171
- /** The sighash type, default value is `SIGHASH_ALL | SIGHASH_FORKID` if omitted. */
172
- sigHashType?: number;
173
- /**
174
- * Index of the OP_CODESEPARATOR to split the previous output script at during verification.
175
- * If undefined, the whole script is used.
176
- * */
177
- csIdx?: number;
178
- /** The flag to distinguish the transaction.*/
179
- flag: TransactionFlag;
180
- };
181
- /**
182
- * `SignatureResponse` contains the signing result corresponding to a `SignatureRequest`.
183
- */
184
- export type SignatureResponse = {
185
- /** The index of input. */
186
- inputIndex: number;
187
- /** The signature.*/
188
- sig: string;
189
- /** The public key bound with the `sig`. */
190
- pubKey: string;
191
- /** The sighash type, default value is `SIGHASH_ALL | SIGHASH_FORKID` if omitted. */
192
- sigHashType: number;
193
- /** The index of the OP_CODESEPARATOR to split the previous output script at.*/
194
- csIdx?: number;
195
- };
196
- /**
197
- * `SendTbcResponse` contains the result of sendTbc.
198
- */
48
+
199
49
  export type SendTransactionResponse = {
200
50
  txid: string;
201
51
  rawtx: string;
202
52
  };
203
- export type GetSignatures = {
204
- rawtx: string;
205
- sigRequests: SignatureRequest[];
206
- };
207
- export type TaggedDerivationRequest = {
208
- label: string;
209
- id: string;
210
- meta?: Record<string, any>;
211
- };
212
- export type TaggedDerivationResponse = {
213
- address: string;
214
- pubKey: string;
215
- tag: DerivationTag;
216
- };
217
- export type MimeTypes = "text/plain" | "text/html" | "text/css" | "application/javascript" | "application/json" | "application/xml" | "image/jpeg" | "image/png" | "image/gif" | "image/svg+xml" | "audio/mpeg" | "audio/wav" | "audio/wave" | "video/mp4" | "application/pdf" | "application/msword" | "application/vnd.ms-excel" | "application/vnd.ms-powerpoint" | "application/zip" | "application/x-7z-compressed" | "application/x-gzip" | "application/x-tar" | "application/x-bzip2";
218
- export type MAP = {
219
- app: string;
220
- type: string;
221
- [prop: string]: string;
222
- };
223
- export type RawInscription = {
224
- base64Data: string;
225
- mimeType: MimeTypes;
226
- map?: MAP;
227
- };
228
- export type InscribeRequest = {
229
- address: string;
230
- base64Data: string;
231
- mimeType: MimeTypes;
232
- map?: MAP;
233
- satoshis?: number;
234
- };
235
- export type GetTaggedKeysRequest = {
236
- label: string;
237
- ids?: string[];
238
- };
53
+
239
54
  export type TuringProviderType = {
240
55
  isReady: boolean;
241
56
  connect: () => Promise<string | undefined>;
@@ -243,18 +58,8 @@ export type TuringProviderType = {
243
58
  isConnected: () => Promise<boolean>;
244
59
  getPubKey: () => Promise<PubKey | undefined>;
245
60
  getAddress: () => Promise<Address | undefined>;
246
- // getSocialProfile: () => Promise<SocialProfile | undefined>;
247
61
  getBalance: () => Promise<Balance | undefined>;
248
- // getOrdinals: () => Promise<Ordinal[] | undefined>;
249
62
  sendTransaction: (params: SendTransaction[]) => Promise<SendTransactionResponse | undefined>;
250
- // transferOrdinal: (params: TransferOrdinal) => Promise<string | undefined>;
251
- // purchaseOrdinal: (params: PurchaseOrdinal) => Promise<string | undefined>;
252
63
  signMessage: (params: SignMessage) => Promise<SignedMessage | undefined>;
253
- // getSignatures: (params: GetSignatures) => Promise<SignatureResponse[] | undefined>;
254
- broadcast: (params: Broadcast) => Promise<string | undefined>;
255
- // getExchangeRate: () => Promise<number | undefined>;
256
64
  getPaymentUtxos: () => Promise<Utxos[] | undefined>;
257
- // generateTaggedKeys: (params: TaggedDerivationRequest) => Promise<TaggedDerivationResponse>;
258
- // getTaggedKeys: (params: GetTaggedKeysRequest) => Promise<TaggedDerivationResponse[] | undefined>;
259
- // inscribe: (params: InscribeRequest[]) => Promise<SendTbcResponse | undefined>;
260
- };
65
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turing-wallet-provider",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [