@xyo-network/xl1-react-client-sdk 2.0.13 → 2.1.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.
@@ -0,0 +1,56 @@
1
+ import type { StackProps } from '@mui/material';
2
+ import type { Payload } from '@xyo-network/sdk-js';
3
+ import type { GatewayName } from '@xyo-network/xl1-sdk';
4
+ import React from 'react';
5
+ export interface SignTransactionButtonProps extends StackProps {
6
+ /**
7
+ * When true (default), elevate a single `network.xyo.hash` payload on-chain
8
+ * that anchors the first referenced payload by hash. This populates the
9
+ * wallet's "On-Chain Payloads" section with a realistic anchor while the
10
+ * referenced content itself stays off-chain. When false, no payloads are
11
+ * elevated and the "On-Chain Payloads" section renders empty.
12
+ */
13
+ anchorOnChain?: boolean;
14
+ /** Gateway/network to build the transaction against. Defaults to `SequenceNetwork.id`. */
15
+ gatewayName?: GatewayName;
16
+ /**
17
+ * Payloads referenced by hash but NOT included with the transaction — only
18
+ * their hash + schema reach the wallet. Exercises the wallet's existing
19
+ * "Private Referenced Payloads" (hash + schema only) section. Defaults to none.
20
+ */
21
+ privateReferencedPayloads?: Payload[];
22
+ /**
23
+ * Payloads passed in full via the RPC request that are referenced (in the
24
+ * bound witness `payload_hashes`) but NOT elevated on-chain. Exercises the
25
+ * wallet's "Referenced Payloads" section — the full contents are shown
26
+ * because they ride along with the transaction even though they won't be
27
+ * stored on-chain. Defaults to none.
28
+ */
29
+ referencedPayloads?: Payload[];
30
+ /** Wallet-detection timeout, forwarded to the wallet hooks. */
31
+ timeout?: number;
32
+ }
33
+ /**
34
+ * Manual Storybook harness that drives the live XL1 Wallet's transaction-signing
35
+ * popup with caller-supplied payloads. It assembles an
36
+ * {@link UnsignedHydratedTransaction} from three independently-stubbed payload
37
+ * groups and calls `signer.signTransaction(tx)`, which opens the wallet's Sign
38
+ * page so its payload sections can be visually verified:
39
+ *
40
+ * - **On-Chain Payloads** — `anchorOnChain` elevates a `network.xyo.hash`
41
+ * payload that anchors `referencedPayloads[0]`.
42
+ * - **Referenced Payloads** — `referencedPayloads` ride along in the
43
+ * transaction's payload array (so the wallet has their full contents) but are
44
+ * not marked elevated, so they won't be stored on-chain.
45
+ * - **Private Referenced Payloads** — `privateReferencedPayloads` are appended
46
+ * to the bound witness's `payload_hashes` / `payload_schemas` only; their
47
+ * contents are withheld, so the wallet can show no more than hash + schema.
48
+ *
49
+ * Chain id, `nbf`, and `exp` are resolved from the gateway's viewer and `from`
50
+ * from the wallet signer, so the transaction is well-formed for the active
51
+ * account. The transaction is only signed, never broadcast — clicking Sign in
52
+ * the wallet returns the signed transaction here and renders its bound-witness
53
+ * hash; nothing is sent to the network.
54
+ */
55
+ export declare const SignTransactionButton: React.FC<SignTransactionButtonProps>;
56
+ //# sourceMappingURL=SignTransactionButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SignTransactionButton.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/connected/SignTransactionButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAS/C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAElD,OAAO,KAAK,EACV,WAAW,EACZ,MAAM,sBAAsB,CAAA;AAI7B,OAAO,KAAgC,MAAM,OAAO,CAAA;AAoBpD,MAAM,WAAW,0BAA2B,SAAQ,UAAU;IAC5D;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,0FAA0F;IAC1F,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,OAAO,EAAE,CAAA;IACrC;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,EAAE,CAAA;IAC9B,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CA4ItE,CAAA"}
@@ -13,4 +13,5 @@ export * from './DataLakeRequestAccessPanel.tsx';
13
13
  export * from './hooks/index.ts';
14
14
  export * from './PermissionsReviewDialog.tsx';
15
15
  export * from './RequestPermissionsButton.tsx';
