mainnet-js 2.7.31 → 3.0.0-next.0

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.
Files changed (126) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.7.31.js → mainnet-3.0.0-next.0.js} +718 -678
  3. package/dist/module/cache/MemoryCache.d.ts +0 -1
  4. package/dist/module/cache/MemoryCache.d.ts.map +1 -1
  5. package/dist/module/cache/MemoryCache.js +5 -7
  6. package/dist/module/cache/MemoryCache.js.map +1 -1
  7. package/dist/module/cache/index.d.ts +1 -0
  8. package/dist/module/cache/index.d.ts.map +1 -1
  9. package/dist/module/cache/index.js +1 -0
  10. package/dist/module/cache/index.js.map +1 -1
  11. package/dist/module/cache/walletCache.d.ts +39 -0
  12. package/dist/module/cache/walletCache.d.ts.map +1 -0
  13. package/dist/module/cache/walletCache.js +141 -0
  14. package/dist/module/cache/walletCache.js.map +1 -0
  15. package/dist/module/history/{electrumTransformer.d.ts → getHistory.d.ts} +3 -3
  16. package/dist/module/history/getHistory.d.ts.map +1 -0
  17. package/dist/module/history/{electrumTransformer.js → getHistory.js} +47 -14
  18. package/dist/module/history/getHistory.js.map +1 -0
  19. package/dist/module/index.d.ts +3 -1
  20. package/dist/module/index.d.ts.map +1 -1
  21. package/dist/module/index.js +3 -1
  22. package/dist/module/index.js.map +1 -1
  23. package/dist/module/interface.d.ts +7 -1
  24. package/dist/module/interface.d.ts.map +1 -1
  25. package/dist/module/interface.js.map +1 -1
  26. package/dist/module/message/interface.d.ts +2 -2
  27. package/dist/module/message/interface.d.ts.map +1 -1
  28. package/dist/module/message/interface.js +0 -3
  29. package/dist/module/message/interface.js.map +1 -1
  30. package/dist/module/message/signed.d.ts +5 -5
  31. package/dist/module/message/signed.d.ts.map +1 -1
  32. package/dist/module/message/signed.js +14 -14
  33. package/dist/module/message/signed.js.map +1 -1
  34. package/dist/module/network/ElectrumNetworkProvider.d.ts +2 -2
  35. package/dist/module/network/ElectrumNetworkProvider.d.ts.map +1 -1
  36. package/dist/module/network/ElectrumNetworkProvider.js +2 -1
  37. package/dist/module/network/ElectrumNetworkProvider.js.map +1 -1
  38. package/dist/module/network/NetworkProvider.d.ts +2 -2
  39. package/dist/module/network/NetworkProvider.d.ts.map +1 -1
  40. package/dist/module/network/constant.js +4 -4
  41. package/dist/module/network/constant.js.map +1 -1
  42. package/dist/module/transaction/Wif.d.ts +21 -19
  43. package/dist/module/transaction/Wif.d.ts.map +1 -1
  44. package/dist/module/transaction/Wif.js +18 -15
  45. package/dist/module/transaction/Wif.js.map +1 -1
  46. package/dist/module/util/checkUtxos.d.ts +2 -2
  47. package/dist/module/util/checkUtxos.d.ts.map +1 -1
  48. package/dist/module/util/checkUtxos.js +11 -12
  49. package/dist/module/util/checkUtxos.js.map +1 -1
  50. package/dist/module/util/deriveCashaddr.d.ts.map +1 -1
  51. package/dist/module/util/deriveCashaddr.js +6 -0
  52. package/dist/module/util/deriveCashaddr.js.map +1 -1
  53. package/dist/module/util/deriveNetwork.js +1 -1
  54. package/dist/module/util/deriveNetwork.js.map +1 -1
  55. package/dist/module/util/hd.d.ts +3 -0
  56. package/dist/module/util/hd.d.ts.map +1 -0
  57. package/dist/module/util/hd.js +11 -0
  58. package/dist/module/util/hd.js.map +1 -0
  59. package/dist/module/util/index.d.ts +1 -0
  60. package/dist/module/util/index.d.ts.map +1 -1
  61. package/dist/module/util/index.js +1 -0
  62. package/dist/module/util/index.js.map +1 -1
  63. package/dist/module/util/sumUtxoValue.d.ts +3 -3
  64. package/dist/module/util/sumUtxoValue.d.ts.map +1 -1
  65. package/dist/module/util/sumUtxoValue.js.map +1 -1
  66. package/dist/module/wallet/Base.d.ts +37 -93
  67. package/dist/module/wallet/Base.d.ts.map +1 -1
  68. package/dist/module/wallet/Base.js +83 -250
  69. package/dist/module/wallet/Base.js.map +1 -1
  70. package/dist/module/wallet/HDWallet.d.ts +164 -0
  71. package/dist/module/wallet/HDWallet.d.ts.map +1 -0
  72. package/dist/module/wallet/HDWallet.js +486 -0
  73. package/dist/module/wallet/HDWallet.js.map +1 -0
  74. package/dist/module/wallet/Watch.d.ts +151 -0
  75. package/dist/module/wallet/Watch.d.ts.map +1 -0
  76. package/dist/module/wallet/Watch.js +307 -0
  77. package/dist/module/wallet/Watch.js.map +1 -0
  78. package/dist/module/wallet/Wif.d.ts +23 -29
  79. package/dist/module/wallet/Wif.d.ts.map +1 -1
  80. package/dist/module/wallet/Wif.js +204 -267
  81. package/dist/module/wallet/Wif.js.map +1 -1
  82. package/dist/module/wallet/createWallet.d.ts +7 -1
  83. package/dist/module/wallet/createWallet.d.ts.map +1 -1
  84. package/dist/module/wallet/createWallet.js +26 -17
  85. package/dist/module/wallet/createWallet.js.map +1 -1
  86. package/dist/module/wallet/interface.d.ts +3 -3
  87. package/dist/module/wallet/interface.d.ts.map +1 -1
  88. package/dist/module/wallet/model.d.ts +3 -3
  89. package/dist/module/wallet/model.d.ts.map +1 -1
  90. package/dist/module/wallet/model.js +2 -18
  91. package/dist/module/wallet/model.js.map +1 -1
  92. package/dist/tsconfig.tsbuildinfo +1 -1
  93. package/package.json +1 -1
  94. package/src/cache/MemoryCache.ts +5 -5
  95. package/src/cache/index.ts +1 -0
  96. package/src/cache/walletCache.ts +252 -0
  97. package/src/history/{electrumTransformer.test.ts → getHistory.test.ts} +6 -19
  98. package/src/history/{electrumTransformer.ts → getHistory.ts} +63 -15
  99. package/src/index.ts +3 -1
  100. package/src/interface.ts +8 -1
  101. package/src/message/interface.ts +2 -28
  102. package/src/message/signed.test.ts +56 -48
  103. package/src/message/signed.ts +15 -18
  104. package/src/network/ElectrumNetworkProvider.ts +4 -4
  105. package/src/network/NetworkProvider.ts +2 -2
  106. package/src/network/Rpc.test.ts +1 -1
  107. package/src/network/constant.ts +4 -4
  108. package/src/transaction/Wif.ts +41 -35
  109. package/src/util/checkUtxos.ts +21 -26
  110. package/src/util/deriveCashaddr.ts +8 -0
  111. package/src/util/deriveNetwork.ts +1 -1
  112. package/src/util/derivePublicKeyHash.test.ts +0 -13
  113. package/src/util/hd.ts +16 -0
  114. package/src/util/index.ts +1 -0
  115. package/src/util/sumUtxoValue.ts +5 -5
  116. package/src/wallet/Base.ts +123 -332
  117. package/src/wallet/HDWallet.test.ts +372 -0
  118. package/src/wallet/HDWallet.ts +764 -0
  119. package/src/wallet/Watch.ts +447 -0
  120. package/src/wallet/Wif.ts +258 -283
  121. package/src/wallet/createWallet.ts +28 -18
  122. package/src/wallet/interface.ts +3 -3
  123. package/src/wallet/model.test.ts +2 -2
  124. package/src/wallet/model.ts +6 -23
  125. package/dist/module/history/electrumTransformer.d.ts.map +0 -1
  126. package/dist/module/history/electrumTransformer.js.map +0 -1
