@gala-chain/gala-core-sdk 1.1.0-beta.4 → 1.1.0-beta.5

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.
package/README.md CHANGED
@@ -104,8 +104,16 @@ unwrap) signs the TOKEN contract's `dtoOperation`
104
104
  (`asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut`, not the bridge contract's, which the
105
105
  chain refuses; verified on stage, 2026-11-02) as a field of its EIP-712 `GalaTransaction` type, so the
106
106
  signature covers it; `buildBridgeOutPayload` does this. The wrap / unwrap request carries no `wrap` field:
107
- the contract's `RequestTokenBridgeOut` DTO has none (strict validation refuses it) and the direction is the
108
- destination channel id. The other bridge strings, all seen live on stage and signed by GalaConnect (this SDK
107
+ the chain's strict validation refuses it and the direction is the destination channel id (verified on stage in
108
+ both directions). It is signed under the SOURCE channel's token contract
109
+ (`asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut` to unwrap, `music_music_GalaChainToken:RequestTokenBridgeOut`
110
+ to wrap; the gateway answers a wrong operation with a bare 401 `UNAUTHORIZED`) and goes through the swap backend's
111
+ chain route (`GalaConnectClient.requestWrapOut`, which needs the client's `dexBackendBaseUrl`: the backend root
112
+ without `/api/v1`; it checks the signer, the amount and the operation, then relays to the chain), not through
113
+ GalaConnect's `/RequestTokenBridgeOut`, which only treats a request as a wrap when it carries the `wrap: true` the
114
+ chain refuses. Only the completion
115
+ (`BridgeTokenOut`) is GalaConnect's: the chain wants the bridge authority's signature for it (a user-signed one is
116
+ refused with `NOT_A_BRIDGE_AUTHORITY`). The other bridge strings, all seen live on stage and signed by GalaConnect (this SDK
109
117
  signs none of them): `BridgeTokenOut` on `/asset/bridge-contract` is
110
118
  `asset-channel_bridge-chaincode_BridgeContract:BridgeTokenOut` (the operation table's bridge-contract entry
111
119
  is right for it), and the grants embedded in a `BridgeTokenOut` sign
@@ -292,7 +300,7 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
292
300
 
293
301
  ## Status
294
302
 
