@bitgo/wasm-utxo 4.41.0 → 5.0.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 (34) hide show
  1. package/dist/cjs/js/address.d.ts +3 -7
  2. package/dist/cjs/js/address.js +4 -8
  3. package/dist/cjs/js/fixedScriptWallet/Dimensions.d.ts +5 -16
  4. package/dist/cjs/js/fixedScriptWallet/Dimensions.js +2 -2
  5. package/dist/cjs/js/fixedScriptWallet/ZcashDimensions.d.ts +45 -0
  6. package/dist/cjs/js/fixedScriptWallet/ZcashDimensions.js +30 -0
  7. package/dist/cjs/js/fixedScriptWallet/ZcashUnifiedAddress.d.ts +16 -0
  8. package/dist/cjs/js/fixedScriptWallet/ZcashUnifiedAddress.js +20 -0
  9. package/dist/cjs/js/index.d.ts +2 -0
  10. package/dist/cjs/js/index.js +4 -1
  11. package/dist/cjs/js/wasm/wasm_utxo.d.ts +53 -5
  12. package/dist/cjs/js/wasm/wasm_utxo.js +136 -7
  13. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm +0 -0
  14. package/dist/cjs/js/wasm/wasm_utxo_bg.wasm.d.ts +80 -74
  15. package/dist/cjs/js/zcashAddress.d.ts +44 -0
  16. package/dist/cjs/js/zcashAddress.js +58 -0
  17. package/dist/esm/js/address.d.ts +3 -7
  18. package/dist/esm/js/address.js +4 -8
  19. package/dist/esm/js/fixedScriptWallet/Dimensions.d.ts +5 -16
  20. package/dist/esm/js/fixedScriptWallet/Dimensions.js +2 -2
  21. package/dist/esm/js/fixedScriptWallet/ZcashDimensions.d.ts +45 -0
  22. package/dist/esm/js/fixedScriptWallet/ZcashDimensions.js +26 -0
  23. package/dist/esm/js/fixedScriptWallet/ZcashUnifiedAddress.d.ts +16 -0
  24. package/dist/esm/js/fixedScriptWallet/ZcashUnifiedAddress.js +20 -0
  25. package/dist/esm/js/index.d.ts +2 -0
  26. package/dist/esm/js/index.js +2 -0
  27. package/dist/esm/js/wasm/wasm_utxo.d.ts +53 -5
  28. package/dist/esm/js/wasm/wasm_utxo.js +1 -1
  29. package/dist/esm/js/wasm/wasm_utxo_bg.js +132 -7
  30. package/dist/esm/js/wasm/wasm_utxo_bg.wasm +0 -0
  31. package/dist/esm/js/wasm/wasm_utxo_bg.wasm.d.ts +80 -74
  32. package/dist/esm/js/zcashAddress.d.ts +44 -0
  33. package/dist/esm/js/zcashAddress.js +52 -0
  34. package/package.json +1 -1
@@ -5,12 +5,8 @@ import type { CoinName } from "./coinName.js";
5
5
  */
6
6
  export type AddressFormat = "default" | "cashaddr";
7
7
  /**
8
- * @param canBeShieldedOutput - When set and `address` is a ZIP-316 unified address carrying an
9
- * Orchard/Ironwood receiver, returns that raw 43-byte receiver instead of a transparent
10
- * scriptPubKey (there is no scriptPubKey for a shielded output). `address` is only even
11
- * attempted as a unified address when this is set. If `address` looks like a unified address for
12
- * this coin's network but is malformed, or has no Orchard/Ironwood receiver (e.g. Sapling-only),
13
- * this throws rather than falling back to the transparent path.
8
+ * Convert `address` to its scriptPubKey bytes for `coin`, decoding it as an ordinary transparent
9
+ * address.
14
10
  */
15
- export declare function toOutputScriptWithCoin(address: string, coin: CoinName, canBeShieldedOutput?: boolean): Uint8Array;
11
+ export declare function toOutputScriptWithCoin(address: string, coin: CoinName): Uint8Array;
16
12
  export declare function fromOutputScriptWithCoin(script: Uint8Array, coin: CoinName, format?: AddressFormat): string;