16
+ export * from './SignTransactionButton.tsx';
16
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/connected/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mCAAmC,CAAA;AACjD,cAAc,kCAAkC,CAAA;AAChD,cAAc,kBAAkB,CAAA;AAChC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,gCAAgC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/client/components/connected/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,+BAA+B,CAAA;AAC7C,cAAc,yBAAyB,CAAA;AACvC,cAAc,wBAAwB,CAAA;AACtC,cAAc,4BAA4B,CAAA;AAC1C,cAAc,2BAA2B,CAAA;AACzC,cAAc,0BAA0B,CAAA;AACxC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,mCAAmC,CAAA;AACjD,cAAc,kCAAkC,CAAA;AAChD,cAAc,kBAAkB,CAAA;AAChC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,6BAA6B,CAAA"}
@@ -4,7 +4,7 @@ import {
4
4
  Tooltip,
5
5
  Typography
6
6
  } from "@mui/material";
7
- import { EthAddressWrapper } from "@xylabs/sdk-js";
7
+ import { EthAddressWrapper } from "@xylabs/eth-address";
8
8
  import { BlockiesAvatarAddress } from "@xyo-network/xl1-blockies";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
10
  var ConnectedAccount = ({ address }) => {
@@ -1655,6 +1655,163 @@ var DataLakeOperationsPanel = ({ timeout, ...props }) => {
1655
1655
  );
1656
1656
  };
1657
1657
 
