mainnet-js 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/dist/index.html +1 -1
- package/dist/{mainnet-1.1.1.js → mainnet-1.1.2.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 +128 -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 +121 -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 +200 -155
- package/src/wallet/Cashtokens.test.headless.js +161 -0
- package/src/wallet/Cashtokens.test.ts +149 -1
- package/src/wallet/Slp.ts +10 -7
- package/src/wallet/Wif.test.ts +101 -1
- package/src/wallet/Wif.ts +161 -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
|
});
|
|
@@ -7,7 +7,13 @@ import {
|
|
|
7
7
|
TokenSendRequest,
|
|
8
8
|
} from "./model";
|
|
9
9
|
import { Network, NFTCapability } from "../interface";
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
binToHex,
|
|
12
|
+
binsAreEqual,
|
|
13
|
+
decodeTransaction,
|
|
14
|
+
hexToBin,
|
|
15
|
+
utf8ToBin,
|
|
16
|
+
} from "@bitauth/libauth";
|
|
11
17
|
import { delay } from "../util";
|
|
12
18
|
import { Config } from "../config";
|
|
13
19
|
|
|
@@ -134,6 +140,8 @@ describe(`Test cashtokens`, () => {
|
|
|
134
140
|
{
|
|
135
141
|
cashaddr: bob.cashaddr!,
|
|
136
142
|
tokenId: tokenId,
|
|
143
|
+
capability: NFTCapability.mutable,
|
|
144
|
+
commitment: "abcd",
|
|
137
145
|
} as any,
|
|
138
146
|
]);
|
|
139
147
|
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
@@ -189,6 +197,7 @@ describe(`Test cashtokens`, () => {
|
|
|
189
197
|
new TokenSendRequest({
|
|
190
198
|
cashaddr: alice.cashaddr!,
|
|
191
199
|
tokenId: tokenId,
|
|
200
|
+
capability: NFTCapability.mutable,
|
|
192
201
|
commitment: "abcd02",
|
|
193
202
|
}),
|
|
194
203
|
]);
|
|
@@ -221,6 +230,7 @@ describe(`Test cashtokens`, () => {
|
|
|
221
230
|
new TokenMintRequest({
|
|
222
231
|
cashaddr: alice.cashaddr!,
|
|
223
232
|
commitment: "test2",
|
|
233
|
+
capability: NFTCapability.none,
|
|
224
234
|
}),
|
|
225
235
|
]);
|
|
226
236
|
expect(await alice.getTokenBalance(tokenId)).toBe(0);
|
|
@@ -250,9 +260,13 @@ describe(`Test cashtokens`, () => {
|
|
|
250
260
|
[
|
|
251
261
|
new TokenMintRequest({
|
|
252
262
|
cashaddr: alice.cashaddr!,
|
|
263
|
+
capability: NFTCapability.none,
|
|
264
|
+
commitment: "0a",
|
|
253
265
|
}),
|
|
254
266
|
new TokenMintRequest({
|
|
255
267
|
cashaddr: alice.cashaddr!,
|
|
268
|
+
capability: NFTCapability.none,
|
|
269
|
+
commitment: "0b",
|
|
256
270
|
}),
|
|
257
271
|
],
|
|
258
272
|
true
|
|
@@ -268,9 +282,13 @@ describe(`Test cashtokens`, () => {
|
|
|
268
282
|
[
|
|
269
283
|
new TokenMintRequest({
|
|
270
284
|
cashaddr: alice.cashaddr!,
|
|
285
|
+
capability: NFTCapability.none,
|
|
286
|
+
commitment: "0c",
|
|
271
287
|
}),
|
|
272
288
|
new TokenMintRequest({
|
|
273
289
|
cashaddr: alice.cashaddr!,
|
|
290
|
+
capability: NFTCapability.none,
|
|
291
|
+
commitment: "0d",
|
|
274
292
|
}),
|
|
275
293
|
],
|
|
276
294
|
false
|
|
@@ -287,12 +305,18 @@ describe(`Test cashtokens`, () => {
|
|
|
287
305
|
[
|
|
288
306
|
new TokenMintRequest({
|
|
289
307
|
cashaddr: alice.cashaddr!,
|
|
308
|
+
capability: NFTCapability.none,
|
|
309
|
+
commitment: "0a",
|
|
290
310
|
}),
|
|
291
311
|
new TokenMintRequest({
|
|
292
312
|
cashaddr: alice.cashaddr!,
|
|
313
|
+
capability: NFTCapability.none,
|
|
314
|
+
commitment: "0a",
|
|
293
315
|
}),
|
|
294
316
|
new TokenMintRequest({
|
|
295
317
|
cashaddr: alice.cashaddr!,
|
|
318
|
+
capability: NFTCapability.none,
|
|
319
|
+
commitment: "0a",
|
|
296
320
|
}),
|
|
297
321
|
],
|
|
298
322
|
true
|
|
@@ -492,6 +516,8 @@ describe(`Test cashtokens`, () => {
|
|
|
492
516
|
amount: 100,
|
|
493
517
|
tokenId: tokenId,
|
|
494
518
|
value: 1500,
|
|
519
|
+
capability: NFTCapability.minting,
|
|
520
|
+
commitment: "test",
|
|
495
521
|
}),
|
|
496
522
|
])),
|
|
497
523
|
0
|
|
@@ -803,6 +829,128 @@ describe(`Test cashtokens`, () => {
|
|
|
803
829
|
);
|
|
804
830
|
});
|
|
805
831
|
|
|
832
|
+
test("Should encode unsigned transactions", async () => {
|
|
833
|
+
const aliceWif = `wif:regtest:${process.env.PRIVATE_WIF!}`;
|
|
834
|
+
const aliceWallet = await RegTestWallet.fromId(aliceWif);
|
|
835
|
+
const aliceWatchWallet = await RegTestWallet.watchOnly(
|
|
836
|
+
aliceWallet.cashaddr!
|
|
837
|
+
);
|
|
838
|
+
|
|
839
|
+
{
|
|
840
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
841
|
+
|
|
842
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
843
|
+
await aliceWatchWallet.tokenGenesis(
|
|
844
|
+
{
|
|
845
|
+
capability: "minting",
|
|
846
|
+
commitment: "00",
|
|
847
|
+
},
|
|
848
|
+
undefined,
|
|
849
|
+
{ buildUnsigned: true }
|
|
850
|
+
);
|
|
851
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
852
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
853
|
+
|
|
854
|
+
// check transaction was not submitted
|
|
855
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
856
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
857
|
+
);
|
|
858
|
+
|
|
859
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
860
|
+
if (typeof decoded === "string") {
|
|
861
|
+
throw decoded;
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
expect(
|
|
865
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
866
|
+
).toBe(true);
|
|
867
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
868
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
const genesisResponse = await aliceWallet.tokenGenesis({
|
|
872
|
+
capability: "minting",
|
|
873
|
+
commitment: "00",
|
|
874
|
+
});
|
|
875
|
+
const tokenId = genesisResponse.tokenIds![0];
|
|
876
|
+
|
|
877
|
+
{
|
|
878
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
879
|
+
|
|
880
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
881
|
+
await aliceWatchWallet.tokenMint(
|
|
882
|
+
tokenId,
|
|
883
|
+
{
|
|
884
|
+
capability: "none",
|
|
885
|
+
commitment: "0a",
|
|
886
|
+
},
|
|
887
|
+
undefined,
|
|
888
|
+
{ buildUnsigned: true }
|
|
889
|
+
);
|
|
890
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
891
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
892
|
+
|
|
893
|
+
// check transaction was not submitted
|
|
894
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
895
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
896
|
+
);
|
|
897
|
+
|
|
898
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
899
|
+
if (typeof decoded === "string") {
|
|
900
|
+
throw decoded;
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
expect(
|
|
904
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
905
|
+
).toBe(true);
|
|
906
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
907
|
+
expect(binToHex(sourceOutputs![0].token?.nft?.commitment!)).toBe("00");
|
|
908
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("00");
|
|
909
|
+
expect(binToHex(decoded.outputs[1].token?.nft?.commitment!)).toBe("0a");
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
await aliceWallet.tokenMint(tokenId, {
|
|
913
|
+
capability: "none",
|
|
914
|
+
commitment: "0a",
|
|
915
|
+
});
|
|
916
|
+
|
|
917
|
+
{
|
|
918
|
+
const aliceUtxos = await aliceWallet.getAddressUtxos();
|
|
919
|
+
|
|
920
|
+
const { unsignedTransaction, sourceOutputs } =
|
|
921
|
+
await aliceWatchWallet.send(
|
|
922
|
+
[
|
|
923
|
+
new TokenSendRequest({
|
|
924
|
+
tokenId: tokenId,
|
|
925
|
+
capability: "none",
|
|
926
|
+
commitment: "0a",
|
|
927
|
+
cashaddr: aliceWallet.cashaddr!,
|
|
928
|
+
}),
|
|
929
|
+
],
|
|
930
|
+
{ buildUnsigned: true }
|
|
931
|
+
);
|
|
932
|
+
const encodedTransaction = hexToBin(unsignedTransaction!);
|
|
933
|
+
expect(encodedTransaction.length).toBeGreaterThan(0);
|
|
934
|
+
|
|
935
|
+
// check transaction was not submitted
|
|
936
|
+
expect(JSON.stringify(aliceUtxos)).toBe(
|
|
937
|
+
JSON.stringify(await aliceWallet.getAddressUtxos())
|
|
938
|
+
);
|
|
939
|
+
|
|
940
|
+
const decoded = decodeTransaction(encodedTransaction);
|
|
941
|
+
if (typeof decoded === "string") {
|
|
942
|
+
throw decoded;
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
expect(
|
|
946
|
+
binsAreEqual(decoded.inputs[0].unlockingBytecode, Uint8Array.from([]))
|
|
947
|
+
).toBe(true);
|
|
948
|
+
expect(sourceOutputs!.length).toBe(decoded.inputs.length);
|
|
949
|
+
expect(binToHex(sourceOutputs![0].token?.nft?.commitment!)).toBe("0a");
|
|
950
|
+
expect(binToHex(decoded.outputs[0].token?.nft?.commitment!)).toBe("0a");
|
|
951
|
+
}
|
|
952
|
+
});
|
|
953
|
+
|
|
806
954
|
test("Test enforcing token addresses", async () => {
|
|
807
955
|
const bob = await RegTestWallet.newRandom();
|
|
808
956
|
|
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
|
});
|