@gala-chain/gala-core-sdk 1.1.0-beta.1 → 1.1.0-beta.3

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
@@ -99,9 +99,13 @@ bridge-out request was accepted the tokens may be locked: a later failure is
99
99
  `BRIDGE_OUT_OUTCOME_UNKNOWN` (with the step, the bridge request id and the `uniqueKey`), and a
100
100
  deposit that may have been sent is `BRIDGE_DEPOSIT_OUTCOME_UNKNOWN`; neither is ever retried by the
101
101
  SDK. `WrapService` wraps a token from its own channel to the asset channel (MUSIC to GMUSIC) and
102
- back, signed natively by a `GalaChainSigner`. The bridge-out request signs the bridge contract's
103
- `dtoOperation` (`asset-channel_bridge-chaincode_BridgeContract:RequestTokenBridgeOut`) as a field of its
104
- EIP-712 `GalaTransaction` type, so the signature covers it; `buildBridgeOutPayload` does this.
102
+ back, signed natively by a `GalaChainSigner`. A `RequestTokenBridgeOut` (the bridge-out and the wrap /
103
+ unwrap) signs the TOKEN contract's `dtoOperation`
104
+ (`asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut`, not the bridge contract's, which the
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.
105
109
 
106
110
  TypeScript: the `./bridge` declarations name `@solana/web3.js` types, whose own declarations import
107
111
  Node's `http` and `https`, so a TypeScript app that imports `./bridge` has `@types/node` (with
@@ -199,7 +203,14 @@ await writes.lockTokens({ tokens: [{ tokenClassKey: 'GALA|Unit|none|none', quant
199
203
  route's `<channel>/<contract>`, such as `asset/token-contract`) or `signPreSend(signer,
200
204
  contractPath, method, dto)`, which sets it and signs; a DTO that already names a different
201
205
  operation is refused as `SIGNING_FAILED`. Never add it after signing: the signature would not
202
- cover it.
206
+ cover it. Inside a launchpad bundle the operation is the bundler's `BatchSubmit`
207
+ (`asset-channel_basic-asset_Launchpad:BatchSubmit`), not the inner DTO's own method: launchpad-sdk sets it.
208
+ - Typed data (`BrowserWalletSigner` with `{ scheme: 'eip712' }`, and the `./bridge` bridge-out) is signed under
209
+ an EIP-712 domain whose NAME the deployment must accept: the stage chain refuses anything but its own
210
+ ("EIP-712 domain name must be GalaChainStage for this deployment."). Pass
211
+ `GALA_CHAIN_ENVIRONMENTS[env].eip712DomainName` (`GalaChainStage` on stage; absent on prod, where a signer
212
+ keeps the name it always signed: `ethereum`, and `GalaConnect` for the bridge) as the signer's `eip712DomainName`;
213
+ `BridgeService` takes the environment's by itself. The chain id stays the wallet's live one.
203
214
  - GalaChain's `Status` is checked before anything else is trusted; a timeout or broken connection is
204
215
  `GATEWAY_WRITE_OUTCOME_UNKNOWN`: the write may have been applied, so check its `uniqueKey` and
205
216
  never resend it under a fresh key.
@@ -276,7 +287,7 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
276
287
 
277
288
  ## Status
278
289
 
279
- <!-- docs:var version -->1.1.0-beta.1<!-- /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()`;
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()`;
280
291
  rc.5: every Ethereum account a read, write or GalaConnect client sends is
281
292
  `eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
282
293
  `bridgeableTokenService` is required). In: signing, signers, transport and the error model (rc.0, from gswap-sdk); the
package/dist/bridge.cjs CHANGED
@@ -67,6 +67,17 @@ const GALA_BRIDGE_TYPED_DATA_DOMAIN = {
67
67
  chainId: 1
68
68
  };
69
69
  /**
70
+ * The bridge-out typed data domain for a deployment: {@link GALA_BRIDGE_TYPED_DATA_DOMAIN}, or the
71
+ * same domain under the name the deployment's chain requires
72
+ * (`GALA_CHAIN_ENVIRONMENTS[env].eip712DomainName`, `GalaChainStage` on stage).
73
+ */
74
+ function galaBridgeTypedDataDomain(name) {
75
+ return name === void 0 ? GALA_BRIDGE_TYPED_DATA_DOMAIN : {
76
+ name,
77
+ chainId: 1
78
+ };
79
+ }
80
+ /**
70
81
  * Common GalaTransaction fields (identical in both schemas)
71
82
  */
72
83
  const GALA_TRANSACTION_TYPE = [
@@ -2219,15 +2230,24 @@ function destinationChainIdOf(value) {
2219
2230
  /** The method a bridge-out signing failure names. */
2220
2231
  const BRIDGE_OUT_METHOD = "RequestTokenBridgeOut";
2221
2232
  /**
2233
+ * The contract path whose operation a `RequestTokenBridgeOut` signs: the TOKEN contract's
2234
+ * (`asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut`). Verified on stage (2026-11-02): the
2235
+ * chain refuses `...BridgeContract:RequestTokenBridgeOut` ("signed to call ...BridgeContract:RequestTokenBridgeOut,
2236
+ * 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.
2239
+ */
2240
+ const BRIDGE_OUT_CONTRACT_PATH = "asset/token-contract";
2241
+ /**
2222
2242
  * Signs the bridge-out typed data with the app's signer. Whatever the signer throws that is not
2223
2243
  * already an SDK error (a declined or locked wallet, a message ethers cannot encode) is
2224
2244
  * `SIGNING_FAILED` (`user_rejected` or `failed`, the original as `cause`), and so is a signature
2225
2245
  * that is not a string: nothing was sent, so a retry is safe.
2226
2246
  */
2227
- async function signBridgeOut(wallet, types, message) {
2247
+ async function signBridgeOut(wallet, domain, types, message) {
2228
2248
  let signature;
2229
2249
  try {
2230
- signature = await wallet.signTypedData(GALA_BRIDGE_TYPED_DATA_DOMAIN, types, message);
2250
+ signature = await wallet.signTypedData(domain, types, message);
2231
2251
  } catch (cause) {
2232
2252
  if ((0, _gala_chain_gala_core_sdk.isGalaError)(cause)) throw cause;
2233
2253
  throw new _gala_chain_gala_core_sdk.GalaSDKError("SIGNING_FAILED", {
@@ -2278,16 +2298,17 @@ async function buildBridgeOutPayload(dto, config) {
2278
2298
  const message = {
2279
2299
  destinationChainId,
2280
2300
  destinationChainTxFee: sanitizeObject(sanitizedFeeObj),
2281
- dtoOperation: (0, _gala_chain_gala_core_sdk.dtoOperationOf)("asset/bridge-contract", BRIDGE_OUT_METHOD),
2301
+ dtoOperation: (0, _gala_chain_gala_core_sdk.dtoOperationOf)(BRIDGE_OUT_CONTRACT_PATH, BRIDGE_OUT_METHOD),
2282
2302
  quantity: dto.quantity,
2283
2303
  recipient: dto.recipient,
2284
2304
  tokenInstance: dto.tokenInstance,
2285
2305
  uniqueKey
2286
2306
  };
2287
2307
  const typedDataTypes = getGalaBridgeTypedDataTypes(hasCrossRate);
2288
- const signature = await signBridgeOut(wallet, typedDataTypes, message);
2308
+ const domain = galaBridgeTypedDataDomain(config.eip712DomainName);
2309
+ const signature = await signBridgeOut(wallet, domain, typedDataTypes, message);
2289
2310
  const prefix = `\u0019Ethereum Signed Message:\n${(0, _gala_chain_gala_core_sdk.serialize)({
2290
- domain: GALA_BRIDGE_TYPED_DATA_DOMAIN,
2311
+ domain,
2291
2312
  message,
2292
2313
  primaryType: "GalaTransaction",
2293
2314
  types: typedDataTypes
@@ -2297,7 +2318,7 @@ async function buildBridgeOutPayload(dto, config) {
2297
2318
  signature,
2298
2319
  prefix,
2299
2320
  types: typedDataTypes,
2300
- domain: GALA_BRIDGE_TYPED_DATA_DOMAIN
2321
+ domain
2301
2322
  };
2302
2323
  }
2303
2324
 
@@ -2362,7 +2383,7 @@ async function completeBridgeOut(galaConnectClient, requestResponse, uniqueKey,
2362
2383
  */
2363
2384
  async function executeBridgeOutFlow(params, config) {
2364
2385
  const { amount, recipientAddress, tokenSymbol: resolvedSymbol } = params;
2365
- const { galaConnectClient, tokenMetadataResolver, ethereumWallet, destinationChainId, destinationChain, validateRecipientAddress } = config;
2386
+ const { galaConnectClient, tokenMetadataResolver, ethereumWallet, eip712DomainName, destinationChainId, destinationChain, validateRecipientAddress } = config;
2366
2387
  const tokenSymbol = assertTokenSymbolResolved(resolvedSymbol);
2367
2388
  validateBridgeAmount(amount);
2368
2389
  validateRecipientAddress(recipientAddress, "recipient");
@@ -2378,7 +2399,10 @@ async function executeBridgeOutFlow(params, config) {
2378
2399
  recipientAddress,
2379
2400
  tokenDescriptor: metadata.descriptor
2380
2401
  });
2381
- const signedPayload = await buildBridgeOutPayload(dtoPayload, { wallet: ethereumWallet });
2402
+ const signedPayload = await buildBridgeOutPayload(dtoPayload, {
2403
+ wallet: ethereumWallet,
2404
+ eip712DomainName
2405
+ });
2382
2406
  const requestResponse = await galaConnectClient.requestBridgeOut(signedPayload);
2383
2407
  assertRequestAccepted("RequestTokenBridgeOut", requestResponse, signedPayload.uniqueKey);
2384
2408
  const transactionHash = await completeBridgeOut(galaConnectClient, requestResponse, signedPayload.uniqueKey, "asset", extractBridgeOutTransactionHash);
@@ -2845,6 +2869,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
2845
2869
  ethereumBridgeContract;
2846
2870
  ethereumWalletAddress;
2847
2871
  tokenMetadataResolver;
2872
+ eip712DomainName;
2848
2873
  /**
2849
2874
  * Creates a new Ethereum bridge strategy.
2850
2875
  *
@@ -2863,6 +2888,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
2863
2888
  const rpcUrl = assertHttpUrlOption(config.ethereumRpcUrl ?? "https://ethereum.publicnode.com", "ethereumRpcUrl");
2864
2889
  if (config.ethereumWalletAddress !== void 0) assertEthereumAddressOption(config.ethereumWalletAddress, "ethereumWalletAddress");
2865
2890
  this.ethereumProvider = new ethers.JsonRpcProvider(rpcUrl);
2891
+ this.eip712DomainName = config.eip712DomainName;
2866
2892
  this.ethereumWallet = new ethers.Wallet(config.ethereumPrivateKey, this.ethereumProvider);
2867
2893
  this.ethereumWalletAddress = config.ethereumWalletAddress ?? this.ethereumWallet.address;
2868
2894
  this.ethereumBridgeContract = ethereumBridgeContract;
@@ -2888,6 +2914,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
2888
2914
  galaConnectClient: this.galaConnectClient,
2889
2915
  tokenMetadataResolver: this.tokenMetadataResolver,
2890
2916
  ethereumWallet: this.ethereumWallet,
2917
+ eip712DomainName: this.eip712DomainName,
2891
2918
  destinationChainId: CHAIN_IDS.ETHEREUM,
2892
2919
  destinationChain: "Ethereum",
2893
2920
  validateRecipientAddress: validateEthereumAddressOrThrow
@@ -3249,6 +3276,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
3249
3276
  network = "Solana";
3250
3277
  galaChainWalletAddress;
3251
3278
  ethereumWallet;
3279
+ eip712DomainName;
3252
3280
  solanaConnection;
3253
3281
  solanaKeypair;
3254
3282
  solanaBridgeProgramId;
@@ -3272,6 +3300,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
3272
3300
  this.galaChainWalletAddress = config.galaChainWalletAddress;
3273
3301
  validateEthereumPrivateKeyFormat(config.ethereumPrivateKey);
3274
3302
  this.ethereumWallet = new ethers.Wallet(config.ethereumPrivateKey);
3303
+ this.eip712DomainName = config.eip712DomainName;
3275
3304
  const rpcUrl = assertHttpUrlOption(config.solanaRpcUrl ?? "https://api.mainnet-beta.solana.com", "solanaRpcUrl");
3276
3305
  this.solanaConnection = config.solanaConnection ?? new _solana_web3_js.Connection(rpcUrl, "confirmed");
3277
3306
  this.solanaKeypair = keypairFromBase58(config.solanaPrivateKeyBase58);
@@ -3301,6 +3330,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
3301
3330
  galaConnectClient: this.galaConnectClient,
3302
3331
  tokenMetadataResolver: this.tokenMetadataResolver,
3303
3332
  ethereumWallet: this.ethereumWallet,
3333
+ eip712DomainName: this.eip712DomainName,
3304
3334
  destinationChainId: CHAIN_IDS.SOLANA,
3305
3335
  destinationChain: "Solana",
3306
3336
  validateRecipientAddress: validateSolanaAddressOrThrow
@@ -3850,6 +3880,7 @@ var BridgeService = class {
3850
3880
  });
3851
3881
  this.bridgeableTokenService = config.bridgeableTokenService;
3852
3882
  const sleep = config.sleep !== void 0 ? { sleep: config.sleep } : {};
3883
+ const eip712DomainName = config.eip712DomainName ?? urls.eip712DomainName;
3853
3884
  this.strategies = /* @__PURE__ */ new Map([["Ethereum", new EthereumBridgeStrategy({
3854
3885
  galaConnectClient: this.galaConnectClient,
3855
3886
  galaChainWalletAddress,
@@ -3857,6 +3888,7 @@ var BridgeService = class {
3857
3888
  ethereumRpcUrl: config.ethereumRpcUrl ?? rpcUrls.ethereum,
3858
3889
  ethereumBridgeContract: config.ethereumBridgeContract ?? getEthereumBridgeContractByEnvironment(this.environment),
3859
3890
  tokenConfigs: getEthereumTokensByEnvironment(this.environment),
3891
+ eip712DomainName,
3860
3892
  ...sleep
3861
3893
  })]]);
3862
3894
  if (config.solanaPrivateKey !== void 0 && config.solanaPrivateKey !== "") this.strategies.set("Solana", new SolanaBridgeStrategy({
@@ -3867,6 +3899,7 @@ var BridgeService = class {
3867
3899
  solanaRpcUrl: config.solanaRpcUrl ?? rpcUrls.solana,
3868
3900
  solanaBridgeProgram: config.solanaBridgeProgram ?? "AaE4dTnL75XqgUJpdxBKg6vS9sTJgBPJwBQRVhD29WwS",
3869
3901
  tokenConfigs: DEFAULT_SOLANA_TOKENS,
3902
+ eip712DomainName,
3870
3903
  ...config.solanaConnection !== void 0 && { solanaConnection: config.solanaConnection },
3871
3904
  ...sleep
3872
3905
  }));
@@ -4758,7 +4791,7 @@ var WrapService = class {
4758
4791
  wrap: true,
4759
4792
  uniqueKey
4760
4793
  };
4761
- const requestBody = await (0, _gala_chain_gala_core_sdk.signPreSend)(this.signer, "asset/bridge-contract", "RequestTokenBridgeOut", message);
4794
+ const requestBody = await (0, _gala_chain_gala_core_sdk.signPreSend)(this.signer, BRIDGE_OUT_CONTRACT_PATH, "RequestTokenBridgeOut", message);
4762
4795
  const response = await this.galaConnectClient.requestBridgeOut(requestBody);
4763
4796
  assertRequestAccepted("RequestTokenBridgeOut", response, uniqueKey);
4764
4797
  return {
@@ -4892,6 +4925,7 @@ exports.createSolanaWallet = createSolanaWallet;
4892
4925
  exports.formatTokenAmount = formatTokenAmount;
4893
4926
  exports.formatTokenDescriptor = formatTokenDescriptor;
4894
4927
  exports.fromBaseUnits = fromBaseUnits;
4928
+ exports.galaBridgeTypedDataDomain = galaBridgeTypedDataDomain;
4895
4929
  exports.getEthereumBridgeContractByEnvironment = getEthereumBridgeContractByEnvironment;
4896
4930
  exports.getEthereumTokenConfig = getEthereumTokenConfig;
4897
4931
  exports.getEthereumTokensByEnvironment = getEthereumTokensByEnvironment;