1658
+ // src/client/components/connected/SignTransactionButton.tsx
1659
+ import {
1660
+ Alert as Alert11,
1661
+ Chip as Chip3,
1662
+ Divider as Divider4,
1663
+ Stack as Stack15,
1664
+ Typography as Typography13
1665
+ } from "@mui/material";
1666
+ import { ButtonEx as ButtonEx10 } from "@xylabs/react-button";
1667
+ import { PopoverErrorRender as PopoverErrorRender2 } from "@xylabs/react-error";
1668
+ import {
1669
+ assertEx as assertEx2,
1670
+ isDefined as isDefined12,
1671
+ isDefinedNotNull as isDefinedNotNull9
1672
+ } from "@xylabs/sdk-js";
1673
+ import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
1674
+ import {
1675
+ asXL1BlockNumber,
1676
+ buildUnsignedTransaction,
1677
+ HashSchema as HashSchema2,
1678
+ SequenceNetwork as SequenceNetwork2
1679
+ } from "@xyo-network/xl1-sdk";
1680
+ import { useCallback as useCallback4, useState as useState13 } from "react";
1681
+ import { jsx as jsx15, jsxs as jsxs15 } from "react/jsx-runtime";
1682
+ var EMPTY_PAYLOADS = [];
1683
+ var SIGNER_PERMISSIONS = [
1684
+ { xyoWallet_getAccounts: { restrictReturnedAccounts: [] } },
1685
+ { xyoSigner_address: {} }
1686
+ ];
1687
+ var SignTransactionButton = ({
1688
+ anchorOnChain = true,
1689
+ gatewayName = SequenceNetwork2.id,
1690
+ privateReferencedPayloads = EMPTY_PAYLOADS,
1691
+ referencedPayloads = EMPTY_PAYLOADS,
1692
+ timeout,
1693
+ ...props
1694
+ }) => {
1695
+ const {
1696
+ gateway,
1697
+ error: gatewayError,
1698
+ timedout
1699
+ } = useGatewayFromWallet(gatewayName, timeout);
1700
+ const [signing, setSigning] = useState13(false);
1701
+ const [signError, setSignError] = useState13();
1702
+ const [signedHash, setSignedHash] = useState13();
1703
+ const signer = gateway?.signer;
1704
+ const viewer = gateway?.connection?.viewer;
1705
+ const canSign = isDefinedNotNull9(signer) && isDefinedNotNull9(viewer) && !signing;
1706
+ const handleSign = useCallback4(async () => {
1707
+ if (!isDefinedNotNull9(gateway)) return;
1708
+ const resolvedSigner = assertEx2(gateway.signer, () => "No signer available on gateway");
1709
+ const resolvedViewer = assertEx2(gateway.connection?.viewer, () => "No viewer available on gateway connection");
1710
+ setSignError(void 0);
1711
+ setSignedHash(void 0);
1712
+ setSigning(true);
1713
+ try {
1714
+ const chain = await resolvedViewer.chainId();
1715
+ const nbf = asXL1BlockNumber(await resolvedViewer.currentBlockNumber(), true);
1716
+ const exp = asXL1BlockNumber(nbf + 10, true);
1717
+ const from = await resolvedSigner.address();
1718
+ const referencedHashes = await PayloadBuilder2.hashes(referencedPayloads);
1719
+ const onChainPayloads = anchorOnChain && isDefined12(referencedHashes[0]) ? [{ schema: HashSchema2, hash: referencedHashes[0] }] : [];
1720
+ let tx = await buildUnsignedTransaction(
1721
+ chain,
1722
+ onChainPayloads,
1723
+ referencedPayloads,
1724
+ nbf,
1725
+ exp,
1726
+ from
1727
+ );
1728
+ if (privateReferencedPayloads.length > 0) {
1729
+ const privateHashes = await PayloadBuilder2.hashes(privateReferencedPayloads);
1730
+ const [bw, payloads] = tx;
1731
+ tx = [
1732
+ {
1733
+ ...bw,
1734
+ payload_hashes: [...bw.payload_hashes, ...privateHashes],
1735
+ payload_schemas: [...bw.payload_schemas, ...privateReferencedPayloads.map((payload) => payload.schema)]
1736
+ },
1737
+ payloads
1738
+ ];
1739
+ }
1740
+ const [signedBoundWitness] = await resolvedSigner.signTransaction(tx);
1741
+ setSignedHash(await PayloadBuilder2.hash(signedBoundWitness));
1742
+ } catch (e) {
1743
+ setSignError(e);
1744
+ } finally {
1745
+ setSigning(false);
1746
+ }
1747
+ }, [anchorOnChain, gateway, privateReferencedPayloads, referencedPayloads]);
1748
+ return /* @__PURE__ */ jsxs15(
1749
+ Stack15,
1750
+ {
1751
+ ...props,
1752
+ sx: {
1753
+ gap: 3,
1754
+ alignItems: "stretch",
1755
+ ...props.sx
1756
+ },
1757
+ children: [
1758
+ timedout ? /* @__PURE__ */ jsx15(Alert11, { severity: "warning", children: "Wallet not detected." }) : null,
1759
+ /* @__PURE__ */ jsxs15(Stack15, { sx: { gap: 1 }, children: [
1760
+ /* @__PURE__ */ jsx15(Typography13, { variant: "subtitle2", children: "1. Grant signer + account access" }),
1761
+ /* @__PURE__ */ jsx15(RequestPermissionsButton, { permissions: SIGNER_PERMISSIONS, timeout })
1762
+ ] }),
1763
+ /* @__PURE__ */ jsx15(Divider4, {}),
1764
+ /* @__PURE__ */ jsxs15(Stack15, { sx: { gap: 1, alignItems: "start" }, children: [
1765
+ /* @__PURE__ */ jsx15(Typography13, { variant: "subtitle2", children: "2. Sign the transaction" }),
1766
+ /* @__PURE__ */ jsxs15(Typography13, { variant: "caption", sx: { color: "text.secondary" }, children: [
1767
+ "Opens the wallet's Sign page with",
1768
+ " ",
1769
+ anchorOnChain ? "1 on-chain anchor, " : "no on-chain payloads, ",
1770
+ referencedPayloads.length,
1771
+ " ",
1772
+ "referenced, and",
1773
+ " ",
1774
+ privateReferencedPayloads.length,
1775
+ " ",
1776
+ "private referenced payload",
1777
+ privateReferencedPayloads.length === 1 ? "" : "s",
1778
+ ". The signed transaction is returned here and not broadcast."
1779
+ ] }),
1780
+ /* @__PURE__ */ jsxs15(Stack15, { direction: "row", sx: { gap: 1, alignItems: "center" }, children: [
1781
+ /* @__PURE__ */ jsx15(
1782
+ ButtonEx10,
1783
+ {
1784
+ variant: "contained",
1785
+ size: "small",
1786
+ disabled: !canSign,
1787
+ busy: signing,
1788
+ onClick: () => void handleSign(),
1789
+ children: "Sign transaction"
1790
+ }
1791
+ ),
1792
+ /* @__PURE__ */ jsx15(PopoverErrorRender2, { error: gatewayError ?? signError, scope: "SignTransactionButton" })
1793
+ ] }),
1794
+ isDefined12(signedHash) ? /* @__PURE__ */ jsxs15(
1795
+ Stack15,
1796
+ {
1797
+ direction: "row",
1798
+ sx: {
1799
+ alignItems: "center",
1800
+ flexWrap: "wrap",
1801
+ gap: 1
1802
+ },
1803
+ children: [
1804
+ /* @__PURE__ */ jsx15(Chip3, { label: "Signed", size: "small", color: "success" }),
1805
+ /* @__PURE__ */ jsx15(Typography13, { variant: "body2", sx: { fontFamily: "monospace", wordBreak: "break-all" }, children: signedHash })
1806
+ ]
1807
+ }
1808
+ ) : null
1809
+ ] })
1810
+ ]
1811
+ }
1812
+ );
1813
+ };
1814
+
1658
1815
  // src/client/context/GatewayContext.ts