@@ -1,6 +1,5 @@
1
1
  import {
2
2
  walletTemplateP2pkhNonHd,
3
- walletTemplateToCompilerBCH,
4
3
  cashAddressToLockingBytecode,
5
4
  Compiler,
6
5
  encodeTransaction,
@@ -8,14 +7,15 @@ import {
8
7
  importWalletTemplate,
9
8
  AnyCompilerConfiguration,
10
9
  AuthenticationProgramStateCommon,
11
- CompilationContextBCH,
12
10
  Output,
13
11
  hexToBin,
14
12
  verifyTransactionTokens,
15
13
  decodeTransaction,
16
14
  TransactionTemplateFixed,
15
+ CompilationContextBch,
16
+ walletTemplateToCompilerBch,
17
17
  } from "@bitauth/libauth";
18
- import { NFTCapability, TokenI, UtxoI } from "../interface.js";
18
+ import { NFTCapability, TokenI, Utxo } from "../interface.js";
19
19
  import { allocateFee } from "./allocateFee.js";
20
20
 
21
21
  import { DUST_UTXO_THRESHOLD } from "../constant.js";
@@ -30,26 +30,31 @@ import { amountInSatoshi } from "../util/amountInSatoshi.js";
30
30
  import { sumSendRequestAmounts } from "../util/sumSendRequestAmounts.js";
31
31
  import { sumUtxoValue } from "../util/sumUtxoValue.js";
32
32
  import { FeePaidByEnum } from "../wallet/enum.js";
33
+ import { WalletCacheI } from "../cache/walletCache.js";
34
+
35
+ export const placeholderPrivateKey =
36
+ "0000000000000000000000000000000000000000000000000000000000000001";
37
+ export const placeholderPrivateKeyBin = hexToBin(placeholderPrivateKey);
33
38
 
34
39
  // Build a transaction for a p2pkh transaction for a non HD wallet
35
40
  export async function buildP2pkhNonHdTransaction({
36
41
  inputs,
37
42
  outputs,
38
43
  signingKey,
39
- sourceAddress,
40
44
  fee = 0,
41
45
  discardChange = false,
42
46
  feePaidBy = FeePaidByEnum.change,
43
47
  changeAddress = "",
48
+ walletCache,
44
49
  }: {
45
- inputs: UtxoI[];
50
+ inputs: Utxo[];
46
51
  outputs: Array<SendRequest | TokenSendRequest | OpReturnData>;
47
- signingKey: Uint8Array;
48
- sourceAddress: string;
52
+ signingKey?: Uint8Array;
49
53
  fee?: number;
50
54
  discardChange?: boolean;
51
55
  feePaidBy?: FeePaidByEnum;
52
56
  changeAddress?: string;
57
+ walletCache?: WalletCacheI;
53
58
  }) {
54
59
  if (!signingKey) {
55
60
  throw new Error("Missing signing key when building transaction");
@@ -60,8 +65,8 @@ export async function buildP2pkhNonHdTransaction({
60
65
  throw new Error("Transaction template error");
61
66
  }
62
67
 
63
- const compiler = await walletTemplateToCompilerBCH(template);
64
- const inputAmount = await sumUtxoValue(inputs);
68
+ const compiler = walletTemplateToCompilerBch(template);
69
+ const inputAmount = sumUtxoValue(inputs);
65
70
 
66
71
  const sendAmount = await sumSendRequestAmounts(outputs);
67
72
 
@@ -72,7 +77,7 @@ export async function buildP2pkhNonHdTransaction({
72
77
  const lockedOutputs = await prepareOutputs(outputs);
73
78
 
74
79
  if (!changeAddress) {
75
- changeAddress = sourceAddress;
80
+ changeAddress = inputs[0].address;
76
81
  }
77
82
 
78
83
  if (discardChange !== true) {
@@ -92,7 +97,7 @@ export async function buildP2pkhNonHdTransaction({
92
97
  inputs,
93
98
  compiler,
94
99
  signingKey,
95
- sourceAddress,
100
+ walletCache,
96
101
  });
97
102
  const result = generateTransaction({
98
103
  inputs: preparedInputs,
@@ -121,16 +126,16 @@ export function prepareInputs({
121
126
  inputs,
122
127
  compiler,
123
128
  signingKey,
124
- sourceAddress,
129
+ walletCache,
125
130
  }: {
126
- inputs: UtxoI[];
131
+ inputs: Utxo[];
127
132
  compiler: Compiler<
128
- CompilationContextBCH,
129
- AnyCompilerConfiguration<CompilationContextBCH>,
133
+ CompilationContextBch,
134
+ AnyCompilerConfiguration<CompilationContextBch>,
130
135
  AuthenticationProgramStateCommon
131
136
  >;
132
137
  signingKey: Uint8Array;
133
- sourceAddress: string;
138
+ walletCache?: WalletCacheI;
134
139
  }) {
135
140
  const preparedInputs: any[] = [];
136
141
  const sourceOutputs: any[] = [];
@@ -160,7 +165,9 @@ export function prepareInputs({
160
165
  }
161
166
  : undefined,
162
167
  };
163
- const key = signingKey?.length ? signingKey : Uint8Array.from(Array(32));
168
+ const key =
169
+ walletCache?.getByAddress(i.address)?.privateKey ??
170
+ (signingKey?.length ? signingKey : Uint8Array.from(Array(32)));
164
171
  const newInput = {
165
172
  outpointIndex: utxoIndex,
166
173
  outpointTransactionHash: utxoOutpointTransactionHash,
@@ -178,7 +185,7 @@ export function prepareInputs({
178
185
 
179
186
  preparedInputs.push(newInput);
180
187
 
181
- const lockingBytecode = cashAddressToLockingBytecode(sourceAddress);
188
+ const lockingBytecode = cashAddressToLockingBytecode(i.address);
182
189
  if (typeof lockingBytecode === "string") {
183
190
  throw lockingBytecode;
184
191
  }
@@ -292,22 +299,22 @@ export function prepareTokenOutputs(request: TokenSendRequest): Output {
292
299
  * @returns A promise to a list of unspent outputs
293
300
  */
294
301
  export async function getSuitableUtxos(
295
- inputs: UtxoI[],
302
+ inputs: Utxo[],
296
303
  amountRequired: bigint | undefined,
297
304
  bestHeight: number,
298
305
  feePaidBy: FeePaidByEnum,
299
306
  requests: SendRequestType[],
300
- ensureUtxos: UtxoI[] = [],
307
+ ensureUtxos: Utxo[] = [],
301
308
  tokenOperation: "send" | "genesis" | "mint" | "burn" = "send"
302
- ): Promise<UtxoI[]> {
303
- const suitableUtxos: UtxoI[] = [...ensureUtxos];
309
+ ): Promise<Utxo[]> {
310
+ const suitableUtxos: Utxo[] = [...ensureUtxos];
304
311
  let amountAvailable = BigInt(0);
305
312
  const tokenRequests = requests.filter(
306
313
  (val) => val instanceof TokenSendRequest
307
314
  ) as TokenSendRequest[];
308
315
 
309
316
  const availableInputs = inputs.slice();
310
- const selectedInputs: UtxoI[] = [];
317
+ const selectedInputs: Utxo[] = [];
311
318
 
312
319
  // find matching utxos for token transfers
313
320
  if (tokenOperation === "send") {
@@ -438,9 +445,8 @@ export async function getFeeAmountSimple({
438
445
  relayFeePerByteInSatoshi,
439
446
  discardChange,
440
447
  }: {
441
- utxos: UtxoI[];
448
+ utxos: Utxo[];
442
449
  sendRequests: Array<SendRequest | TokenSendRequest | OpReturnData>;
443
- privateKey: Uint8Array;
444
450
  sourceAddress: string;
445
451
  relayFeePerByteInSatoshi: number;
446
452
  feePaidBy: FeePaidByEnum;
@@ -494,19 +500,19 @@ export async function getFeeAmountSimple({
494
500
  export async function getFeeAmount({
495
501
  utxos,
496
502
  sendRequests,
497
- privateKey,
498
503
  sourceAddress,
499
504
  relayFeePerByteInSatoshi,
500
505
  feePaidBy,
501
506
  discardChange,
507
+ walletCache,
502
508
  }: {
503
- utxos: UtxoI[];
509
+ utxos: Utxo[];
504
510
  sendRequests: Array<SendRequest | TokenSendRequest | OpReturnData>;
505
- privateKey: Uint8Array;
506
511
  sourceAddress: string;
507
512
  relayFeePerByteInSatoshi: number;
508
513
  feePaidBy: FeePaidByEnum;
509
514
  discardChange?: boolean;
515
+ walletCache?: WalletCacheI;
510
516
  }) {
511
517
  // build transaction
512
518
  if (utxos) {
@@ -515,12 +521,12 @@ export async function getFeeAmount({
515
521
  await buildEncodedTransaction({
516
522
  inputs: utxos,
517
523
  outputs: sendRequests,
518
- signingKey: privateKey,
519
- sourceAddress,
524
+ signingKey: placeholderPrivateKeyBin,
520
525
  fee: 0, //DUST_UTXO_THRESHOLD
521
526
  discardChange: discardChange ?? false,
522
527
  feePaidBy,
523
528
  changeAddress: "",
529
+ walletCache,
524
530
  });
525
531
 
526
532
  return Math.ceil(draftTransaction.length * relayFeePerByteInSatoshi + 1);
@@ -536,32 +542,32 @@ export async function buildEncodedTransaction({
536
542
  inputs,
537
543
  outputs,
538
544
  signingKey,
539
- sourceAddress,
540
545
  fee = 0,
541
546
  discardChange = false,
542
547
  feePaidBy = FeePaidByEnum.change,
543
548
  changeAddress = "",
544
549
  buildUnsigned = false,
550
+ walletCache,
545
551
  }: {
546
- inputs: UtxoI[];
552
+ inputs: Utxo[];
547
553
  outputs: Array<SendRequest | TokenSendRequest | OpReturnData>;
548
554
  signingKey: Uint8Array;
549
- sourceAddress: string;
550
555
  fee?: number;
551
556
  discardChange?: boolean;
552
557
  feePaidBy?: FeePaidByEnum;
553
558
  changeAddress?: string;
554
559
  buildUnsigned?: boolean;
560
+ walletCache?: WalletCacheI;
555
561
  }) {
556
562
  const { transaction, sourceOutputs } = await buildP2pkhNonHdTransaction({
557
563
  inputs,
558
564
  outputs,
559
565
  signingKey,
560
- sourceAddress,
561
566
  fee,
562
567
  discardChange,
563
568
  feePaidBy,
564
569
  changeAddress,
570
+ walletCache,
565
571
  });
566
572
 
567
573
  if (buildUnsigned === true) {
@@ -592,7 +598,7 @@ export async function signUnsignedTransaction(
592
598
  throw new Error("Transaction template error");
593
599
  }
594
600
 
595
- const compiler = walletTemplateToCompilerBCH(template);
601
+ const compiler = walletTemplateToCompilerBch(template);
596
602
  const transactionTemplate: Readonly<
597
603
  TransactionTemplateFixed<typeof compiler>
598
604
  > = { ...decoded };
@@ -1,31 +1,26 @@
1
- import { UtxoI } from "../interface.js";
1
+ import { Utxo, UtxoId } from "../interface.js";
2
2
 
3
3
  export async function checkUtxos(
4
- utxos: UtxoI[],
5
- wallet: import("../wallet/Wif.js").Wallet
6
- ): Promise<UtxoI[]> {
7
- if (utxos.some((val) => val.satoshis === 0)) {
8
- const addressUtxos = await wallet.getAddressUtxos(wallet.cashaddr);
9
- const absent = utxos.filter(
10
- (val) =>
11
- !addressUtxos.find(
12
- (utxo) => val.txid === utxo.txid && val.vout === utxo.vout
13
- )
14
- );
15
- if (absent.length) {
16
- const absentString = absent
17
- .map((val) => `${val.txid}:${val.vout}`)
18
- .join(", ");
19
- throw Error(`Utxos [${absentString}] not found in wallet`);
20
- }
21
-
22
- utxos = utxos.map(
23
- (val) =>
24
- addressUtxos.find(
25
- (utxo) => val.txid === utxo.txid && val.vout === utxo.vout
26
- )!
27
- );
4
+ utxoIds: UtxoId[],
5
+ walletOrUtxos: Utxo[] | import("../wallet/Wif.js").Wallet
6
+ ): Promise<Utxo[]> {
7
+ const addressUtxos = Array.isArray(walletOrUtxos)
8
+ ? walletOrUtxos
9
+ : await walletOrUtxos.getUtxos();
10
+ const absent = utxoIds.filter(
11
+ (val) =>
12
+ !addressUtxos.find(
13
+ (utxo) => val.txid === utxo.txid && val.vout === utxo.vout
14
+ )
15
+ );
16
+ if (absent.length) {
17
+ const absentString = absent
18
+ .map((val) => `${val.txid}:${val.vout}`)
19
+ .join(", ");
20
+ throw Error(`Utxos [${absentString}] not found in wallet`);
28
21
  }
29
22
 
30
- return utxos;
23
+ return addressUtxos.filter((val) =>
24
+ utxoIds.find((utxo) => val.txid === utxo.txid && val.vout === utxo.vout)
25
+ );
31
26
  }
@@ -80,6 +80,10 @@ function decodeAddress(address: string): DecodedCashAddress {
80
80
  }
81
81
 
82
82
  export function toCashaddr(address: string): string {
83
+ if (address.indexOf(":q") > 0 || address.indexOf(":p") > 0) {
84
+ return address;
85
+ }
86
+
83
87
  const result = decodeAddress(address);
84
88
 
85
89
  return encodeCashAddress({
@@ -90,6 +94,10 @@ export function toCashaddr(address: string): string {
90
94
  }
91
95
 
92
96
  export function toTokenaddr(address: string): string {
97
+ if (address.indexOf(":z") > 0 || address.indexOf(":r") > 0) {
98
+ return address;
99
+ }
100
+
93
101
  const result = decodeAddress(address);
94
102
 
95
103
  return encodeCashAddress({
@@ -10,7 +10,7 @@ export function derivedNetwork(addresses: string[]) {
10
10
  // Get a unique set of networks requested
11
11
  let networkSet = new Set(networks);
12
12
  if (networkSet.size > 1) {
13
- throw Error("Contract addresses are not on the same network");
13
+ throw Error("Addresses are not on the same network");
14
14
  } else if (networkSet.size === 0) {
15
15
  throw Error("No address network was derived");
16
16
  } else {
@@ -53,16 +53,3 @@ test("Should calculate public key hash consistent with hash160", async () => {
53
53
  expect(binToHex(pkh2)).toEqual("d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa");
54
54
  expect(binToHex(pkh3)).toEqual("d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa");
55
55
  });
56
-
57
- test("Should return the a public key hash of manually set wallet", async () => {
58
- let w = new Wallet();
59
- // @ts-ignore
60
- w.privateKey = hexToBin(
61
- "e284129cc0922579a535bbf4d1a3b25773090d28c909bc0fed73b5e0222cc372"
62
- );
63
- // @ts-ignore
64
- await w.deriveInfo();
65
- let pkh = derivePublicKeyHash(w.getDepositAddress());
66
- let expectedPKH = "d986ed01b7a22225a70edbf2ba7cfb63a15cb3aa";
67
- expect(binToHex(pkh)).toBe(expectedPKH);
68
- });
package/src/util/hd.ts ADDED
@@ -0,0 +1,16 @@
1
+ export const arrayRange = (start: number, stop: number) =>
2
+ Array.from({ length: stop - start }, (_, index) => start + index);
3
+
4
+ export const getNextUnusedIndex = (
5
+ index: number,
6
+ statuses: Array<string | null>
7
+ ): number => {
8
+ if (index === -1) {
9
+ index = statuses.findIndex((status) => status === null);
10
+ if (index === -1) {
11
+ index = statuses.length;
12
+ }
13
+ }
14
+
15
+ return index;
16
+ };
package/src/util/index.ts CHANGED
@@ -35,3 +35,4 @@ export {
35
35
  } from "./balanceObjectFromSatoshi.js";
36
36
  export * from "./sumUtxoValue.js";
37
37
  export { decodeHeader } from "./header.js";
38
+ export * from "./checkUtxos.js";
@@ -1,8 +1,8 @@
1
- import { UtxoI } from "../interface.js";
1
+ import { Utxo } from "../interface.js";
2
2
 
3
- export function sumUtxoValue(utxos: UtxoI[]) {
3
+ export function sumUtxoValue(utxos: Utxo[]) {
4
4
  if (utxos.length > 0) {
5
- const balanceArray: number[] = utxos.map((o: UtxoI) => {
5
+ const balanceArray: number[] = utxos.map((o: Utxo) => {
6
6
  return o.satoshis;
7
7
  });
8
8
  const balance = balanceArray.reduce((a: number, b: number) => a + b, 0);
@@ -12,11 +12,11 @@ export function sumUtxoValue(utxos: UtxoI[]) {
12
12
  }
13
13
  }
14
14
 
15
- export function sumTokenAmounts(utxos: UtxoI[], tokenId: string): bigint {
15
+ export function sumTokenAmounts(utxos: Utxo[], tokenId: string): bigint {
16
16
  if (utxos.length > 0) {
17
17
  const tokenArray: bigint[] = utxos
18
18
  .filter((utxo) => utxo.token?.tokenId === tokenId)
19
- .map((o: UtxoI) => {
19
+ .map((o: Utxo) => {
20
20
  return o.token?.amount || 0n;
21
21
  });
22
22
  const balance = tokenArray.reduce((a: bigint, b: bigint) => a + b, 0n);