@bitgo/wasm-utxo 1.4.0 → 1.5.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 (84) hide show
  1. package/dist/{esm → cjs/js}/fixedScriptWallet.d.ts +19 -0
  2. package/dist/cjs/{fixedScriptWallet.js → js/fixedScriptWallet.js} +25 -0
  3. package/dist/{esm → cjs/js}/wasm/wasm_utxo.d.ts +29 -0
  4. package/dist/cjs/{wasm → js/wasm}/wasm_utxo.js +77 -0
  5. package/dist/{esm → cjs/js}/wasm/wasm_utxo_bg.wasm +0 -0
  6. package/dist/cjs/{wasm → js/wasm}/wasm_utxo_bg.wasm.d.ts +19 -16
  7. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -0
  8. package/dist/{cjs → esm/js}/fixedScriptWallet.d.ts +19 -0
  9. package/dist/esm/{fixedScriptWallet.js → js/fixedScriptWallet.js} +25 -0
  10. package/dist/{cjs → esm/js}/wasm/wasm_utxo.d.ts +29 -0
  11. package/dist/esm/{wasm → js/wasm}/wasm_utxo_bg.js +77 -0
  12. package/dist/{cjs → esm/js}/wasm/wasm_utxo_bg.wasm +0 -0
  13. package/dist/esm/{wasm → js/wasm}/wasm_utxo_bg.wasm.d.ts +19 -16
  14. package/dist/esm/test/address/utxolibCompat.d.ts +1 -0
  15. package/dist/esm/test/address/utxolibCompat.js +105 -0
  16. package/dist/esm/test/ast/formatNode.d.ts +1 -0
  17. package/dist/esm/test/ast/formatNode.js +15 -0
  18. package/dist/esm/test/descriptorFixtures.d.ts +25 -0
  19. package/dist/esm/test/descriptorFixtures.js +605 -0
  20. package/dist/esm/test/descriptorUtil.d.ts +13 -0
  21. package/dist/esm/test/descriptorUtil.js +52 -0
  22. package/dist/esm/test/fixedScript/address.d.ts +1 -0
  23. package/dist/esm/test/fixedScript/address.js +64 -0
  24. package/dist/esm/test/fixedScript/finalizeExtract.d.ts +1 -0
  25. package/dist/esm/test/fixedScript/finalizeExtract.js +66 -0
  26. package/dist/esm/test/fixedScript/fixtureUtil.d.ts +93 -0
  27. package/dist/esm/test/fixedScript/fixtureUtil.js +44 -0
  28. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.d.ts +1 -0
  29. package/dist/esm/test/fixedScript/parseTransactionWithWalletKeys.js +140 -0
  30. package/dist/esm/test/fixedScript/verifySignature.d.ts +1 -0
  31. package/dist/esm/test/fixedScript/verifySignature.js +141 -0
  32. package/dist/esm/test/fixedScriptToDescriptor.d.ts +1 -0
  33. package/dist/esm/test/fixedScriptToDescriptor.js +91 -0
  34. package/dist/esm/test/fixtures.d.ts +1 -0
  35. package/dist/esm/test/fixtures.js +12 -0
  36. package/dist/esm/test/opdrop.d.ts +1 -0
  37. package/dist/esm/test/opdrop.js +85 -0
  38. package/dist/esm/test/psbt.util.d.ts +8 -0
  39. package/dist/esm/test/psbt.util.js +116 -0
  40. package/dist/esm/test/psbtFixedScriptCompat.d.ts +1 -0
  41. package/dist/esm/test/psbtFixedScriptCompat.js +114 -0
  42. package/dist/esm/test/psbtFixedScriptCompatFixtures.d.ts +10 -0
  43. package/dist/esm/test/psbtFixedScriptCompatFixtures.js +53 -0
  44. package/dist/esm/test/psbtFromDescriptor.d.ts +1 -0
  45. package/dist/esm/test/psbtFromDescriptor.js +107 -0
  46. package/dist/esm/test/psbtFromDescriptor.util.d.ts +63 -0
  47. package/dist/esm/test/psbtFromDescriptor.util.js +101 -0
  48. package/dist/esm/test/test.d.ts +1 -0
  49. package/dist/esm/test/test.js +122 -0
  50. package/dist/esm/tsconfig.tsbuildinfo +1 -0
  51. package/package.json +12 -12
  52. /package/dist/cjs/{address.d.ts → js/address.d.ts} +0 -0
  53. /package/dist/cjs/{address.js → js/address.js} +0 -0
  54. /package/dist/cjs/{ast → js/ast}/formatNode.d.ts +0 -0
  55. /package/dist/cjs/{ast → js/ast}/formatNode.js +0 -0
  56. /package/dist/cjs/{ast → js/ast}/fromWasmNode.d.ts +0 -0
  57. /package/dist/cjs/{ast → js/ast}/fromWasmNode.js +0 -0
  58. /package/dist/cjs/{ast → js/ast}/index.d.ts +0 -0
  59. /package/dist/cjs/{ast → js/ast}/index.js +0 -0
  60. /package/dist/cjs/{coinName.d.ts → js/coinName.d.ts} +0 -0
  61. /package/dist/cjs/{coinName.js → js/coinName.js} +0 -0
  62. /package/dist/cjs/{index.d.ts → js/index.d.ts} +0 -0
  63. /package/dist/cjs/{index.js → js/index.js} +0 -0
  64. /package/dist/cjs/{triple.d.ts → js/triple.d.ts} +0 -0
  65. /package/dist/cjs/{triple.js → js/triple.js} +0 -0
  66. /package/dist/cjs/{utxolibCompat.d.ts → js/utxolibCompat.d.ts} +0 -0
  67. /package/dist/cjs/{utxolibCompat.js → js/utxolibCompat.js} +0 -0
  68. /package/dist/esm/{address.d.ts → js/address.d.ts} +0 -0
  69. /package/dist/esm/{address.js → js/address.js} +0 -0
  70. /package/dist/esm/{ast → js/ast}/formatNode.d.ts +0 -0
  71. /package/dist/esm/{ast → js/ast}/formatNode.js +0 -0
  72. /package/dist/esm/{ast → js/ast}/fromWasmNode.d.ts +0 -0
  73. /package/dist/esm/{ast → js/ast}/fromWasmNode.js +0 -0
  74. /package/dist/esm/{ast → js/ast}/index.d.ts +0 -0
  75. /package/dist/esm/{ast → js/ast}/index.js +0 -0
  76. /package/dist/esm/{coinName.d.ts → js/coinName.d.ts} +0 -0
  77. /package/dist/esm/{coinName.js → js/coinName.js} +0 -0
  78. /package/dist/esm/{index.d.ts → js/index.d.ts} +0 -0
  79. /package/dist/esm/{index.js → js/index.js} +0 -0
  80. /package/dist/esm/{triple.d.ts → js/triple.d.ts} +0 -0
  81. /package/dist/esm/{triple.js → js/triple.js} +0 -0
  82. /package/dist/esm/{utxolibCompat.d.ts → js/utxolibCompat.d.ts} +0 -0
  83. /package/dist/esm/{utxolibCompat.js → js/utxolibCompat.js} +0 -0
  84. /package/dist/esm/{wasm → js/wasm}/wasm_utxo.js +0 -0
