@gala-chain/gala-core-sdk 1.1.0-beta.1 → 1.1.0-beta.2
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 +9 -2
- package/dist/bridge.cjs +32 -7
- package/dist/bridge.cjs.map +1 -1
- package/dist/bridge.d.cts +26 -0
- package/dist/bridge.d.ts +26 -0
- package/dist/bridge.mjs +32 -8
- package/dist/bridge.mjs.map +1 -1
- package/dist/browser/bridge.js +1 -1
- package/dist/browser/bridge.js.map +1 -1
- package/dist/browser/classes/signers.js +1 -1
- package/dist/browser/classes/signers.js.map +1 -1
- package/dist/browser/config/environments.js +1 -1
- package/dist/browser/config/environments.js.map +1 -1
- package/dist/browser/providers.js.map +1 -1
- package/dist/browser/utils/eip712.js +1 -1
- package/dist/browser/utils/eip712.js.map +1 -1
- package/dist/browser/utils/transport.js +1 -1
- package/dist/browser/version.js +1 -1
- package/dist/browser/version.js.map +1 -1
- package/dist/index.cjs +25 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.mjs +25 -8
- package/dist/index.mjs.map +1 -1
- package/dist/providers.cjs +2 -0
- package/dist/providers.cjs.map +1 -1
- package/dist/providers.d.cts +3 -0
- package/dist/providers.d.ts +3 -0
- package/dist/providers.mjs +2 -0
- package/dist/providers.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -199,7 +199,14 @@ await writes.lockTokens({ tokens: [{ tokenClassKey: 'GALA|Unit|none|none', quant
|
|
|
199
199
|
route's `<channel>/<contract>`, such as `asset/token-contract`) or `signPreSend(signer,
|
|
200
200
|
contractPath, method, dto)`, which sets it and signs; a DTO that already names a different
|
|
201
201
|
operation is refused as `SIGNING_FAILED`. Never add it after signing: the signature would not
|
|
202
|
-
cover it.
|
|
202
|
+
cover it. Inside a launchpad bundle the operation is the bundler's `BatchSubmit`
|
|
203
|
+
(`asset-channel_basic-asset_Launchpad:BatchSubmit`), not the inner DTO's own method: launchpad-sdk sets it.
|
|
204
|
+
- Typed data (`BrowserWalletSigner` with `{ scheme: 'eip712' }`, and the `./bridge` bridge-out) is signed under
|
|
205
|
+
an EIP-712 domain whose NAME the deployment must accept: the stage chain refuses anything but its own
|
|
206
|
+
("EIP-712 domain name must be GalaChainStage for this deployment."). Pass
|
|
207
|
+
`GALA_CHAIN_ENVIRONMENTS[env].eip712DomainName` (`GalaChainStage` on stage; absent on prod, where a signer
|
|
208
|
+
keeps the name it always signed: `ethereum`, and `GalaConnect` for the bridge) as the signer's `eip712DomainName`;
|
|
209
|
+
`BridgeService` takes the environment's by itself. The chain id stays the wallet's live one.
|
|
203
210
|
- GalaChain's `Status` is checked before anything else is trusted; a timeout or broken connection is
|
|
204
211
|
`GATEWAY_WRITE_OUTCOME_UNKNOWN`: the write may have been applied, so check its `uniqueKey` and
|
|
205
212
|
never resend it under a fresh key.
|
|
@@ -276,7 +283,7 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
|
|
|
276
283
|
|
|
277
284
|
## Status
|
|
278
285
|
|
|
279
|
-
<!-- docs:var version -->1.1.0-beta.
|
|
286
|
+
<!-- docs:var version -->1.1.0-beta.2<!-- /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
287
|
rc.5: every Ethereum account a read, write or GalaConnect client sends is
|
|
281
288
|
`eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
|
|
282
289
|
`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 = [
|
|
@@ -2224,10 +2235,10 @@ const BRIDGE_OUT_METHOD = "RequestTokenBridgeOut";
|
|
|
2224
2235
|
* `SIGNING_FAILED` (`user_rejected` or `failed`, the original as `cause`), and so is a signature
|
|
2225
2236
|
* that is not a string: nothing was sent, so a retry is safe.
|
|
2226
2237
|
*/
|
|
2227
|
-
async function signBridgeOut(wallet, types, message) {
|
|
2238
|
+
async function signBridgeOut(wallet, domain, types, message) {
|
|
2228
2239
|
let signature;
|
|
2229
2240
|
try {
|
|
2230
|
-
signature = await wallet.signTypedData(
|
|
2241
|
+
signature = await wallet.signTypedData(domain, types, message);
|
|
2231
2242
|
} catch (cause) {
|
|
2232
2243
|
if ((0, _gala_chain_gala_core_sdk.isGalaError)(cause)) throw cause;
|
|
2233
2244
|
throw new _gala_chain_gala_core_sdk.GalaSDKError("SIGNING_FAILED", {
|
|
@@ -2285,9 +2296,10 @@ async function buildBridgeOutPayload(dto, config) {
|
|
|
2285
2296
|
uniqueKey
|
|
2286
2297
|
};
|
|
2287
2298
|
const typedDataTypes = getGalaBridgeTypedDataTypes(hasCrossRate);
|
|
2288
|
-
const
|
|
2299
|
+
const domain = galaBridgeTypedDataDomain(config.eip712DomainName);
|
|
2300
|
+
const signature = await signBridgeOut(wallet, domain, typedDataTypes, message);
|
|
2289
2301
|
const prefix = `\u0019Ethereum Signed Message:\n${(0, _gala_chain_gala_core_sdk.serialize)({
|
|
2290
|
-
domain
|
|
2302
|
+
domain,
|
|
2291
2303
|
message,
|
|
2292
2304
|
primaryType: "GalaTransaction",
|
|
2293
2305
|
types: typedDataTypes
|
|
@@ -2297,7 +2309,7 @@ async function buildBridgeOutPayload(dto, config) {
|
|
|
2297
2309
|
signature,
|
|
2298
2310
|
prefix,
|
|
2299
2311
|
types: typedDataTypes,
|
|
2300
|
-
domain
|
|
2312
|
+
domain
|
|
2301
2313
|
};
|
|
2302
2314
|
}
|
|
2303
2315
|
|
|
@@ -2362,7 +2374,7 @@ async function completeBridgeOut(galaConnectClient, requestResponse, uniqueKey,
|
|
|
2362
2374
|
*/
|
|
2363
2375
|
async function executeBridgeOutFlow(params, config) {
|
|
2364
2376
|
const { amount, recipientAddress, tokenSymbol: resolvedSymbol } = params;
|
|
2365
|
-
const { galaConnectClient, tokenMetadataResolver, ethereumWallet, destinationChainId, destinationChain, validateRecipientAddress } = config;
|
|
2377
|
+
const { galaConnectClient, tokenMetadataResolver, ethereumWallet, eip712DomainName, destinationChainId, destinationChain, validateRecipientAddress } = config;
|
|
2366
2378
|
const tokenSymbol = assertTokenSymbolResolved(resolvedSymbol);
|
|
2367
2379
|
validateBridgeAmount(amount);
|
|
2368
2380
|
validateRecipientAddress(recipientAddress, "recipient");
|
|
@@ -2378,7 +2390,10 @@ async function executeBridgeOutFlow(params, config) {
|
|
|
2378
2390
|
recipientAddress,
|
|
2379
2391
|
tokenDescriptor: metadata.descriptor
|
|
2380
2392
|
});
|
|
2381
|
-
const signedPayload = await buildBridgeOutPayload(dtoPayload, {
|
|
2393
|
+
const signedPayload = await buildBridgeOutPayload(dtoPayload, {
|
|
2394
|
+
wallet: ethereumWallet,
|
|
2395
|
+
eip712DomainName
|
|
2396
|
+
});
|
|
2382
2397
|
const requestResponse = await galaConnectClient.requestBridgeOut(signedPayload);
|
|
2383
2398
|
assertRequestAccepted("RequestTokenBridgeOut", requestResponse, signedPayload.uniqueKey);
|
|
2384
2399
|
const transactionHash = await completeBridgeOut(galaConnectClient, requestResponse, signedPayload.uniqueKey, "asset", extractBridgeOutTransactionHash);
|
|
@@ -2845,6 +2860,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
|
|
|
2845
2860
|
ethereumBridgeContract;
|
|
2846
2861
|
ethereumWalletAddress;
|
|
2847
2862
|
tokenMetadataResolver;
|
|
2863
|
+
eip712DomainName;
|
|
2848
2864
|
/**
|
|
2849
2865
|
* Creates a new Ethereum bridge strategy.
|
|
2850
2866
|
*
|
|
@@ -2863,6 +2879,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
|
|
|
2863
2879
|
const rpcUrl = assertHttpUrlOption(config.ethereumRpcUrl ?? "https://ethereum.publicnode.com", "ethereumRpcUrl");
|
|
2864
2880
|
if (config.ethereumWalletAddress !== void 0) assertEthereumAddressOption(config.ethereumWalletAddress, "ethereumWalletAddress");
|
|
2865
2881
|
this.ethereumProvider = new ethers.JsonRpcProvider(rpcUrl);
|
|
2882
|
+
this.eip712DomainName = config.eip712DomainName;
|
|
2866
2883
|
this.ethereumWallet = new ethers.Wallet(config.ethereumPrivateKey, this.ethereumProvider);
|
|
2867
2884
|
this.ethereumWalletAddress = config.ethereumWalletAddress ?? this.ethereumWallet.address;
|
|
2868
2885
|
this.ethereumBridgeContract = ethereumBridgeContract;
|
|
@@ -2888,6 +2905,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
|
|
|
2888
2905
|
galaConnectClient: this.galaConnectClient,
|
|
2889
2906
|
tokenMetadataResolver: this.tokenMetadataResolver,
|
|
2890
2907
|
ethereumWallet: this.ethereumWallet,
|
|
2908
|
+
eip712DomainName: this.eip712DomainName,
|
|
2891
2909
|
destinationChainId: CHAIN_IDS.ETHEREUM,
|
|
2892
2910
|
destinationChain: "Ethereum",
|
|
2893
2911
|
validateRecipientAddress: validateEthereumAddressOrThrow
|
|
@@ -3249,6 +3267,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
|
|
|
3249
3267
|
network = "Solana";
|
|
3250
3268
|
galaChainWalletAddress;
|
|
3251
3269
|
ethereumWallet;
|
|
3270
|
+
eip712DomainName;
|
|
3252
3271
|
solanaConnection;
|
|
3253
3272
|
solanaKeypair;
|
|
3254
3273
|
solanaBridgeProgramId;
|
|
@@ -3272,6 +3291,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
|
|
|
3272
3291
|
this.galaChainWalletAddress = config.galaChainWalletAddress;
|
|
3273
3292
|
validateEthereumPrivateKeyFormat(config.ethereumPrivateKey);
|
|
3274
3293
|
this.ethereumWallet = new ethers.Wallet(config.ethereumPrivateKey);
|
|
3294
|
+
this.eip712DomainName = config.eip712DomainName;
|
|
3275
3295
|
const rpcUrl = assertHttpUrlOption(config.solanaRpcUrl ?? "https://api.mainnet-beta.solana.com", "solanaRpcUrl");
|
|
3276
3296
|
this.solanaConnection = config.solanaConnection ?? new _solana_web3_js.Connection(rpcUrl, "confirmed");
|
|
3277
3297
|
this.solanaKeypair = keypairFromBase58(config.solanaPrivateKeyBase58);
|
|
@@ -3301,6 +3321,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
|
|
|
3301
3321
|
galaConnectClient: this.galaConnectClient,
|
|
3302
3322
|
tokenMetadataResolver: this.tokenMetadataResolver,
|
|
3303
3323
|
ethereumWallet: this.ethereumWallet,
|
|
3324
|
+
eip712DomainName: this.eip712DomainName,
|
|
3304
3325
|
destinationChainId: CHAIN_IDS.SOLANA,
|
|
3305
3326
|
destinationChain: "Solana",
|
|
3306
3327
|
validateRecipientAddress: validateSolanaAddressOrThrow
|
|
@@ -3850,6 +3871,7 @@ var BridgeService = class {
|
|
|
3850
3871
|
});
|
|
3851
3872
|
this.bridgeableTokenService = config.bridgeableTokenService;
|
|
3852
3873
|
const sleep = config.sleep !== void 0 ? { sleep: config.sleep } : {};
|
|
3874
|
+
const eip712DomainName = config.eip712DomainName ?? urls.eip712DomainName;
|
|
3853
3875
|
this.strategies = /* @__PURE__ */ new Map([["Ethereum", new EthereumBridgeStrategy({
|
|
3854
3876
|
galaConnectClient: this.galaConnectClient,
|
|
3855
3877
|
galaChainWalletAddress,
|
|
@@ -3857,6 +3879,7 @@ var BridgeService = class {
|
|
|
3857
3879
|
ethereumRpcUrl: config.ethereumRpcUrl ?? rpcUrls.ethereum,
|
|
3858
3880
|
ethereumBridgeContract: config.ethereumBridgeContract ?? getEthereumBridgeContractByEnvironment(this.environment),
|
|
3859
3881
|
tokenConfigs: getEthereumTokensByEnvironment(this.environment),
|
|
3882
|
+
eip712DomainName,
|
|
3860
3883
|
...sleep
|
|
3861
3884
|
})]]);
|
|
3862
3885
|
if (config.solanaPrivateKey !== void 0 && config.solanaPrivateKey !== "") this.strategies.set("Solana", new SolanaBridgeStrategy({
|
|
@@ -3867,6 +3890,7 @@ var BridgeService = class {
|
|
|
3867
3890
|
solanaRpcUrl: config.solanaRpcUrl ?? rpcUrls.solana,
|
|
3868
3891
|
solanaBridgeProgram: config.solanaBridgeProgram ?? "AaE4dTnL75XqgUJpdxBKg6vS9sTJgBPJwBQRVhD29WwS",
|
|
3869
3892
|
tokenConfigs: DEFAULT_SOLANA_TOKENS,
|
|
3893
|
+
eip712DomainName,
|
|
3870
3894
|
...config.solanaConnection !== void 0 && { solanaConnection: config.solanaConnection },
|
|
3871
3895
|
...sleep
|
|
3872
3896
|
}));
|
|
@@ -4892,6 +4916,7 @@ exports.createSolanaWallet = createSolanaWallet;
|
|
|
4892
4916
|
exports.formatTokenAmount = formatTokenAmount;
|
|
4893
4917
|
exports.formatTokenDescriptor = formatTokenDescriptor;
|
|
4894
4918
|
exports.fromBaseUnits = fromBaseUnits;
|
|
4919
|
+
exports.galaBridgeTypedDataDomain = galaBridgeTypedDataDomain;
|
|
4895
4920
|
exports.getEthereumBridgeContractByEnvironment = getEthereumBridgeContractByEnvironment;
|
|
4896
4921
|
exports.getEthereumTokenConfig = getEthereumTokenConfig;
|
|
4897
4922
|
exports.getEthereumTokensByEnvironment = getEthereumTokensByEnvironment;
|