mainnet-js 1.1.1 → 1.1.3
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/dist/index.html +1 -1
- package/dist/{mainnet-1.1.1.js → mainnet-1.1.3.js} +4 -4
- package/dist/module/libauth.d.ts +1 -1
- package/dist/module/libauth.d.ts.map +1 -1
- package/dist/module/libauth.js +1 -1
- package/dist/module/libauth.js.map +1 -1
- package/dist/module/transaction/Wif.d.ts +42 -7
- package/dist/module/transaction/Wif.d.ts.map +1 -1
- package/dist/module/transaction/Wif.js +132 -107
- package/dist/module/transaction/Wif.js.map +1 -1
- package/dist/module/wallet/Slp.d.ts.map +1 -1
- package/dist/module/wallet/Slp.js +11 -1
- package/dist/module/wallet/Slp.js.map +1 -1
- package/dist/module/wallet/Wif.d.ts +8 -4
- package/dist/module/wallet/Wif.d.ts.map +1 -1
- package/dist/module/wallet/Wif.js +119 -55
- package/dist/module/wallet/Wif.js.map +1 -1
- package/dist/module/wallet/interface.d.ts +2 -0
- package/dist/module/wallet/interface.d.ts.map +1 -1
- package/dist/module/wallet/model.d.ts +4 -0
- package/dist/module/wallet/model.d.ts.map +1 -1
- package/dist/module/wallet/model.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/libauth.ts +1 -0
- package/src/transaction/Wif.ts +207 -155
- package/src/wallet/Cashtokens.test.headless.js +161 -0
- package/src/wallet/Cashtokens.test.ts +179 -1
- package/src/wallet/Slp.ts +10 -7
- package/src/wallet/Wif.test.ts +101 -1
- package/src/wallet/Wif.ts +160 -92
- package/src/wallet/interface.ts +2 -0
- package/src/wallet/model.ts +6 -0
|
@@ -77,6 +77,8 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
77
77
|
new TokenSendRequest({
|
|
78
78
|
cashaddr: bob.cashaddr,
|
|
79
79
|
tokenId: tokenId,
|
|
80
|
+
capability: NFTCapability.mutable,
|
|
81
|
+
commitment: "abcd",
|
|
80
82
|
}),
|
|
81
83
|
]);
|
|
82
84
|
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
@@ -135,6 +137,7 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
135
137
|
new TokenSendRequest({
|
|
136
138
|
cashaddr: alice.cashaddr,
|
|
137
139
|
tokenId: tokenId,
|
|
140
|
+
capability: NFTCapability.mutable,
|
|
138
141
|
commitment: "abcd02",
|
|
139
142
|
}),
|
|
140
143
|
]);
|
|
@@ -163,9 +166,13 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
163
166
|
const response = await alice.tokenMint(tokenId, [
|
|
164
167
|
new TokenMintRequest({
|
|
165
168
|
cashaddr: alice.cashaddr,
|
|
169
|
+
commitment: "test",
|
|
170
|
+
capability: NFTCapability.none,
|
|
166
171
|
}),
|
|
167
172
|
new TokenMintRequest({
|
|
168
173
|
cashaddr: alice.cashaddr,
|
|
174
|
+
commitment: "test2",
|
|
175
|
+
capability: NFTCapability.none,
|
|
169
176
|
}),
|
|
170
177
|
]);
|
|
171
178
|
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
@@ -197,9 +204,13 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
197
204
|
[
|
|
198
205
|
new TokenMintRequest({
|
|
199
206
|
cashaddr: alice.cashaddr,
|
|
207
|
+
capability: NFTCapability.none,
|
|
208
|
+
commitment: "0a",
|
|
200
209
|
}),
|
|
201
210
|
new TokenMintRequest({
|
|
202
211
|
cashaddr: alice.cashaddr,
|
|
212
|
+
capability: NFTCapability.none,
|
|
213
|
+
commitment: "0b",
|
|
203
214
|
}),
|
|
204
215
|
],
|
|
205
216
|
true
|
|
@@ -215,9 +226,13 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
215
226
|
[
|
|
216
227
|
new TokenMintRequest({
|
|
217
228
|
cashaddr: alice.cashaddr,
|
|
229
|
+
capability: NFTCapability.none,
|
|
230
|
+
commitment: "0c",
|
|
218
231
|
}),
|
|
219
232
|
new TokenMintRequest({
|
|
220
233
|
cashaddr: alice.cashaddr,
|
|
234
|
+
capability: NFTCapability.none,
|
|
235
|
+
commitment: "0d",
|
|
221
236
|
}),
|
|
222
237
|
],
|
|
223
238
|
false
|
|
@@ -234,12 +249,18 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
234
249
|
[
|
|
235
250
|
new TokenMintRequest({
|
|
236
251
|
cashaddr: alice.cashaddr,
|
|
252
|
+
capability: NFTCapability.none,
|
|
253
|
+
commitment: "0a",
|
|
237
254
|
}),
|
|
238
255
|
new TokenMintRequest({
|
|
239
256
|
cashaddr: alice.cashaddr,
|
|
257
|
+
capability: NFTCapability.none,
|
|
258
|
+
commitment: "0a",
|
|
240
259
|
}),
|
|
241
260
|
new TokenMintRequest({
|
|
242
261
|
cashaddr: alice.cashaddr,
|
|
262
|
+
capability: NFTCapability.none,
|
|
263
|
+
commitment: "0a",
|
|
243
264
|
}),
|
|
244
265
|
],
|
|
245
266
|
true
|
|
@@ -425,6 +446,8 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
425
446
|
const genesisResponse = await alice.tokenGenesis({
|
|
426
447
|
amount: 100,
|
|
427
448
|
value: 5000,
|
|
449
|
+
capability: NFTCapability.minting,
|
|
450
|
+
commitment: "test",
|
|
428
451
|
cashaddr: alice.cashaddr,
|
|
429
452
|
});
|
|
430
453
|
|
|
@@ -444,6 +467,8 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
444
467
|
amount: 100,
|
|
445
468
|
tokenId: tokenId,
|
|
446
469
|
value: 1500,
|
|
470
|
+
capability: NFTCapability.minting,
|
|
471
|
+
commitment: "test",
|
|
447
472
|
}),
|
|
448
473
|
]),
|
|
449
474
|
0
|
|
@@ -464,4 +489,140 @@ describe(`Wallet should function in the browser`, () => {
|
|
|
464
489
|
await Promise.all([cancel(), delay(1000)]);
|
|
465
490
|
}, process.env.ALICE_ID);
|
|
466
491
|
});
|
|
492
|
+
|
|
493
|
+
test("Should encode unsigned transactions", async () => {
|
|
494
|
+
await page.evaluate(async (id) => {
|
|
495
|
+
const binsAreEqual = (a, b) => {
|
|
496
|
+
if (a.length !== b.length) {
|
|
497
|
+
return false;
|
|
498
|
+
}
|
|
499
|
+
// eslint-disable-next-line functional/no-let, functional/no-loop-statement, no-plusplus
|
|
500
|
+
for (let i = 0; i < a.length; i++) {
|
|
501
|
+
if (a[i] !== b[i]) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
return true;
|
|
506
|
+
};
|
|
507
|
+
|
|
508
|
+
const aliceWallet = await RegTestWallet.fromId(id);
|
|
509
|
+
const aliceWatchWallet = await RegTestWallet.watchOnly(
|
|
510
|
+
aliceWallet.cashaddr
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
{
|
|
514
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
515
|
+
|
|
516
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
517
|
+
await aliceWatchWallet.tokenGenesis(
|
|
518
|
+
{
|
|
519
|
+
capability: "minting",
|
|
520
|
+
commitment: "00",
|
|
521
|
+
},
|
|
522
|
+
undefined,
|
|
523
|
+
{ buildUnsigned: true }
|
|
524
|
+
);
|
|
525
|
+
const encodedTransaction = hexToBin(unsignedTransaction);
|
|
526
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
527
|
+
|
|
528
|
+
// check transaction was not submitted
|
|
529
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
530
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
531
|
+
);
|
|
532
|
+
|
|
533
|
+
const decoded = libauth.decodeTransaction(encodedTransaction);
|
|
534
|
+
if (typeof decoded === "string") {
|
|
535
|
+
throw decoded;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
expect(
|
|
539
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
540
|
+
).toBe(true);
|
|
541
|
+
expect(sourceOutputs.length).toBe(decoded.inputs.length);
|
|
542
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment)).toBe("00");
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
const genesisResponse = await aliceWallet.tokenGenesis({
|
|
546
|
+
capability: "minting",
|
|
547
|
+
commitment: "00",
|
|
548
|
+
});
|
|
549
|
+
const tokenId = genesisResponse.tokenIds[0];
|
|
550
|
+
|
|
551
|
+
{
|
|
552
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
553
|
+
|
|
554
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
555
|
+
await aliceWatchWallet.tokenMint(
|
|
556
|
+
tokenId,
|
|
557
|
+
{
|
|
558
|
+
capability: "none",
|
|
559
|
+
commitment: "0a",
|
|
560
|
+
},
|
|
561
|
+
undefined,
|
|
562
|
+
{ buildUnsigned: true }
|
|
563
|
+
);
|
|
564
|
+
const encodedTransaction = hexToBin(unsignedTransaction);
|
|
565
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
566
|
+
|
|
567
|
+
// check transaction was not submitted
|
|
568
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
569
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
const decoded = libauth.decodeTransaction(encodedTransaction);
|
|
573
|
+
if (typeof decoded === "string") {
|
|
574
|
+
throw decoded;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
expect(
|
|
578
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
579
|
+
).toBe(true);
|
|
580
|
+
expect(sourceOutputs.length).toBe(decoded.inputs.length);
|
|
581
|
+
expect(binToHex(sourceOutputs[0].token?.nft?.commitment)).toBe("00");
|
|
582
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment)).toBe("00");
|
|
583
|
+
expect(binToHex(decoded.outputs[1].token?.nft?.commitment)).toBe("0a");
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
await aliceWallet.tokenMint(tokenId, {
|
|
587
|
+
capability: "none",
|
|
588
|
+
commitment: "0a",
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
{
|
|
592
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
593
|
+
|
|
594
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
595
|
+
await aliceWatchWallet.send(
|
|
596
|
+
[
|
|
597
|
+
new TokenSendRequest({
|
|
598
|
+
tokenId: tokenId,
|
|
599
|
+
capability: "none",
|
|
600
|
+
commitment: "0a",
|
|
601
|
+
cashaddr: aliceWallet.cashaddr,
|
|
602
|
+
}),
|
|
603
|
+
],
|
|
604
|
+
{ buildUnsigned: true }
|
|
605
|
+
);
|
|
606
|
+
const encodedTransaction = hexToBin(unsignedTransaction);
|
|
607
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
608
|
+
|
|
609
|
+
// check transaction was not submitted
|
|
610
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
611
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
612
|
+
);
|
|
613
|
+
|
|
614
|
+
const decoded = libauth.decodeTransaction(encodedTransaction);
|
|
615
|
+
if (typeof decoded === "string") {
|
|
616
|
+
throw decoded;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
expect(
|
|
620
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
621
|
+
).toBe(true);
|
|
622
|
+
expect(sourceOutputs.length).toBe(decoded.inputs.length);
|
|
623
|
+
expect(binToHex(sourceOutputs[0].token?.nft?.commitment)).toBe("0a");
|
|
624
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment)).toBe("0a");
|
|
625
|
+
}
|
|
626
|
+
}, process.env.ALICE_ID);
|
|
627
|
+
});
|
|
467
628
|
});
|
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { RegTestWallet, TestNetWallet, Wallet } from "./Wif";
|
|
2
2
|
import { initProviders, disconnectProviders } from "../network/Connection";
|
|
3
3
|
import {
|
|
4
|
+
OpReturnData,
|
|
4
5
|
SendRequest,
|
|
5
6
|
SendResponse,
|
|
6
7
|
TokenMintRequest,
|
|
7
8
|
TokenSendRequest,
|
|
8
9
|
} from "./model";
|
|
9
10
|
import { Network, NFTCapability } from "../interface";
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
binToHex,
|
|
13
|
+
binsAreEqual,
|
|
14
|
+
decodeTransaction,
|
|
15
|
+
hexToBin,
|
|
16
|
+
utf8ToBin,
|
|
17
|
+
} from "@bitauth/libauth";
|
|
11
18
|
import { delay } from "../util";
|
|
12
19
|
import { Config } from "../config";
|
|
13
20
|
|
|
@@ -134,6 +141,8 @@ describe(`Test cashtokens`, () => {
|
|
|
134
141
|
{
|
|
135
142
|
cashaddr: bob.cashaddr!,
|
|
136
143
|
tokenId: tokenId,
|
|
144
|
+
capability: NFTCapability.mutable,
|
|
145
|
+
commitment: "abcd",
|
|
137
146
|
} as any,
|
|
138
147
|
]);
|
|
139
148
|
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
@@ -189,6 +198,7 @@ describe(`Test cashtokens`, () => {
|
|
|
189
198
|
new TokenSendRequest({
|
|
190
199
|
cashaddr: alice.cashaddr!,
|
|
191
200
|
tokenId: tokenId,
|
|
201
|
+
capability: NFTCapability.mutable,
|
|
192
202
|
commitment: "abcd02",
|
|
193
203
|
}),
|
|
194
204
|
]);
|
|
@@ -221,6 +231,7 @@ describe(`Test cashtokens`, () => {
|
|
|
221
231
|
new TokenMintRequest({
|
|
222
232
|
cashaddr: alice.cashaddr!,
|
|
223
233
|
commitment: "test2",
|
|
234
|
+
capability: NFTCapability.none,
|
|
224
235
|
}),
|
|
225
236
|
]);
|
|
226
237
|
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
@@ -250,9 +261,13 @@ describe(`Test cashtokens`, () => {
|
|
|
250
261
|
[
|
|
251
262
|
new TokenMintRequest({
|
|
252
263
|
cashaddr: alice.cashaddr!,
|
|
264
|
+
capability: NFTCapability.none,
|
|
265
|
+
commitment: "0a",
|
|
253
266
|
}),
|
|
254
267
|
new TokenMintRequest({
|
|
255
268
|
cashaddr: alice.cashaddr!,
|
|
269
|
+
capability: NFTCapability.none,
|
|
270
|
+
commitment: "0b",
|
|
256
271
|
}),
|
|
257
272
|
],
|
|
258
273
|
true
|
|
@@ -268,9 +283,13 @@ describe(`Test cashtokens`, () => {
|
|
|
268
283
|
[
|
|
269
284
|
new TokenMintRequest({
|
|
270
285
|
cashaddr: alice.cashaddr!,
|
|
286
|
+
capability: NFTCapability.none,
|
|
287
|
+
commitment: "0c",
|
|
271
288
|
}),
|
|
272
289
|
new TokenMintRequest({
|
|
273
290
|
cashaddr: alice.cashaddr!,
|
|
291
|
+
capability: NFTCapability.none,
|
|
292
|
+
commitment: "0d",
|
|
274
293
|
}),
|
|
275
294
|
],
|
|
276
295
|
false
|
|
@@ -287,12 +306,18 @@ describe(`Test cashtokens`, () => {
|
|
|
287
306
|
[
|
|
288
307
|
new TokenMintRequest({
|
|
289
308
|
cashaddr: alice.cashaddr!,
|
|
309
|
+
capability: NFTCapability.none,
|
|
310
|
+
commitment: "0a",
|
|
290
311
|
}),
|
|
291
312
|
new TokenMintRequest({
|
|
292
313
|
cashaddr: alice.cashaddr!,
|
|
314
|
+
capability: NFTCapability.none,
|
|
315
|
+
commitment: "0a",
|
|
293
316
|
}),
|
|
294
317
|
new TokenMintRequest({
|
|
295
318
|
cashaddr: alice.cashaddr!,
|
|
319
|
+
capability: NFTCapability.none,
|
|
320
|
+
commitment: "0a",
|
|
296
321
|
}),
|
|
297
322
|
],
|
|
298
323
|
true
|
|
@@ -492,6 +517,8 @@ describe(`Test cashtokens`, () => {
|
|
|
492
517
|
amount: 100,
|
|
493
518
|
tokenId: tokenId,
|
|
494
519
|
value: 1500,
|
|
520
|
+
capability: NFTCapability.minting,
|
|
521
|
+
commitment: "test",
|
|
495
522
|
}),
|
|
496
523
|
])),
|
|
497
524
|
0
|
|
@@ -803,6 +830,157 @@ describe(`Test cashtokens`, () => {
|
|
|
803
830
|
);
|
|
804
831
|
});
|
|
805
832
|
|
|
833
|
+
test("Should encode unsigned transactions", async () => {
|
|
834
|
+
const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
|
|
835
|
+
const aliceWallet = await RegTestWallet.fromId(aliceWif);
|
|
836
|
+
const aliceWatchWallet = await RegTestWallet.watchOnly(
|
|
837
|
+
aliceWallet.cashaddr!
|
|
838
|
+
);
|
|
839
|
+
|
|
840
|
+
{
|
|
841
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
842
|
+
|
|
843
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
844
|
+
await aliceWatchWallet.tokenGenesis(
|
|
845
|
+
{
|
|
846
|
+
capability: "minting",
|
|
847
|
+
commitment: "00",
|
|
848
|
+
},
|
|
849
|
+
undefined,
|
|
850
|
+
{ buildUnsigned: true }
|
|
851
|
+
);
|
|
852
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
853
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
854
|
+
|
|
855
|
+
// check transaction was not submitted
|
|
856
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
857
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
861
|
+
if (typeof decoded === "string") {
|
|
862
|
+
throw decoded;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
expect(
|
|
866
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
867
|
+
).toBe(true);
|
|
868
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
869
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
const genesisResponse = await aliceWallet.tokenGenesis({
|
|
873
|
+
capability: "minting",
|
|
874
|
+
commitment: "00",
|
|
875
|
+
});
|
|
876
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
877
|
+
|
|
878
|
+
{
|
|
879
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
880
|
+
|
|
881
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
882
|
+
await aliceWatchWallet.tokenMint(
|
|
883
|
+
tokenId,
|
|
884
|
+
{
|
|
885
|
+
capability: "none",
|
|
886
|
+
commitment: "0a",
|
|
887
|
+
},
|
|
888
|
+
undefined,
|
|
889
|
+
{ buildUnsigned: true }
|
|
890
|
+
);
|
|
891
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
892
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
893
|
+
|
|
894
|
+
// check transaction was not submitted
|
|
895
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
896
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
900
|
+
if (typeof decoded === "string") {
|
|
901
|
+
throw decoded;
|
|
902
|
+
}
|
|
903
|
+
|
|
904
|
+
expect(
|
|
905
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
906
|
+
).toBe(true);
|
|
907
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
908
|
+
expect(binToHex(sourceOutputs![0].token?.nft?.commitment!)).toBe("00");
|
|
909
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
|
|
910
|
+
expect(binToHex(decoded.outputs[1].token?.nft?.commitment!)).toBe("0a");
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
await aliceWallet.tokenMint(tokenId, {
|
|
914
|
+
capability: "none",
|
|
915
|
+
commitment: "0a",
|
|
916
|
+
});
|
|
917
|
+
|
|
918
|
+
{
|
|
919
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
920
|
+
|
|
921
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
922
|
+
await aliceWatchWallet.send(
|
|
923
|
+
[
|
|
924
|
+
new TokenSendRequest({
|
|
925
|
+
tokenId: tokenId,
|
|
926
|
+
capability: "none",
|
|
927
|
+
commitment: "0a",
|
|
928
|
+
cashaddr: aliceWallet.cashaddr!,
|
|
929
|
+
}),
|
|
930
|
+
],
|
|
931
|
+
{ buildUnsigned: true }
|
|
932
|
+
);
|
|
933
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
934
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
935
|
+
|
|
936
|
+
// check transaction was not submitted
|
|
937
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
938
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
939
|
+
);
|
|
940
|
+
|
|
941
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
942
|
+
if (typeof decoded === "string") {
|
|
943
|
+
throw decoded;
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
expect(
|
|
947
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
948
|
+
).toBe(true);
|
|
949
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
950
|
+
expect(binToHex(sourceOutputs![0].token?.nft?.commitment!)).toBe("0a");
|
|
951
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("0a");
|
|
952
|
+
}
|
|
953
|
+
});
|
|
954
|
+
|
|
955
|
+
test("Kek", async () => {
|
|
956
|
+
const aliceWatchWallet = await TestNetWallet.watchOnly("bchtest:zzm0t7f76ye50xh2hr0lmt2a0wage2sutcqnl25ahq");
|
|
957
|
+
|
|
958
|
+
// const utxos = (await aliceWatchWallet.getTokenUtxos()).filter(val => val.token?.tokenId.startsWith("4cca"));
|
|
959
|
+
// console.log(utxos);
|
|
960
|
+
// return;
|
|
961
|
+
|
|
962
|
+
|
|
963
|
+
const { unsignedTransaction, sourceOutputs } = await aliceWatchWallet.tokenGenesis({
|
|
964
|
+
cashaddr: aliceWatchWallet.cashaddr!,
|
|
965
|
+
capability: NFTCapability.minting,
|
|
966
|
+
commitment: "",
|
|
967
|
+
value: 1000
|
|
968
|
+
}, OpReturnData.from(""), { buildUnsigned: true });
|
|
969
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
970
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
971
|
+
|
|
972
|
+
// const decoded = decodeTransaction(encodedTransaction);
|
|
973
|
+
// if (typeof decoded === "string") {
|
|
974
|
+
// throw decoded;
|
|
975
|
+
// }
|
|
976
|
+
|
|
977
|
+
// expect(binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))).toBe(true);
|
|
978
|
+
// expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
979
|
+
// expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
|
|
980
|
+
|
|
981
|
+
});
|
|
982
|
+
|
|
983
|
+
|
|
806
984
|
test("Test enforcing token addresses", async () => {
|
|
807
985
|
const bob = await RegTestWallet.newRandom();
|
|
808
986
|
|
package/src/wallet/Slp.ts
CHANGED
|
@@ -682,6 +682,7 @@ export class Slp {
|
|
|
682
682
|
utxos: fundingBchUtxos,
|
|
683
683
|
sendRequests: slpOutputsResult.BchSendRequests,
|
|
684
684
|
privateKey: this.wallet.privateKey,
|
|
685
|
+
sourceAddress: this.wallet.cashaddr!,
|
|
685
686
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
686
687
|
slpOutputs: slpOutputsResult.SlpOutputs,
|
|
687
688
|
feePaidBy: FeePaidByEnum.change,
|
|
@@ -709,19 +710,21 @@ export class Slp {
|
|
|
709
710
|
utxos: fundingUtxos,
|
|
710
711
|
sendRequests: slpOutputsResult.BchSendRequests,
|
|
711
712
|
privateKey: this.wallet.privateKey,
|
|
713
|
+
sourceAddress: this.wallet.cashaddr!,
|
|
712
714
|
relayFeePerByteInSatoshi: relayFeePerByteInSatoshi,
|
|
713
715
|
slpOutputs: slpOutputsResult.SlpOutputs,
|
|
714
716
|
feePaidBy: FeePaidByEnum.change,
|
|
715
717
|
});
|
|
716
718
|
|
|
717
|
-
const encodedTransaction = await buildEncodedTransaction(
|
|
718
|
-
fundingUtxos,
|
|
719
|
-
slpOutputsResult.BchSendRequests,
|
|
720
|
-
this.wallet.privateKey,
|
|
719
|
+
const { encodedTransaction } = await buildEncodedTransaction({
|
|
720
|
+
inputs: fundingUtxos,
|
|
721
|
+
outputs: slpOutputsResult.BchSendRequests,
|
|
722
|
+
signingKey: this.wallet.privateKey,
|
|
723
|
+
sourceAddress: this.wallet.cashaddr!,
|
|
721
724
|
fee,
|
|
722
|
-
false,
|
|
723
|
-
slpOutputsResult.SlpOutputs
|
|
724
|
-
);
|
|
725
|
+
discardChange: false,
|
|
726
|
+
slpOutputs: slpOutputsResult.SlpOutputs,
|
|
727
|
+
});
|
|
725
728
|
|
|
726
729
|
return this._submitTransaction(encodedTransaction, tokenId);
|
|
727
730
|
}
|
package/src/wallet/Wif.test.ts
CHANGED
|
@@ -7,7 +7,13 @@ import { DERIVATION_PATHS, DUST_UTXO_THRESHOLD as DUST } from "../constant";
|
|
|
7
7
|
import { delay } from "../util/delay";
|
|
8
8
|
import { OpReturnData, SendResponse } from "./model";
|
|
9
9
|
import { ElectrumRawTransaction } from "../network/interface";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
binToHex,
|
|
12
|
+
binsAreEqual,
|
|
13
|
+
decodeTransaction,
|
|
14
|
+
hexToBin,
|
|
15
|
+
utf8ToBin,
|
|
16
|
+
} from "@bitauth/libauth";
|
|
11
17
|
import { mine } from "../mine";
|
|
12
18
|
import ElectrumNetworkProvider from "../network/ElectrumNetworkProvider";
|
|
13
19
|
|
|
@@ -1114,4 +1120,98 @@ describe(`Wallet extrema behavior regression testing`, () => {
|
|
|
1114
1120
|
(await bob.getMaxAmountToSend({ options: { slpSemiAware: false } })).sat
|
|
1115
1121
|
).toBeLessThanOrEqual(546);
|
|
1116
1122
|
});
|
|
1123
|
+
|
|
1124
|
+
test("Should encode unsigned transactions", async () => {
|
|
1125
|
+
const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
|
|
1126
|
+
const aliceWallet = await RegTestWallet.fromId(aliceWif);
|
|
1127
|
+
const bobWallet = await RegTestWallet.newRandom();
|
|
1128
|
+
aliceWallet.privateKey = undefined;
|
|
1129
|
+
|
|
1130
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
1131
|
+
|
|
1132
|
+
{
|
|
1133
|
+
const { encodedTransaction, sourceOutputs } =
|
|
1134
|
+
await aliceWallet.encodeTransaction(
|
|
1135
|
+
[
|
|
1136
|
+
{
|
|
1137
|
+
cashaddr: bobWallet.cashaddr!,
|
|
1138
|
+
value: 2000,
|
|
1139
|
+
unit: "satoshis",
|
|
1140
|
+
},
|
|
1141
|
+
],
|
|
1142
|
+
false,
|
|
1143
|
+
{ buildUnsigned: true }
|
|
1144
|
+
);
|
|
1145
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
1146
|
+
|
|
1147
|
+
// check transaction was not submitted
|
|
1148
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
1149
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
1150
|
+
);
|
|
1151
|
+
|
|
1152
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
1153
|
+
if (typeof decoded === "string") {
|
|
1154
|
+
throw decoded;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
expect(
|
|
1158
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
1159
|
+
).toBe(true);
|
|
1160
|
+
expect(sourceOutputs.length).toBe(decoded.inputs.length);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
{
|
|
1164
|
+
const { unsignedTransaction, sourceOutputs } = await aliceWallet.send(
|
|
1165
|
+
[
|
|
1166
|
+
{
|
|
1167
|
+
cashaddr: bobWallet.cashaddr!,
|
|
1168
|
+
value: 2000,
|
|
1169
|
+
unit: "satoshis",
|
|
1170
|
+
},
|
|
1171
|
+
],
|
|
1172
|
+
{ buildUnsigned: true }
|
|
1173
|
+
);
|
|
1174
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
1175
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
1176
|
+
|
|
1177
|
+
// check transaction was not submitted
|
|
1178
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
1179
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
1180
|
+
);
|
|
1181
|
+
|
|
1182
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
1183
|
+
if (typeof decoded === "string") {
|
|
1184
|
+
throw decoded;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
expect(
|
|
1188
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
1189
|
+
).toBe(true);
|
|
1190
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
{
|
|
1194
|
+
const { unsignedTransaction, sourceOutputs } = await aliceWallet.sendMax(
|
|
1195
|
+
bobWallet.cashaddr!,
|
|
1196
|
+
{ buildUnsigned: true }
|
|
1197
|
+
);
|
|
1198
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
1199
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
1200
|
+
|
|
1201
|
+
// check transaction was not submitted
|
|
1202
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
1203
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
1204
|
+
);
|
|
1205
|
+
|
|
1206
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
1207
|
+
if (typeof decoded === "string") {
|
|
1208
|
+
throw decoded;
|
|
1209
|
+
}
|
|
1210
|
+
|
|
1211
|
+
expect(
|
|
1212
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
1213
|
+
).toBe(true);
|
|
1214
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
1215
|
+
}
|
|
1216
|
+
});
|
|
1117
1217
|
});
|