295
- <!-- docs:var version -->1.1.0-beta.4<!-- /docs:var --> (rc.7: `eth|0x<hex>` is refused as `INVALID_ETH_USER_REF_PREFIX`, not an address form; rc.6: `fetchPublicKey`, MetaMask and Trust Wallet detection, silent `restore()`;
303
+ <!-- docs:var version -->1.1.0-beta.5<!-- /docs:var --> (rc.7: `eth|0x<hex>` is refused as `INVALID_ETH_USER_REF_PREFIX`, not an address form; rc.6: `fetchPublicKey`, MetaMask and Trust Wallet detection, silent `restore()`;
296
304
  rc.5: every Ethereum account a read, write or GalaConnect client sends is
297
305
  `eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
298
306
  `bridgeableTokenService` is required). In: signing, signers, transport and the error model (rc.0, from gswap-sdk); the
package/dist/bridge.cjs CHANGED
@@ -1345,6 +1345,18 @@ function uniqueKeyOf(payload) {
1345
1345
  const key = payload["uniqueKey"];
1346
1346
  return typeof key === "string" && key !== "" ? key : void 0;
1347
1347
  }
1348
+ /**
1349
+ * The chain's own answer inside the swap backend's chain-route envelope
1350
+ * (`{ status, data: { transactionId, blockNumber, mode, result: { Data, Status } } }`); an answer
1351
+ * without that shape is returned as it is, for the caller's checks to refuse.
1352
+ */
1353
+ function chainResultOf(answer) {
1354
+ if (typeof answer !== "object" || answer === null) return answer;
1355
+ const data = answer["data"];
1356
+ if (typeof data !== "object" || data === null) return answer;
1357
+ const result = data["result"];
1358
+ return typeof result === "object" && result !== null ? result : answer;
1359
+ }
1348
1360
  /** `GALACONNECT_HTTP_ERROR` for an answer of status `status` and body text `text`. */
1349
1361
  function httpFailure(op, url, status, text) {
1350
1362
  const body = safeParseJson(text, { rawBody: text.slice(0, MAX_ERROR_BODY_LENGTH) });
@@ -1435,6 +1447,7 @@ function shouldRetryAttempt(error, op) {
1435
1447
  var GalaConnectClient = class {
1436
1448
  baseUrl;
1437
1449
  galachainBaseUrl;
1450
+ dexBackendBaseUrl;
1438
1451
  walletAddress;
1439
1452
  rateLimiter;
1440
1453
  defaultHeaders;
@@ -1457,6 +1470,7 @@ var GalaConnectClient = class {
1457
1470
  this.requestTimeoutMs = (0, _gala_chain_gala_core_sdk.validateTimeoutMs)(config.requestTimeoutMs ?? DEFAULT_CONFIG.requestTimeoutMs, "requestTimeoutMs");
1458
1471
  this.baseUrl = assertHttpUrlOption(config.baseUrl ?? DEFAULT_CONFIG.baseUrl, "baseUrl");
1459
1472
  this.galachainBaseUrl = assertHttpUrlOption(config.galachainBaseUrl ?? DEFAULT_CONFIG.galachainBaseUrl, "galachainBaseUrl");
1473
+ this.dexBackendBaseUrl = config.dexBackendBaseUrl === void 0 ? void 0 : assertHttpUrlOption(config.dexBackendBaseUrl, "dexBackendBaseUrl").replace(/\/+$/u, "");
1460
1474
  this.walletAddress = config.walletAddress === "" ? "" : (0, _gala_chain_gala_core_sdk.galaChainUserRef)(config.walletAddress, "walletAddress");
1461
1475
  this.rateLimiter = new RateLimiter(config.requestsPerSecond ?? DEFAULT_CONFIG.requestsPerSecond);
1462
1476
  this.requestor = config.httpRequestor ?? ((url, init) => globalThis.fetch(url, init));
@@ -1554,6 +1568,34 @@ var GalaConnectClient = class {
1554
1568
  }, payload);
1555
1569
  }
1556
1570
  /**
1571
+ * Request a wrap or unwrap: the natively signed `RequestTokenBridgeOut` on the SOURCE channel's
1572
+ * token contract, sent through the swap backend's chain route
1573
+ * (`<dexBackendBaseUrl>/v1/chain/<channel>/token-contract/RequestTokenBridgeOut`), which checks
1574
+ * the signer, the amount and the `dtoOperation` before it relays the request to the chain.
1575
+ *
1576
+ * A wrap is a channel move, so it is not a GalaConnect request: the message names the
1577
+ * destination channel (`destinationChainId`) and carries no wrap flag. GalaConnect's own
1578
+ * `/RequestTokenBridgeOut` route decides "wrap" from a `wrap: true` field that the chain refuses,
1579
+ * which is why this request does not go through it. Only the completion (`bridgeTokenOut`) is
1580
+ * GalaConnect's, because the chain wants the bridge authority's signature for it.
1581
+ *
1582
+ * @param channel - The source channel (`asset`, `music`): one lowercase path segment
1583
+ * @param payload - The signed `RequestTokenBridgeOut` body
1584
+ * @returns The chain's answer, `{ Data: <bridge request id>, Status: 1 }` (the backend's envelope
1585
+ * `{ status, data: { transactionId, result } }` is read down to `result`)
1586
+ * @throws GalaSDKError `INVALID_BRIDGE_OPTION` (`channel`) for a channel that is no path segment,
1587
+ * (`dexBackendBaseUrl`) for a client built without the swap backend's URL
1588
+ */
1589
+ async requestWrapOut(channel, payload) {
1590
+ if (!/^[a-z0-9-]+$/u.test(channel)) throw new _gala_chain_gala_core_sdk.GalaSDKError("INVALID_BRIDGE_OPTION", { option: "channel" });
1591
+ if (this.dexBackendBaseUrl === void 0) throw new _gala_chain_gala_core_sdk.GalaSDKError("INVALID_BRIDGE_OPTION", { option: "dexBackendBaseUrl" });
1592
+ return chainResultOf(await this.postJson({
1593
+ path: `/v1/chain/${channel}/token-contract/RequestTokenBridgeOut`,
1594
+ write: true,
1595
+ uniqueKey: uniqueKeyOf(payload)
1596
+ }, payload, { baseUrl: this.dexBackendBaseUrl }));
1597
+ }
1598
+ /**
1557
1599
  * Execute bridge token out (generate wormhole message).
1558
1600
  *
1559
1601
  * This is the second step in the bridge out process.
@@ -4641,8 +4683,11 @@ var WrappableTokenService = class {
4641
4683
  * Wrap Service
4642
4684
  *
4643
4685
  * Cross-channel wrap (a token from its own channel to the asset channel, e.g. MUSIC → GMUSIC) and
4644
- * unwrap (back), through GalaConnect: the natively signed `RequestTokenBridgeOut`, then
4645
- * `BridgeTokenOut` from the source channel.
4686
+ * unwrap (back): the natively signed `RequestTokenBridgeOut` goes through the swap backend's chain
4687
+ * route (`dexBackendBaseUrl`, which checks it and relays it) to the source channel's token contract
4688
+ * (the destination channel id in the message is the whole instruction; there is no wrap flag), then
4689
+ * GalaConnect completes it with `BridgeTokenOut` (the chain wants the bridge authority's signature
4690
+ * for that call).
4646
4691
  *
4647
4692
  * A wrap or unwrap that does not complete throws (nothing is returned as a "failed" result):
4648
4693
  * before anything is sent, the refusal of the input (`TOKEN_NOT_WRAPPABLE`,
@@ -4661,6 +4706,11 @@ const CHANNEL_IDS = {
4661
4706
  [ASSET_CHANNEL]: GALACHAIN_CHANNELS.ASSET,
4662
4707
  music: GALACHAIN_CHANNELS.MUSIC
4663
4708
  };
4709
+ /** The token contract a wrap or unwrap is requested on, by its source channel. */
4710
+ const WRAP_TOKEN_CONTRACT_PATHS = {
4711
+ [ASSET_CHANNEL]: "asset/token-contract",
4712
+ music: "music/token-contract"
4713
+ };
4664
4714
  /** The prefix of a wrap or unwrap uniqueKey. */
4665
4715
  const WRAP_UNIQUE_KEY_PREFIX = "galaswap-operation-";
4666
4716
  /**
@@ -4791,8 +4841,8 @@ var WrapService = class {
4791
4841
  recipient,
4792
4842
  uniqueKey
4793
4843
  };
4794
- const requestBody = await (0, _gala_chain_gala_core_sdk.signPreSend)(this.signer, BRIDGE_OUT_CONTRACT_PATH, "RequestTokenBridgeOut", message);
4795
- const response = await this.galaConnectClient.requestBridgeOut(requestBody);
4844
+ const requestBody = await (0, _gala_chain_gala_core_sdk.signPreSend)(this.signer, WRAP_TOKEN_CONTRACT_PATHS[routing.sourceChannel], "RequestTokenBridgeOut", message);
4845
+ const response = await this.galaConnectClient.requestWrapOut(routing.sourceChannel, requestBody);
4796
4846
  assertRequestAccepted("RequestTokenBridgeOut", response, uniqueKey);
4797
4847
  return {
4798
4848
  success: true,