mainnet-js 2.3.0 → 2.3.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.
Files changed (34) hide show
  1. package/dist/index.html +1 -1
  2. package/dist/{mainnet-2.3.0.js → mainnet-2.3.2.js} +422 -432
  3. package/dist/module/libauth.d.ts +1 -1
  4. package/dist/module/libauth.d.ts.map +1 -1
  5. package/dist/module/libauth.js +1 -1
  6. package/dist/module/libauth.js.map +1 -1
  7. package/dist/module/network/interface.d.ts +1 -1
  8. package/dist/module/network/interface.d.ts.map +1 -1
  9. package/dist/module/transaction/Wif.d.ts +2 -2
  10. package/dist/module/transaction/Wif.d.ts.map +1 -1
  11. package/dist/module/transaction/Wif.js +5 -5
  12. package/dist/module/transaction/Wif.js.map +1 -1
  13. package/dist/module/util/index.d.ts +1 -3
  14. package/dist/module/util/index.d.ts.map +1 -1
  15. package/dist/module/util/index.js +1 -3
  16. package/dist/module/util/index.js.map +1 -1
  17. package/dist/module/util/randomInt.d.ts +1 -1
  18. package/dist/module/util/randomInt.d.ts.map +1 -1
  19. package/dist/module/util/randomInt.js +1 -1
  20. package/dist/module/util/randomInt.js.map +1 -1
  21. package/dist/tsconfig.tsbuildinfo +1 -1
  22. package/package.json +2 -2
  23. package/src/libauth.ts +4 -4
  24. package/src/network/interface.ts +1 -1
  25. package/src/transaction/Wif.ts +7 -11
  26. package/src/util/index.ts +1 -3
  27. package/src/util/randomInt.test.ts +3 -3
  28. package/src/util/randomInt.ts +1 -1
  29. package/src/util/satoshiToAmount.test.ts +1 -1
  30. package/dist/module/util/randomValues.d.ts +0 -2
  31. package/dist/module/util/randomValues.d.ts.map +0 -1
  32. package/dist/module/util/randomValues.js +0 -13
  33. package/dist/module/util/randomValues.js.map +0 -1
  34. package/src/util/randomValues.ts +0 -13
package/package.json CHANGED
@@ -9,7 +9,7 @@
9
9
  "url": "https://github.com/mainnet-cash/mainnet-js/issues"
10
10
  },
11
11
  "name": "mainnet-js",
12
- "version": "2.3.0",
12
+ "version": "2.3.2",
13
13
  "homepage": "https://mainnet.cash",
14
14
  "module": "dist/module/index.js",
15
15
  "browser": {
@@ -38,7 +38,7 @@
38
38
  "reload": "npx reload --dir=../../jest/playwright "
39
39
  },