@@ -4,15 +4,11 @@ exports.toOutputScriptWithCoin = toOutputScriptWithCoin;
4
4
  exports.fromOutputScriptWithCoin = fromOutputScriptWithCoin;
5
5
  const wasm_utxo_js_1 = require("./wasm/wasm_utxo.js");
6
6
  /**
7
- * @param canBeShieldedOutput - When set and `address` is a ZIP-316 unified address carrying an
8
- * Orchard/Ironwood receiver, returns that raw 43-byte receiver instead of a transparent
9
- * scriptPubKey (there is no scriptPubKey for a shielded output). `address` is only even
10
- * attempted as a unified address when this is set. If `address` looks like a unified address for
11
- * this coin's network but is malformed, or has no Orchard/Ironwood receiver (e.g. Sapling-only),
12
- * this throws rather than falling back to the transparent path.
7
+ * Convert `address` to its scriptPubKey bytes for `coin`, decoding it as an ordinary transparent
8
+ * address.
13
9
  */
14
- function toOutputScriptWithCoin(address, coin, canBeShieldedOutput) {
15
- return wasm_utxo_js_1.AddressNamespace.to_output_script_with_coin(address, coin, canBeShieldedOutput);
10
+ function toOutputScriptWithCoin(address, coin) {
11
+ return wasm_utxo_js_1.AddressNamespace.to_output_script_with_coin(address, coin);
16
12
  }
17
13
  function fromOutputScriptWithCoin(script, coin, format) {
18
14
  return wasm_utxo_js_1.AddressNamespace.from_output_script_with_coin(script, coin, format);
@@ -1,3 +1,4 @@
1
+ import { WasmDimensions } from "../wasm/wasm_utxo.js";
1
2
  import type { BitGoPsbt, InputScriptType, SignPath } from "./BitGoPsbt.js";
2
3
  import type { CoinName } from "../coinName.js";
3
4
  import type { OutputScriptType } from "./scriptType.js";
@@ -17,16 +18,6 @@ export type FromInputOptions = {
17
18
  */
18
19
  utxolibCompat?: boolean;
19
20
  };
20
- /**
21
- * Options for output dimension calculation
22
- */
23
- export type FromOutputOptions = {
24
- /**
25
- * Set when `address` may be a ZIP-316 Unified Address whose Orchard receiver should be sized
26
- * as a shielded output. Forwarded to `toOutputScriptWithCoin`'s `canBeShieldedOutput`.
27
- */
28
- isShielded?: boolean;
29
- };
30
21
  /**
31
22
  * Dimensions class for estimating transaction virtual size.
32
23
  *
@@ -37,7 +28,7 @@ export type FromOutputOptions = {
37
28
  */
38
29
  export declare class Dimensions {
39
30
  private _wasm;
40
- private constructor();
31
+ protected constructor(_wasm: WasmDimensions);
41
32
  /**
42
33
  * Create empty dimensions (zero weight)
43
34
  */
@@ -62,12 +53,10 @@ export declare class Dimensions {
62
53
  */
63
54
  static fromOutput(script: Uint8Array): Dimensions;
64
55
  /**
65
- * Create dimensions for a single output from an address.
66
- *
67
- * Pass `{ isShielded: true }` when `address` may be a ZIP-316 Unified Address whose Orchard
68
- * receiver should be sized as a shielded output
56
+ * Create dimensions for a single output from an address, decoded as an ordinary transparent
57
+ * address for `network`.
69
58
  */
70
- static fromOutput(address: string, network: CoinName, options?: FromOutputOptions): Dimensions;
59
+ static fromOutput(address: string, network: CoinName): Dimensions;
71
60
  /**
72
61
  * Create dimensions for a single output from script length only
73
62
  */
@@ -45,12 +45,12 @@ class Dimensions {
45
45
  }
46
46
  return new Dimensions(wasm_utxo_js_1.WasmDimensions.from_input(params.chain, params.signPath?.signer, params.signPath?.cosigner, compat));
47
47
  }
48
- static fromOutput(params, network, options) {
48
+ static fromOutput(params, network) {
49
49
  if (typeof params === "string") {
50
50
  if (network === undefined) {
51
51
  throw new Error("network is required when passing an address string");
52
52
  }
53
- const script = (0, address_js_1.toOutputScriptWithCoin)(params, network, options?.isShielded);
53
+ const script = (0, address_js_1.toOutputScriptWithCoin)(params, network);
54
54
  return new Dimensions(wasm_utxo_js_1.WasmDimensions.from_output_script_length(script.length));
55
55
  }
56
56
  if (typeof params === "object" && "scriptType" in params) {
@@ -0,0 +1,45 @@
1
+ import type { CoinName } from "../coinName.js";
2
+ import type { OutputScriptType } from "./scriptType.js";
3
+ import { Dimensions } from "./Dimensions.js";
4
+ /**
5
+ * Options for {@link ZcashDimensions.fromOutput}.
6
+ */
7
+ export type ZcashFromOutputOptions = {
8
+ /**
9
+ * Set when `address` may be a ZIP-316 Unified Address whose Orchard receiver should be sized
10
+ * as a shielded output. Forwarded to `zcashAddress.toShieldedReceiverWithCoin`; when unset,
11
+ * `zcashAddress.toTransparentReceiverWithCoin` is used instead.
12
+ */
13
+ isShielded?: boolean;
14
+ };
15
+ /**
16
+ * Zcash-specific dimensions: resolves ZIP-316 Unified Addresses (transparent or Orchard/Ironwood
17
+ * shielded receiver) instead of the plain transparent-only decoding {@link Dimensions.fromOutput}
18
+ * does for every other coin.
19
+ */
20
+ export declare class ZcashDimensions extends Dimensions {
21
+ /**
22
+ * Create dimensions for a single output from script bytes
23
+ */
24
+ static fromOutput(script: Uint8Array): Dimensions;
25
+ /**
26
+ * Create dimensions for a single output from a Zcash address for `network`.
27
+ *
28
+ * Pass `{ isShielded: true }` when `address` may be a ZIP-316 Unified Address whose Orchard
29
+ * receiver should be sized as a shielded output; otherwise its transparent receiver is
30
+ * resolved (a UA with no transparent receiver throws rather than falling back to Orchard).
31
+ */
32
+ static fromOutput(address: string, network: CoinName, options?: ZcashFromOutputOptions): Dimensions;
33
+ /**
34
+ * Create dimensions for a single output from script length only
35
+ */
36
+ static fromOutput(params: {
37
+ length: number;
38
+ }): Dimensions;
39
+ /**
40
+ * Create dimensions for a single output from script type
41
+ */
42
+ static fromOutput(params: {
43
+ scriptType: OutputScriptType;
44
+ }): Dimensions;
45
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZcashDimensions = void 0;
4
+ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
5
+ const zcashAddress_js_1 = require("../zcashAddress.js");
6
+ const Dimensions_js_1 = require("./Dimensions.js");
7
+ /**
8
+ * Zcash-specific dimensions: resolves ZIP-316 Unified Addresses (transparent or Orchard/Ironwood
9
+ * shielded receiver) instead of the plain transparent-only decoding {@link Dimensions.fromOutput}
10
+ * does for every other coin.
11
+ */
12
+ class ZcashDimensions extends Dimensions_js_1.Dimensions {
13
+ static fromOutput(params, network, options) {
14
+ if (typeof params === "string") {
15
+ if (network === undefined) {
16
+ throw new Error("network is required when passing an address string");
17
+ }
18
+ const receiver = options?.isShielded
19
+ ? (0, zcashAddress_js_1.toShieldedReceiverWithCoin)(params, network)
20
+ : (0, zcashAddress_js_1.toTransparentReceiverWithCoin)(params, network);
21
+ return new ZcashDimensions(wasm_utxo_js_1.WasmDimensions.from_output_script_length(receiver.length));
22
+ }
23
+ if (typeof params === "object" && "scriptType" in params) {
24
+ return Dimensions_js_1.Dimensions.fromOutput(params);
25
+ }
26
+ // Both Uint8Array and { length: number } have .length
27
+ return Dimensions_js_1.Dimensions.fromOutput(params);
28
+ }
29
+ }
30
+ exports.ZcashDimensions = ZcashDimensions;
@@ -15,6 +15,8 @@ import type { ZcashNetworkName } from "./ZcashBitGoPsbt.js";
15
15
  * const ua = ZcashUnifiedAddress.parse(uaString, "zec");
16
16
  * const ironwood = ua.orchardReceiver; // 43 bytes, or undefined
17
17
  * const script = ua.transparentScript; // scriptPubKey bytes, or undefined
18
+ * ua.hasOrchardReceiver; // true iff orchardReceiver is present
19
+ * ua.hasTransparentReceiver; // true iff transparentScript is present
18
20
  * ua.contains(transparentAddress); // is it one of this UA's receivers?
19
21
  * ```
20
22
  */
@@ -43,6 +45,20 @@ export declare class ZcashUnifiedAddress {
43
45
  * a `TxOut.scriptPubKey`, or `undefined` if the UA has no transparent receiver.
44
46
  */
45
47
  get transparentScript(): Uint8Array | undefined;
48
+ /**
49
+ * Whether this Unified Address carries an Orchard/Ironwood receiver.
50
+ *
51
+ * Equivalent to `orchardReceiver !== undefined`; prefer this when only presence
52
+ * matters, since it avoids copying the receiver bytes.
53
+ */
54
+ get hasOrchardReceiver(): boolean;
55
+ /**
56
+ * Whether this Unified Address carries a transparent (P2PKH/P2SH) receiver.
57
+ *
58
+ * Equivalent to `transparentScript !== undefined`; prefer this when only presence
59
+ * matters, since it avoids copying the script bytes.
60
+ */
61
+ get hasTransparentReceiver(): boolean;
46
62
  /**
47
63
  * Whether `candidate` is a receiver of this unified address.
48
64
  *
@@ -17,6 +17,8 @@ const wasm_utxo_js_1 = require("../wasm/wasm_utxo.js");
17
17
  * const ua = ZcashUnifiedAddress.parse(uaString, "zec");
18
18
  * const ironwood = ua.orchardReceiver; // 43 bytes, or undefined
19
19
  * const script = ua.transparentScript; // scriptPubKey bytes, or undefined
20
+ * ua.hasOrchardReceiver; // true iff orchardReceiver is present
21
+ * ua.hasTransparentReceiver; // true iff transparentScript is present
20
22
  * ua.contains(transparentAddress); // is it one of this UA's receivers?
21
23
  * ```
22
24
  */
@@ -55,6 +57,24 @@ class ZcashUnifiedAddress {
55
57
  get transparentScript() {
56
58
  return this._wasm.transparentScript;
57
59
  }
60
+ /**
61
+ * Whether this Unified Address carries an Orchard/Ironwood receiver.
62
+ *
63
+ * Equivalent to `orchardReceiver !== undefined`; prefer this when only presence
64
+ * matters, since it avoids copying the receiver bytes.
65
+ */
66
+ get hasOrchardReceiver() {
67
+ return this._wasm.hasOrchardReceiver;
68
+ }
69
+ /**
70
+ * Whether this Unified Address carries a transparent (P2PKH/P2SH) receiver.
71
+ *
72
+ * Equivalent to `transparentScript !== undefined`; prefer this when only presence
73
+ * matters, since it avoids copying the script bytes.
74
+ */
75
+ get hasTransparentReceiver() {
76
+ return this._wasm.hasTransparentReceiver;
77
+ }
58
78
  /**
59
79
  * Whether `candidate` is a receiver of this unified address.
60
80
  *
@@ -1,4 +1,5 @@
1
1
  export * as address from "./address.js";
2
+ export * as zcashAddress from "./zcashAddress.js";
2
3
  export * as ast from "./ast/index.js";
3
4
  export * as bip322 from "./bip322/index.js";
4
5
  export * as inscriptions from "./inscriptions.js";
@@ -11,6 +12,7 @@ export * as ecpair from "./ecpair.js";
11
12
  export { ECPair } from "./ecpair.js";
12
13
  export { BIP32 } from "./bip32.js";
13
14
  export { Dimensions } from "./fixedScriptWallet/Dimensions.js";
15
+ export { ZcashDimensions } from "./fixedScriptWallet/ZcashDimensions.js";
14
16
  export type WasmUtxoVersionInfo = {
15
17
  version: string;
16
18
  gitHash: string;
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.hasPsbtMagic = exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.requiresPrevTxForP2sh = exports.isCoinName = exports.isTestnet = exports.isMainnet = exports.getMainnet = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.descriptorWallet = exports.fixedScriptWallet = exports.utxolibCompat = exports.message = exports.inscriptions = exports.bip322 = exports.ast = exports.address = void 0;
36
+ exports.hasPsbtMagic = exports.ZcashTransaction = exports.Transaction = exports.DashTransaction = exports.Psbt = exports.Miniscript = exports.Descriptor = exports.requiresPrevTxForP2sh = exports.isCoinName = exports.isTestnet = exports.isMainnet = exports.getMainnet = exports.ZcashDimensions = exports.Dimensions = exports.BIP32 = exports.ECPair = exports.ecpair = exports.bip32 = exports.descriptorWallet = exports.fixedScriptWallet = exports.utxolibCompat = exports.message = exports.inscriptions = exports.bip322 = exports.ast = exports.zcashAddress = exports.address = void 0;
37
37
  exports.getWasmUtxoVersion = getWasmUtxoVersion;
38
38
  exports.isWasmUtxoError = isWasmUtxoError;
39
39
  const wasm = __importStar(require("./wasm/wasm_utxo.js"));
@@ -44,6 +44,7 @@ void wasm;
44
44
  // Most exports are namespaced to avoid polluting the top-level namespace
45
45
  // and to make imports more explicit (e.g., `import { address } from '@bitgo/wasm-utxo'`)
46
46
  exports.address = __importStar(require("./address.js"));
47
+ exports.zcashAddress = __importStar(require("./zcashAddress.js"));
47
48
  exports.ast = __importStar(require("./ast/index.js"));
48
49
  exports.bip322 = __importStar(require("./bip322/index.js"));
49
50
  exports.inscriptions = __importStar(require("./inscriptions.js"));
@@ -60,6 +61,8 @@ var bip32_js_1 = require("./bip32.js");
60
61
  Object.defineProperty(exports, "BIP32", { enumerable: true, get: function () { return bip32_js_1.BIP32; } });
61
62
  var Dimensions_js_1 = require("./fixedScriptWallet/Dimensions.js");
62
63
  Object.defineProperty(exports, "Dimensions", { enumerable: true, get: function () { return Dimensions_js_1.Dimensions; } });
64
+ var ZcashDimensions_js_1 = require("./fixedScriptWallet/ZcashDimensions.js");
65
+ Object.defineProperty(exports, "ZcashDimensions", { enumerable: true, get: function () { return ZcashDimensions_js_1.ZcashDimensions; } });
63
66
  function getWasmUtxoVersion() {
64
67
  return wasm_utxo_js_1.WasmUtxoNamespace.get_wasm_utxo_version();
65
68
  }
@@ -7,12 +7,9 @@ export class AddressNamespace {
7
7
  [Symbol.dispose](): void;
8
8
  static from_output_script_with_coin(script: Uint8Array, coin: string, format?: string | null): string;
9
9
  /**
10
- * `can_be_shielded_output`: when set and `address` is a ZIP-316 unified address carrying an
11
- * Orchard/Ironwood receiver, returns that raw 43-byte receiver instead of a transparent
12
- * scriptPubKey. See [`to_output_script_or_shielded_receiver_with_coin`] for the exact
13
- * fallback/error rules.
10
+ * Convert `address` to its scriptPubKey bytes for `coin`.
14
11
  */
15
- static to_output_script_with_coin(address: string, coin: string, can_be_shielded_output?: boolean | null): Uint8Array;
12
+ static to_output_script_with_coin(address: string, coin: string): Uint8Array;
16
13
  }
17
14
 
18
15
  /**
@@ -1798,6 +1795,20 @@ export class ZcashUnifiedAddress {
1798
1795
  * below are infallible. Throws if the address is malformed or on the wrong network.
1799
1796
  */
1800
1797
  static parse(address: string, network: string): ZcashUnifiedAddress;
1798
+ /**
1799
+ * Whether this Unified Address carries an Orchard/Ironwood receiver.
1800
+ *
1801
+ * Equivalent to `orchardReceiver !== undefined`, without cloning the receiver bytes
1802
+ * when the caller only needs presence.
1803
+ */
1804
+ readonly hasOrchardReceiver: boolean;
1805
+ /**
1806
+ * Whether this Unified Address carries a transparent (P2PKH/P2SH) receiver.
1807
+ *
1808
+ * Equivalent to `transparentScript !== undefined`, without cloning the script bytes
1809
+ * when the caller only needs presence.
1810
+ */
1811
+ readonly hasTransparentReceiver: boolean;
1801
1812
  /**
1802
1813
  * The Orchard/Ironwood receiver's raw 43 bytes (diversifier + pk_d), or `undefined`.
1803
1814
  */
@@ -1966,6 +1977,43 @@ export function parsePsbtToJson(psbt_bytes: Uint8Array, coin_name: string): stri
1966
1977
  */
1967
1978
  export function parseTxToJson(tx_bytes: Uint8Array, coin_name: string): string;
1968
1979
 
1980
+ /**
1981
+ * Whether `address` is a ZIP-316 unified address for `coin`'s network carrying an
1982
+ * Orchard/Ironwood receiver. `false` (never throws) for a malformed/wrong-network unified
1983
+ * address, an ordinary address, or a UA with no Orchard/Ironwood receiver.
1984
+ */
1985
+ export function zcashHasOrchardReceiver(address: string, coin: string): boolean;
1986
+
1987
+ /**
1988
+ * Whether `address` has a usable transparent receiver for `coin`'s network: either it's a
1989
+ * unified address carrying a transparent receiver, or it's itself a valid transparent address
1990
+ * for `coin`. `false` (never throws) otherwise.
1991
+ */
1992
+ export function zcashHasTransparentReceiver(address: string, coin: string): boolean;
1993
+
1994
+ export function zcashToShieldedReceiverWithCoin(address: string, coin: string): Uint8Array;
1995
+
1996
+ /**
1997
+ * Resolve the Orchard/Ironwood receiver of a ZIP-316 unified address for `coin`'s network, as
1998
+ * its raw 43 bytes (diversifier + `pk_d`) — there is no scriptPubKey for a shielded output, so
1999
+ * this can't return script bytes uniformly and returns raw receiver bytes instead.
2000
+ *
2001
+ * A UA that has no Orchard/Ironwood receiver (e.g. Sapling-only) throws rather than falling back
2002
+ * to the transparent receiver. If `address` merely looks like a unified address for this coin's
2003
+ * network (right Bech32m HRP) but is malformed, this also throws. `address` must be a unified
2004
+ * address — an ordinary transparent address is rejected, since it can never carry a shielded
2005
+ * receiver; use {@link toOutputScriptWithCoin} in `js/address.ts` for the transparent case.
2006
+ * Resolve the transparent receiver of an `address` for `coin`'s network, as its scriptPubKey
2007
+ * bytes. When `address` is a ZIP-316 unified address, resolves its transparent receiver rather
2008
+ * than rejecting the UA string outright — a UA with no transparent receiver (e.g. Orchard-only)
2009
+ * throws rather than falling back to a shielded one. An ordinary (non-UA) address falls through
2010
+ * to the same transparent codec path as any other coin.
2011
+ *
2012
+ * This is the zcash-aware counterpart of `toOutputScriptWithCoin` in `js/address.ts`, which
2013
+ * dispatches here for zcash/tzec so that non-zcash coins never pay for a unified-address check.
2014
+ */
2015
+ export function zcashToTransparentReceiverWithCoin(address: string, coin: string): Uint8Array;
2016
+
1969
2017
  /**
1970
2018
  * Return the Zcash consensus branch ID active at `height` on `network`.
1971
2019
  *
@@ -48,23 +48,19 @@ class AddressNamespace {
48
48
  }
49
49
  }
50
50
  /**
51
- * `can_be_shielded_output`: when set and `address` is a ZIP-316 unified address carrying an
52
- * Orchard/Ironwood receiver, returns that raw 43-byte receiver instead of a transparent
53
- * scriptPubKey. See [`to_output_script_or_shielded_receiver_with_coin`] for the exact
54
- * fallback/error rules.
51
+ * Convert `address` to its scriptPubKey bytes for `coin`.
55
52
  * @param {string} address
56
53
  * @param {string} coin
57
- * @param {boolean | null} [can_be_shielded_output]
58
54
  * @returns {Uint8Array}
59
55
  */
60
- static to_output_script_with_coin(address, coin, can_be_shielded_output) {
56
+ static to_output_script_with_coin(address, coin) {
61
57
  try {
62
58
  const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
63
59
  const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
64
60
  const len0 = WASM_VECTOR_LEN;
65
61
  const ptr1 = passStringToWasm0(coin, wasm.__wbindgen_export, wasm.__wbindgen_export2);
66
62
  const len1 = WASM_VECTOR_LEN;
67
- wasm.addressnamespace_to_output_script_with_coin(retptr, ptr0, len0, ptr1, len1, isLikeNone(can_be_shielded_output) ? 0xFFFFFF : can_be_shielded_output ? 1 : 0);
63
+ wasm.addressnamespace_to_output_script_with_coin(retptr, ptr0, len0, ptr1, len1);
68
64
  var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
69
65
  var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
70
66
  var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
@@ -6818,6 +6814,28 @@ class ZcashUnifiedAddress {
6818
6814
  wasm.__wbindgen_export4(deferred4_0, deferred4_1, 1);
6819
6815
  }
6820
6816
  }
6817
+ /**
6818
+ * Whether this Unified Address carries an Orchard/Ironwood receiver.
6819
+ *
6820
+ * Equivalent to `orchardReceiver !== undefined`, without cloning the receiver bytes
6821
+ * when the caller only needs presence.
6822
+ * @returns {boolean}
6823
+ */
6824
+ get hasOrchardReceiver() {
6825
+ const ret = wasm.zcashunifiedaddress_hasOrchardReceiver(this.__wbg_ptr);
6826
+ return ret !== 0;
6827
+ }
6828
+ /**
6829
+ * Whether this Unified Address carries a transparent (P2PKH/P2SH) receiver.
6830
+ *
6831
+ * Equivalent to `transparentScript !== undefined`, without cloning the script bytes
6832
+ * when the caller only needs presence.
6833
+ * @returns {boolean}
6834
+ */
6835
+ get hasTransparentReceiver() {
6836
+ const ret = wasm.zcashunifiedaddress_hasTransparentReceiver(this.__wbg_ptr);
6837
+ return ret !== 0;
6838
+ }
6821
6839
  /**
6822
6840
  * The Orchard/Ironwood receiver's raw 43 bytes (diversifier + pk_d), or `undefined`.
6823
6841
  * @returns {Uint8Array | undefined}
@@ -7330,6 +7348,117 @@ function parseTxToJson(tx_bytes, coin_name) {
7330
7348
  }
7331
7349
  exports.parseTxToJson = parseTxToJson;
7332
7350
 
7351
+ /**
7352
+ * Whether `address` is a ZIP-316 unified address for `coin`'s network carrying an
7353
+ * Orchard/Ironwood receiver. `false` (never throws) for a malformed/wrong-network unified
7354
+ * address, an ordinary address, or a UA with no Orchard/Ironwood receiver.
7355
+ * @param {string} address
7356
+ * @param {string} coin
7357
+ * @returns {boolean}
7358
+ */
7359
+ function zcashHasOrchardReceiver(address, coin) {
7360
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7361
+ const len0 = WASM_VECTOR_LEN;
7362
+ const ptr1 = passStringToWasm0(coin, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7363
+ const len1 = WASM_VECTOR_LEN;
7364
+ const ret = wasm.zcashHasOrchardReceiver(ptr0, len0, ptr1, len1);
7365
+ return ret !== 0;
7366
+ }
7367
+ exports.zcashHasOrchardReceiver = zcashHasOrchardReceiver;
7368
+
7369
+ /**
7370
+ * Whether `address` has a usable transparent receiver for `coin`'s network: either it's a
7371
+ * unified address carrying a transparent receiver, or it's itself a valid transparent address
7372
+ * for `coin`. `false` (never throws) otherwise.
7373
+ * @param {string} address
7374
+ * @param {string} coin
7375
+ * @returns {boolean}
7376
+ */
7377
+ function zcashHasTransparentReceiver(address, coin) {
7378
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7379
+ const len0 = WASM_VECTOR_LEN;
7380
+ const ptr1 = passStringToWasm0(coin, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7381
+ const len1 = WASM_VECTOR_LEN;
7382
+ const ret = wasm.zcashHasTransparentReceiver(ptr0, len0, ptr1, len1);
7383
+ return ret !== 0;
7384
+ }
7385
+ exports.zcashHasTransparentReceiver = zcashHasTransparentReceiver;
7386
+
7387
+ /**
7388
+ * @param {string} address
7389
+ * @param {string} coin
7390
+ * @returns {Uint8Array}
7391
+ */
7392
+ function zcashToShieldedReceiverWithCoin(address, coin) {
7393
+ try {
7394
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
7395
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7396
+ const len0 = WASM_VECTOR_LEN;
7397
+ const ptr1 = passStringToWasm0(coin, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7398
+ const len1 = WASM_VECTOR_LEN;
7399
+ wasm.zcashToShieldedReceiverWithCoin(retptr, ptr0, len0, ptr1, len1);
7400
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
7401
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
7402
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
7403
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
7404
+ if (r3) {
7405
+ throw takeObject(r2);
7406
+ }
7407
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
7408
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
7409
+ return v3;
7410
+ } finally {
7411
+ wasm.__wbindgen_add_to_stack_pointer(16);
7412
+ }
7413
+ }
7414
+ exports.zcashToShieldedReceiverWithCoin = zcashToShieldedReceiverWithCoin;
7415
+
7416
+ /**
7417
+ * Resolve the Orchard/Ironwood receiver of a ZIP-316 unified address for `coin`'s network, as
7418
+ * its raw 43 bytes (diversifier + `pk_d`) — there is no scriptPubKey for a shielded output, so
7419
+ * this can't return script bytes uniformly and returns raw receiver bytes instead.
7420
+ *
7421
+ * A UA that has no Orchard/Ironwood receiver (e.g. Sapling-only) throws rather than falling back
7422
+ * to the transparent receiver. If `address` merely looks like a unified address for this coin's
7423
+ * network (right Bech32m HRP) but is malformed, this also throws. `address` must be a unified
7424
+ * address — an ordinary transparent address is rejected, since it can never carry a shielded
7425
+ * receiver; use {@link toOutputScriptWithCoin} in `js/address.ts` for the transparent case.
7426
+ * Resolve the transparent receiver of an `address` for `coin`'s network, as its scriptPubKey
7427
+ * bytes. When `address` is a ZIP-316 unified address, resolves its transparent receiver rather
7428
+ * than rejecting the UA string outright — a UA with no transparent receiver (e.g. Orchard-only)
7429
+ * throws rather than falling back to a shielded one. An ordinary (non-UA) address falls through
7430
+ * to the same transparent codec path as any other coin.
7431
+ *
7432
+ * This is the zcash-aware counterpart of `toOutputScriptWithCoin` in `js/address.ts`, which
7433
+ * dispatches here for zcash/tzec so that non-zcash coins never pay for a unified-address check.
7434
+ * @param {string} address
7435
+ * @param {string} coin
7436
+ * @returns {Uint8Array}
7437
+ */
7438
+ function zcashToTransparentReceiverWithCoin(address, coin) {
7439
+ try {
7440
+ const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
7441
+ const ptr0 = passStringToWasm0(address, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7442
+ const len0 = WASM_VECTOR_LEN;
7443
+ const ptr1 = passStringToWasm0(coin, wasm.__wbindgen_export, wasm.__wbindgen_export2);
7444
+ const len1 = WASM_VECTOR_LEN;
7445
+ wasm.zcashToTransparentReceiverWithCoin(retptr, ptr0, len0, ptr1, len1);
7446
+ var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
7447
+ var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
7448
+ var r2 = getDataViewMemory0().getInt32(retptr + 4 * 2, true);
7449
+ var r3 = getDataViewMemory0().getInt32(retptr + 4 * 3, true);
7450
+ if (r3) {
7451
+ throw takeObject(r2);
7452
+ }
7453
+ var v3 = getArrayU8FromWasm0(r0, r1).slice();
7454
+ wasm.__wbindgen_export4(r0, r1 * 1, 1);
7455
+ return v3;
7456
+ } finally {
7457
+ wasm.__wbindgen_add_to_stack_pointer(16);
7458
+ }
7459
+ }
7460
+ exports.zcashToTransparentReceiverWithCoin = zcashToTransparentReceiverWithCoin;
7461
+
7333
7462
  /**
7334
7463
  * Return the Zcash consensus branch ID active at `height` on `network`.
7335
7464
  *
Binary file