1659
1816
  import { createContextEx } from "@xylabs/react-shared";
1660
1817
  var GatewayContext = createContextEx();
@@ -1667,14 +1824,14 @@ var InPageGatewaysContext = createContextEx2();
1667
1824
  import { DefaultNetworks as DefaultNetworks2 } from "@xyo-network/xl1-sdk";
1668
1825
  import {
1669
1826
  startTransition,
1670
- useCallback as useCallback4,
1827
+ useCallback as useCallback5,
1671
1828
  useEffect as useEffect5,
1672
1829
  useMemo as useMemo5,
1673
- useState as useState13
1830
+ useState as useState14
1674
1831
  } from "react";
1675
1832
 
1676
1833
  // src/client/context/in-page/lib/buildGateway.ts
1677
- import { assertEx as assertEx2, isDefined as isDefined12 } from "@xylabs/sdk-js";
1834
+ import { assertEx as assertEx3, isDefined as isDefined13 } from "@xylabs/sdk-js";
1678
1835
  import {
1679
1836
  basicRemoteRunnerLocator,
1680
1837
  basicRemoteViewerLocator,
@@ -1683,24 +1840,24 @@ import {
1683
1840
  } from "@xyo-network/xl1-sdk";
1684
1841
  var buildGateway = async (gatewayName, signerTransport) => {
1685
1842
  const network = DefaultNetworks.find((network2) => network2.id === gatewayName);
1686
- const resolvedNetwork = assertEx2(network, () => `No network found for id ${gatewayName}`);
1843
+ const resolvedNetwork = assertEx3(network, () => `No network found for id ${gatewayName}`);
1687
1844
  const remoteConfig = {
1688
1845
  rpc: {
1689
1846
  protocol: "http",
1690
1847
  url: `${resolvedNetwork.url}/rpc`
1691
1848
  }
1692
1849
  };
1693
- const locator = isDefined12(signerTransport) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, signerTransport) : await basicRemoteViewerLocator(gatewayName, remoteConfig);
1850
+ const locator = isDefined13(signerTransport) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, signerTransport) : await basicRemoteViewerLocator(gatewayName, remoteConfig);
1694
1851
  return await locator.getInstance(XyoGatewayMoniker);
1695
1852
  };
1696
1853
 
1697
1854
  // src/client/context/in-page/Provider.tsx
1698
- import { jsx as jsx15 } from "react/jsx-runtime";
1855
+ import { jsx as jsx16 } from "react/jsx-runtime";
1699
1856
  var InPageGatewaysProvider = ({ signerTransport, children }) => {
1700
- const [gateways, setGateways] = useState13({});
1701
- const [errors, setErrors] = useState13({});
1702
- const [previousSignerTransport, setPreviousSignerTransport] = useState13(signerTransport);
1703
- const clearAll = useCallback4(() => {
1857
+ const [gateways, setGateways] = useState14({});
1858
+ const [errors, setErrors] = useState14({});
1859
+ const [previousSignerTransport, setPreviousSignerTransport] = useState14(signerTransport);
1860
+ const clearAll = useCallback5(() => {
1704
1861
  setGateways({});
1705
1862
  setErrors({});
1706
1863
  }, []);
@@ -1747,7 +1904,7 @@ var InPageGatewaysProvider = ({ signerTransport, children }) => {
1747
1904
  };
1748
1905
  return value2;
1749
1906
  }, [clearAll, errors, gateways]);
1750
- return /* @__PURE__ */ jsx15(InPageGatewaysContext, { value, children });
1907
+ return /* @__PURE__ */ jsx16(InPageGatewaysContext, { value, children });
1751
1908
  };