40
40
  "dependencies": {
41
- "@bitauth/libauth": "^2.0.0-alpha.8",
41
+ "@bitauth/libauth": "^2.0.0",
42
42
  "bip39": "^3.0.3",
43
43
  "buffer": "^6.0.3",
44
44
  "electrum-cash": "^2.0.10",
package/src/libauth.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  export {
2
- importAuthenticationTemplate,
3
- authenticationTemplateP2pkhNonHd,
4
- authenticationTemplateP2pkh,
5
- authenticationTemplateToCompilerBCH,
2
+ importWalletTemplate,
3
+ walletTemplateP2pkhNonHd,
4
+ walletTemplateP2pkh,
5
+ walletTemplateToCompilerBCH,
6
6
  cashAddressToLockingBytecode,
7
7
  hexToBin,
8
8
  generateTransaction,
@@ -1,5 +1,5 @@
1
1
  import { ClusterOrder } from "electrum-cash";
2
- import { NFTCapability } from "../interface";
2
+ import { NFTCapability } from "../interface.js";
3
3
 
4
4
  export interface BlockHeader {
5
5
  height: number;
@@ -1,11 +1,11 @@
1
1
  import {
2
- authenticationTemplateP2pkhNonHd,
3
- authenticationTemplateToCompilerBCH,
2
+ walletTemplateP2pkhNonHd,
3
+ walletTemplateToCompilerBCH,
4
4
  cashAddressToLockingBytecode,
5
5
  Compiler,
6
6
  encodeTransaction,
7
7
  generateTransaction,
8
- importAuthenticationTemplate,
8
+ importWalletTemplate,
9
9
  AnyCompilerConfiguration,
10
10
  AuthenticationProgramStateCommon,
11
11
  CompilationContextBCH,
@@ -55,14 +55,12 @@ export async function buildP2pkhNonHdTransaction({
55
55
  throw new Error("Missing signing key when building transaction");
56
56
  }
57
57
 
58
- const template = importAuthenticationTemplate(
59
- authenticationTemplateP2pkhNonHd
60
- );
58
+ const template = importWalletTemplate(walletTemplateP2pkhNonHd);
61
59
  if (typeof template === "string") {
62
60
  throw new Error("Transaction template error");
63
61
  }
64
62
 
65
- const compiler = await authenticationTemplateToCompilerBCH(template);
63
+ const compiler = await walletTemplateToCompilerBCH(template);
66
64
  const inputAmount = await sumUtxoValue(inputs);
67
65
 
68
66
  const sendAmount = await sumSendRequestAmounts(outputs);
@@ -586,14 +584,12 @@ export async function signUnsignedTransaction(
586
584
  throw decoded;
587
585
  }
588
586
 
589
- const template = importAuthenticationTemplate(
590
- authenticationTemplateP2pkhNonHd
591
- );
587
+ const template = importWalletTemplate(walletTemplateP2pkhNonHd);
592
588
  if (typeof template === "string") {
593
589
  throw new Error("Transaction template error");
594
590
  }
595
591
 
596
- const compiler = authenticationTemplateToCompilerBCH(template);
592
+ const compiler = walletTemplateToCompilerBCH(template);
597
593
  const transactionTemplate: Readonly<
598
594
  TransactionTemplateFixed<typeof compiler>
599
595
  > = { ...decoded };
package/src/util/index.ts CHANGED
@@ -25,10 +25,8 @@ export { hash160 } from "./hash160.js";
25
25
  export { ExchangeRate } from "../rate/ExchangeRate.js";
26
26
  export { sanitizeAddress } from "./sanitizeAddress.js";
27
27
  export { sanitizeUnit } from "./sanitizeUnit.js";
28
- export { getRandomInt } from "./randomInt.js";
28
+ export { getWeakRandomInt } from "./randomInt.js";
29
29
  export { getXPubKey } from "../util/getXPubKey.js";
30
- import * as randomValues from "./randomValues.js";
31
- export { randomValues };
32
30
  export { sumUtxoValue } from "./sumUtxoValue.js";
33
31
  export {
34
32
  BalanceResponse,
@@ -1,14 +1,14 @@
1
- import { getRandomInt } from "./randomInt";
1
+ import { getWeakRandomInt } from "./randomInt";
2
2
 
3
3
  test("get a random int", async () => {
4
- let zero = await getRandomInt(0);
4
+ let zero = await getWeakRandomInt(0);
5
5
  expect(zero).toBe(0);
6
6
  });
7
7
 
8
8
  test("average some random ints", async () => {
9
9
  let average = 0;
10
10
  for (let i = 0; i < 100; i++) {
11
- average += getRandomInt(1000) / 100;
11
+ average += getWeakRandomInt(1000) / 100;
12
12
  }
13
13
  expect(average).toBeGreaterThan(400);
14
14
  expect(average).toBeLessThan(600);
@@ -1,4 +1,4 @@
1
1
  // Simple function to get a random integer
2
- export function getRandomInt(max: number) {
2
+ export function getWeakRandomInt(max: number) {
3
3
  return Math.floor(Math.random() * Math.floor(max));
4
4
  }
@@ -1,6 +1,6 @@
1
1
  import { satoshiToAmount } from "./satoshiToAmount";
2
2
 
3
- test("get a random int", async () => {
3
+ test("get a zero satoshis", async () => {
4
4
  let zero = await satoshiToAmount(0, "sat");
5
5
  expect(zero).toBe(0);
6
6
  });
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=randomValues.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"randomValues.d.ts","sourceRoot":"","sources":["../../../src/util/randomValues.ts"],"names":[],"mappings":""}
@@ -1,13 +0,0 @@
1
- import { getRuntimePlatform } from "./getRuntimePlatform.js";
2
- import crypto from "crypto";
3
- if (getRuntimePlatform() === "node") {
4
- if (!globalThis.crypto || !globalThis.crypto.getRandomValues) {
5
- globalThis.crypto = crypto;
6
- // (globalThis.crypto as any).getRandomValues = (buf: Uint8Array) => {
7
- // const bytes = crypto.randomBytes(buf.length);
8
- // buf.set(bytes);
9
- // return buf;
10
- // };
11
- }
12
- }
13
- //# sourceMappingURL=randomValues.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"randomValues.js","sourceRoot":"","sources":["../../../src/util/randomValues.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,IAAI,kBAAkB,EAAE,KAAK,MAAM,EAAE;IACnC,IAAI,CAAC,UAAU,CAAC,MAAM,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,eAAe,EAAE;QAC3D,UAAkB,CAAC,MAAM,GAAG,MAAM,CAAC;QACpC,sEAAsE;QACtE,kDAAkD;QAClD,oBAAoB;QACpB,gBAAgB;QAChB,KAAK;KACN;CACF"}
@@ -1,13 +0,0 @@
1
- import { getRuntimePlatform } from "./getRuntimePlatform.js";
2
- import crypto from "crypto";
3
-
4
- if (getRuntimePlatform() === "node") {
5
- if (!globalThis.crypto || !globalThis.crypto.getRandomValues) {
6
- (globalThis as any).crypto = crypto;
7
- // (globalThis.crypto as any).getRandomValues = (buf: Uint8Array) => {
8
- // const bytes = crypto.randomBytes(buf.length);
9
- // buf.set(bytes);
10
- // return buf;
11
- // };
12
- }
13
- }