@@ -0,0 +1,105 @@
1
+ import * as path from "node:path";
2
+ import * as fs from "node:fs/promises";
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname } from "node:path";
5
+ import * as utxolib from "@bitgo/utxo-lib";
6
+ import assert from "node:assert";
7
+ import { utxolibCompat, address as addressNs, } from "../../js/index.js";
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+ function getCoinNameForNetwork(name) {
11
+ switch (name) {
12
+ case "bitcoin":
13
+ return "btc";
14
+ case "testnet":
15
+ return "tbtc";
16
+ case "bitcoinTestnet4":
17
+ return "tbtc4";
18
+ case "bitcoinPublicSignet":
19
+ return "tbtcsig";
20
+ case "bitcoinBitGoSignet":
21
+ return "tbtcbgsig";
22
+ case "bitcoincash":
23
+ return "bch";
24
+ case "bitcoincashTestnet":
25
+ return "tbch";
26
+ case "ecash":
27
+ return "bcha";
28
+ case "ecashTest":
29
+ return "tbcha";
30
+ case "bitcoingold":
31
+ return "btg";
32
+ case "bitcoingoldTestnet":
33
+ return "tbtg";
34
+ case "bitcoinsv":
35
+ return "bsv";
36
+ case "bitcoinsvTestnet":
37
+ return "tbsv";
38
+ case "dash":
39
+ return "dash";
40
+ case "dashTest":
41
+ return "tdash";
42
+ case "dogecoin":
43
+ return "doge";
44
+ case "dogecoinTest":
45
+ return "tdoge";
46
+ case "litecoin":
47
+ return "ltc";
48
+ case "litecoinTest":
49
+ return "tltc";
50
+ case "zcash":
51
+ return "zec";
52
+ case "zcashTest":
53
+ return "tzec";
54
+ default:
55
+ throw new Error(`Unknown network: ${name}`);
56
+ }
57
+ }
58
+ async function getFixtures(name, addressFormat) {
59
+ if (name === "bitcoinBitGoSignet") {
60
+ name = "bitcoinPublicSignet";
61
+ }
62
+ const filename = addressFormat ? `${name}-${addressFormat}` : name;
63
+ const fixturePath = path.join(__dirname, "..", "fixtures", "address", `${filename}.json`);
64
+ const fixtures = await fs.readFile(fixturePath, "utf8");
65
+ return JSON.parse(fixtures);
66
+ }
67
+ function runTest(network, addressFormat) {
68
+ const name = utxolib.getNetworkName(network);
69
+ describe(`utxolibCompat ${name} ${addressFormat ?? "default"}`, function () {
70
+ let fixtures;
71
+ before(async function () {
72
+ fixtures = await getFixtures(name, addressFormat);
73
+ });
74
+ it("should convert to utxolib compatible network", async function () {
75
+ for (const fixture of fixtures) {
76
+ const [_type, script, addressRef] = fixture;
77
+ const scriptBuf = Buffer.from(script, "hex");
78
+ const address = utxolibCompat.fromOutputScript(scriptBuf, network, addressFormat);
79
+ assert.strictEqual(address, addressRef);
80
+ const scriptFromAddress = utxolibCompat.toOutputScript(address, network, addressFormat);
81
+ assert.deepStrictEqual(Buffer.from(scriptFromAddress), scriptBuf);
82
+ }
83
+ });
84
+ it("should convert using coin name", async function () {
85
+ const coinName = getCoinNameForNetwork(name);
86
+ for (const fixture of fixtures) {
87
+ const [_type, script, addressRef] = fixture;
88
+ const scriptBuf = Buffer.from(script, "hex");
89
+ // Test encoding (script -> address)
90
+ const address = addressNs.fromOutputScriptWithCoin(scriptBuf, coinName, addressFormat);
91
+ assert.strictEqual(address, addressRef);
92
+ // Test decoding (address -> script)
93
+ const scriptFromAddress = addressNs.toOutputScriptWithCoin(addressRef, coinName);
94
+ assert.deepStrictEqual(Buffer.from(scriptFromAddress), scriptBuf);
95
+ }
96
+ });
97
+ });
98
+ }
99
+ utxolib.getNetworkList().forEach((network) => {
100
+ runTest(network);
101
+ const mainnet = utxolib.getMainnet(network);
102
+ if (mainnet === utxolib.networks.bitcoincash || mainnet === utxolib.networks.ecash) {
103
+ runTest(network, "cashaddr");
104
+ }
105
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import * as assert from "assert";
2
+ import { formatNode } from "../../js/ast/index.js";
3
+ describe("formatNode", function () {
4
+ it("formats simple nodes", function () {
5
+ assert.strictEqual(formatNode({ pk: "lol" }), "pk(lol)");
6
+ assert.strictEqual(formatNode({ after: 1 }), "after(1)");
7
+ assert.strictEqual(formatNode({ and_v: [{ after: 1 }, { after: 1 }] }), "and_v(after(1),after(1))");
8
+ // taproot single key
9
+ assert.strictEqual(formatNode({ tr: "k" }), "tr(k)");
10
+ // key with single-node taproot tree
11
+ assert.strictEqual(formatNode({ tr: ["k", { pk: "k1" }] }), "tr(k,pk(k1))");
12
+ // key with multi-node taproot tree
13
+ assert.strictEqual(formatNode({ tr: ["k", [{ pk: "k1" }, { pk: "k2" }]] }), "tr(k,{pk(k1),pk(k2)})");
14
+ });
15
+ });
@@ -0,0 +1,25 @@
1
+ export declare const fixtures: {
2
+ valid: ({
3
+ descriptor: string;
4
+ script: string;
5
+ checksumRequired: boolean;
6
+ index?: undefined;
7
+ } | {
8
+ descriptor: string;
9
+ script: string;
10
+ index: number;
11
+ checksumRequired: boolean;
12
+ } | {
13
+ descriptor: string;
14
+ script: string;
15
+ checksumRequired?: undefined;
16
+ index?: undefined;
17
+ })[];
18
+ invalid: ({
19
+ descriptor: string;
20
+ checksumRequired: boolean;
21
+ } | {
22
+ descriptor: string;
23
+ checksumRequired?: undefined;
24
+ })[];
25
+ };