@gala-chain/gala-core-sdk 1.1.0-beta.3 → 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
@@ -103,9 +103,22 @@ back, signed natively by a `GalaChainSigner`. A `RequestTokenBridgeOut` (the bri
103
103
  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
- signature covers it; `buildBridgeOutPayload` does this. The bridge contract's entry in the operation table
107
- is kept for `BridgeTokenOut`, which stage has not yet been seen to accept or refuse (UNVERIFIED); the SDK
108
- signs nothing under it.
106
+ signature covers it; `buildBridgeOutPayload` does this. The wrap / unwrap request carries no `wrap` field:
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
117
+ signs none of them): `BridgeTokenOut` on `/asset/bridge-contract` is
118
+ `asset-channel_bridge-chaincode_BridgeContract:BridgeTokenOut` (the operation table's bridge-contract entry
119
+ is right for it), and the grants embedded in a `BridgeTokenOut` sign
120
+ `asset-channel_bridge-chaincode_GalaChainToken:GrantAllowance`, which is NOT in the platform's operation
121
+ table.
109
122
 
110
123
  TypeScript: the `./bridge` declarations name `@solana/web3.js` types, whose own declarations import
111
124
  Node's `http` and `https`, so a TypeScript app that imports `./bridge` has `@types/node` (with
@@ -287,7 +300,7 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
287
300
 
288
301
  ## Status
289
302
 
290
- <!-- docs:var version -->1.1.0-beta.3<!-- /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()`;
291
304
  rc.5: every Ethereum account a read, write or GalaConnect client sends is
292
305
  `eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
293
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.
@@ -2234,8 +2276,9 @@ const BRIDGE_OUT_METHOD = "RequestTokenBridgeOut";
2234
2276
  * (`asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut`). Verified on stage (2026-11-02): the
2235
2277
  * chain refuses `...BridgeContract:RequestTokenBridgeOut` ("signed to call ...BridgeContract:RequestTokenBridgeOut,
2236
2278
  * but the current operation is asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut") and accepts this one.
2237
- * The table's `asset/bridge-contract` entry is kept for `BridgeTokenOut`, which stage has not yet been seen to accept
2238
- * or refuse: it is UNVERIFIED and nothing here signs it.
2279
+ * The table's `asset/bridge-contract` entry is right for `BridgeTokenOut` (seen live on stage:
2280
+ * `asset-channel_bridge-chaincode_BridgeContract:BridgeTokenOut`, signed by GalaConnect, not by this SDK), and the grants
2281
+ * embedded in it sign `asset-channel_bridge-chaincode_GalaChainToken:GrantAllowance`, which the table lacks.
2239
2282
  */
2240
2283
  const BRIDGE_OUT_CONTRACT_PATH = "asset/token-contract";
2241
2284
  /**
@@ -4640,8 +4683,11 @@ var WrappableTokenService = class {
4640
4683
  * Wrap Service
4641
4684
  *
4642
4685
  * Cross-channel wrap (a token from its own channel to the asset channel, e.g. MUSIC → GMUSIC) and
4643
- * unwrap (back), through GalaConnect: the natively signed `RequestTokenBridgeOut`, then
4644
- * `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).
4645
4691
  *
4646
4692
  * A wrap or unwrap that does not complete throws (nothing is returned as a "failed" result):
4647
4693
  * before anything is sent, the refusal of the input (`TOKEN_NOT_WRAPPABLE`,
@@ -4660,6 +4706,11 @@ const CHANNEL_IDS = {
4660
4706
  [ASSET_CHANNEL]: GALACHAIN_CHANNELS.ASSET,
4661
4707
  music: GALACHAIN_CHANNELS.MUSIC
4662
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
+ };
4663
4714
  /** The prefix of a wrap or unwrap uniqueKey. */
4664
4715
  const WRAP_UNIQUE_KEY_PREFIX = "galaswap-operation-";
4665
4716
  /**
@@ -4788,11 +4839,10 @@ var WrapService = class {
4788
4839
  },
4789
4840
  destinationChainId: routing.destinationChannelId,
4790
4841
  recipient,
4791
- wrap: true,
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,