1752
1909
 
1753
1910
  // src/client/context/in-page/useProvidedInPageGateways.ts
@@ -1756,9 +1913,9 @@ var useProvidedInPageGateways = (required = true) => useContextEx(InPageGateways
1756
1913
 
1757
1914
  // src/client/context/providers/GatewayProvider.tsx
1758
1915
  import { ErrorRender as ErrorRender9 } from "@xylabs/react-error";
1759
- import { isDefinedNotNull as isDefinedNotNull9, isNull as isNull2 } from "@xylabs/sdk-js";
1916
+ import { isDefinedNotNull as isDefinedNotNull10, isNull as isNull2 } from "@xylabs/sdk-js";
1760
1917
  import { useMemo as useMemo6 } from "react";
1761
- import { jsx as jsx16, jsxs as jsxs15 } from "react/jsx-runtime";
1918
+ import { jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
1762
1919
  var GatewayProvider = ({ gatewayName, children }) => {
1763
1920
  const {
1764
1921
  gateway: gatewayFromWallet,
@@ -1780,7 +1937,7 @@ var GatewayProvider = ({ gatewayName, children }) => {
1780
1937
  walletGateway: null
1781
1938
  }
1782
1939
  };
1783
- } else if (isDefinedNotNull9(gatewayFromWallet)) {
1940
+ } else if (isDefinedNotNull10(gatewayFromWallet)) {
1784
1941
  return {
1785
1942
  defaultGateway: gatewayFromWallet,
1786
1943
  gateways: {
@@ -1813,8 +1970,8 @@ var GatewayProvider = ({ gatewayName, children }) => {
1813
1970
  gateways,
1814
1971
  clearAll
1815
1972
  ]);
1816
- return /* @__PURE__ */ jsxs15(GatewayContext, { value, children: [
1817
- /* @__PURE__ */ jsx16(ErrorRender9, { error: gatewayFromConfigError }),
1973
+ return /* @__PURE__ */ jsxs16(GatewayContext, { value, children: [
1974
+ /* @__PURE__ */ jsx17(ErrorRender9, { error: gatewayFromConfigError }),
1818
1975
  children
1819
1976
  ] });
1820
1977
  };
@@ -1822,7 +1979,7 @@ var GatewayProvider = ({ gatewayName, children }) => {
1822
1979
  // src/client/context/providers/WalletGatewayProvider.tsx
1823
1980
  import { ErrorRender as ErrorRender10 } from "@xylabs/react-error";
1824
1981
  import { useMemo as useMemo7 } from "react";
1825
- import { jsx as jsx17, jsxs as jsxs16 } from "react/jsx-runtime";
1982
+ import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
1826
1983
  var WalletGatewayProvider = ({ gatewayName, children }) => {
1827
1984
  const {
1828
1985
  gateway: gatewayFromWallet,
@@ -1850,8 +2007,8 @@ var WalletGatewayProvider = ({ gatewayName, children }) => {
1850
2007
  gatewayFromWalletError,
1851
2008
  gateways
1852
2009
  ]);
1853
- return /* @__PURE__ */ jsxs16(GatewayContext, { value, children: [
1854
- /* @__PURE__ */ jsx17(ErrorRender10, { error: gatewayFromWalletError }),
2010
+ return /* @__PURE__ */ jsxs17(GatewayContext, { value, children: [
2011
+ /* @__PURE__ */ jsx18(ErrorRender10, { error: gatewayFromWalletError }),
1855
2012
  children
1856
2013
  ] });
1857
2014
  };
@@ -1878,6 +2035,7 @@ export {
1878
2035
  InPageGatewaysProvider,
1879
2036
  PermissionsReviewDialog,
1880
2037
  RequestPermissionsButton,
2038
+ SignTransactionButton,
1881
2039
  WalletGatewayProvider,
1882
2040
  findCaveat,
1883
2041
  getXyoClient,