@gala-chain/gala-core-sdk 1.0.0-rc.4 → 1.0.0-rc.6

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.
Files changed (47) hide show
  1. package/README.md +17 -8
  2. package/dist/bridge.cjs +15 -48
  3. package/dist/bridge.cjs.map +1 -1
  4. package/dist/bridge.d.cts +10 -3
  5. package/dist/bridge.d.ts +10 -3
  6. package/dist/bridge.mjs +13 -47
  7. package/dist/bridge.mjs.map +1 -1
  8. package/dist/browser/bridge.js +1 -1
  9. package/dist/browser/bridge.js.map +1 -1
  10. package/dist/browser/index.js +1 -1
  11. package/dist/browser/providers.js +1 -1
  12. package/dist/browser/providers.js.map +1 -1
  13. package/dist/browser/react.js +1 -1
  14. package/dist/browser/react.js.map +1 -1
  15. package/dist/browser/reads/gateway_reads.js +1 -1
  16. package/dist/browser/reads/gateway_reads.js.map +1 -1
  17. package/dist/browser/reads/parse.js +1 -1
  18. package/dist/browser/reads/parse.js.map +1 -1
  19. package/dist/browser/reads/request.js +1 -1
  20. package/dist/browser/reads/request.js.map +1 -1
  21. package/dist/browser/reads/types.js +1 -1
  22. package/dist/browser/reads/types.js.map +1 -1
  23. package/dist/browser/utils/transport.js +1 -1
  24. package/dist/browser/version.js +1 -1
  25. package/dist/browser/version.js.map +1 -1
  26. package/dist/browser/writes/identity.js +1 -1
  27. package/dist/browser/writes/identity.js.map +1 -1
  28. package/dist/browser/writes/types.js.map +1 -1
  29. package/dist/index.cjs +94 -23
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +73 -12
  32. package/dist/index.d.ts +73 -12
  33. package/dist/index.mjs +94 -24
  34. package/dist/index.mjs.map +1 -1
  35. package/dist/providers.cjs +143 -6
  36. package/dist/providers.cjs.map +1 -1
  37. package/dist/providers.d.cts +63 -0
  38. package/dist/providers.d.ts +63 -0
  39. package/dist/providers.mjs +140 -7
  40. package/dist/providers.mjs.map +1 -1
  41. package/dist/react.cjs +58 -24
  42. package/dist/react.cjs.map +1 -1
  43. package/dist/react.d.cts +7 -1
  44. package/dist/react.d.ts +7 -1
  45. package/dist/react.mjs +58 -24
  46. package/dist/react.mjs.map +1 -1
  47. package/package.json +1 -1
package/README.md CHANGED
@@ -41,14 +41,15 @@ key.fill(0);
41
41
  | Signers | `PrivateKeySigner`, `createLazyPrivateKeySigner`, `GalaWalletSigner`, `BrowserWalletSigner`, `signPreSend`, type `GalaChainSigner` |
42
42
  | Signing | `serialize`, `getPayloadToSign`, `signNative`, `signPersonalMessage`, `personalSignPrefixFor`, `fixpointPrefixFor`, `signChainDto*`, `signRawObject`, `generateEIP712Types`, `buildEIP712Payload`, `hashTypedData`, `signTypedDataPayload` |
43
43
  | Transport | `fetchRequestor`, `requestWithTimeout` (`kind: { write: false }` makes a read's timeout and transport failure say `write: false`), `buildRequestHeaders`, `buildQueryString`, `readRetryAfter`, `httpRequestorFromAxios`, `eip1193ProviderFromEthers`, `isFetchTransportFailure`, types `HttpRequestor`, `WireOptions`, `RequestKind` |
44
- | Gateway writes | `GatewayWrites` (`transferGala`, `transferToken`, `burnTokens`, `lockTokens`, `unlockTokens`), `GATEWAY_WRITE_METHODS`, `GATEWAY_WRITE_BATCH_LIMITS`, `GALA_TOKEN_CLASS_KEY`, types `GatewayWritesOptions`, `GatewayWriteReceipt`, `TokenNameResolver`, `TokenQuantityInput` |
45
- | Gateway reads | `GatewayReads` (`fetchBalances`, `fetchTokenBalance`, `fetchNftBalances`, `fetchTokenClasses`, `fetchTokenClassesWithSupply`, `fetchTokenClass`, `fetchTokenDetails`, `fetchTokenClassesPage`, `fetchAllTokenClasses`, `fetchNftCollectionAuthorizationsPage`, `fetchAllNftCollectionAuthorizations`), `GATEWAY_READ_METHODS`, `GATEWAY_READ_LIMITS`, types `GalaChainTokenBalance`, `GalaChainTokenBalanceSummary`, `GalaChainTokenClass`, `GalaChainTokenDetails`, `GalaChainPage` |
44
+ | Gateway reads | `GatewayReads` (`fetchBalances`, `fetchTokenBalance`, `fetchNftBalances`, `fetchTokenClasses`, `fetchTokenClassesWithSupply`, `fetchTokenClass`, `fetchTokenDetails`, `fetchTokenClassesPage`, `fetchAllTokenClasses`, `fetchNftCollectionAuthorizationsPage`, `fetchAllNftCollectionAuthorizations`, `fetchPublicKey`), `GATEWAY_READ_METHODS`, `GATEWAY_READ_LIMITS`, types `GalaChainTokenBalance`, `GalaChainTokenBalanceSummary`, `GalaChainTokenClass`, `GalaChainTokenDetails`, `GalaChainPage`, `GalaChainPublicKey` |
45
+ | Gateway writes | `GatewayWrites` (`transferGala`, `transferToken`, `burnTokens`, `lockTokens`, `unlockTokens`), `galaChainUserRef` (a user reference in the one spelling the gateway accepts), `GATEWAY_WRITE_METHODS`, `GATEWAY_WRITE_BATCH_LIMITS`, `GALA_TOKEN_CLASS_KEY`, types `GatewayWritesOptions`, `GatewayWriteReceipt`, `TokenNameResolver`, `TokenQuantityInput` |
46
+ | Gateway reads | `GatewayReads` (`fetchBalances`, `fetchTokenBalance`, `fetchNftBalances`, `fetchTokenClasses`, `fetchTokenClassesWithSupply`, `fetchTokenClass`, `fetchTokenDetails`, `fetchTokenClassesPage`, `fetchAllTokenClasses`, `fetchNftCollectionAuthorizationsPage`, `fetchAllNftCollectionAuthorizations`, `fetchPublicKey`), `GATEWAY_READ_METHODS`, `GATEWAY_READ_LIMITS`, types `GalaChainTokenBalance`, `GalaChainTokenBalanceSummary`, `GalaChainTokenClass`, `GalaChainTokenDetails`, `GalaChainPage`, `GalaChainPublicKey` |
46
47
  | Deployments | `GALA_CHAIN_ENVIRONMENTS` (gateway and DEX API of `prod` / `stage`) |
47
48
  | Keys | `compositeKeyOf`, `tryParseTokenClassKey`, `tryParseCompositeKey`, `createUniqueKey`, `assertUniqueKey`, `isValidUniqueKey` |
48
49
  | Wallets | `createWallet` (random, from a private key, or from a 12/24-word mnemonic at `m/44'/60'/0'/0/0`), `validateWalletInput`, `getPublicKeyFromPrivateKey`, `getEthereumAddressFromPrivateKey`, `checksumEthereumAddress`, types `GeneratedWallet`, `PublicKeyResult` |
49
50
  | Errors | `GalaSDKError`, `isGalaError`, `GALA_ERROR_CATALOG`, `galaErrorTemplates`, `GALA_ERROR_PHASE_BY_CODE`, `toFailureView`, `isWriteView`, `FAILURE_OUTCOMES` |
50
51
  | Wallet helpers (`./wallet`) | `isWalletUserRejection`, `walletDeclineCode`, `isGalaErrorLike` |
51
- | Wallet providers (`./providers`) | `PrivateKeyProvider`, `ExternalWalletProvider`, `GalaWalletProvider`, `detectWallets`, `subscribeToWalletChanges`, `getWalletByRdns`, `isWalletAvailable`, `hasAnyWallet`, `getInjectedEip1193Provider`, `KNOWN_WALLET_RDNS`, `createWalletProvider`, `createProviderFromEip1193`, `ensureConnected`, `getPrivateKeyIfAvailable`, `isPrivateKeyProvider`, `isExternalProvider`, `isEip1193Provider`, type `WalletProvider` |
52
+ | Wallet providers (`./providers`) | `PrivateKeyProvider`, `ExternalWalletProvider`, `GalaWalletProvider`, `detectWallets`, `subscribeToWalletChanges`, `getWalletByRdns`, `isWalletAvailable`, `findMetaMaskWallet`, `getMetaMaskWallet`, `findTrustWallet`, `getTrustWallet`, `hasAnyWallet`, `getInjectedEip1193Provider`, `KNOWN_WALLET_RDNS`, `createWalletProvider`, `createProviderFromEip1193`, `ensureConnected`, `getPrivateKeyIfAvailable`, `isPrivateKeyProvider`, `isExternalProvider`, `isEip1193Provider`, type `WalletProvider` |
52
53
  | React (`./react`) | `WalletProvider` (context component), `WalletContext`, `useWallet`, `useWalletContext`, `useWalletConnection`, `useWalletDetection`, `useWalletAddress`, `useGalaAddress`, `useWalletProvider`, `useIsWalletConnected` |
53
54
  | Bridge (`./bridge`) | `BridgeService` (bridge out to and in from Ethereum and Solana, fees, status, external balances), `EthereumBridgeStrategy`, `SolanaBridgeStrategy`, `BaseBridgeStrategy`, `GalaConnectClient`, `BridgeableTokenService`, `WrappableTokenService`, `WrapService` (channel wrap / unwrap), `createSolanaWallet`, `buildBridgeOutPayload` (the signed bridge-out request), the bridge constants and token tables, the bridge types, `RateLimiter`, the token amount helpers (`toBaseUnits`, `fromBaseUnits`, `formatTokenAmount`, `compareAmounts`) |
54
55
 
@@ -172,8 +173,9 @@ await writes.lockTokens({ tokens: [{ tokenClassKey: 'GALA|Unit|none|none', quant
172
173
  - Tokens: `tokenClassKey` (`collection|category|type|additionalKey` with exactly four parts, the
173
174
  `$` composite key, or the object) plus `instance` (default `"0"`), or `tokenName` through an
174
175
  optional `tokenNameResolver`. A bare symbol is never a class key.
175
- - Identities (`to`, `walletAddress`, `lockAuthority`): `eth|<40 hex>` and `client|<id>` as written,
176
- `0x<40 hex>` as checksummed `eth|`.
176
+ - Identities (`to`, `walletAddress`, `lockAuthority`): an Ethereum account (`eth|<40 hex>`,
177
+ `eth|0x<40 hex>`, `0x<40 hex>`, bare hex; any casing but a wrong EIP-55 checksum) is always sent
178
+ as `eth|<checksummed>`, the only spelling the gateway accepts; `client|<id>` is sent as written.
177
179
  - The signer is handed the bare DTO; the body sent is exactly the DTO plus the signature (a signer
178
180
  that adds or changes a field is refused). A `uniqueKey` is minted per write unless you pass one.
179
181
  - GalaChain's `Status` is checked before anything else is trusted; a timeout or broken connection is
@@ -196,14 +198,18 @@ const classes = await reads.fetchAllTokenClasses({ collection: 'BONKTactics' },
196
198
 
197
199
  - Reads are unsigned and apply nothing: every failure after the request left says so
198
200
  (`error.write === false`), and a retry is always safe.
199
- - Owners are spelled as the writes spell them (`eth|` / `client|` as written, `0x` as checksummed
200
- `eth|`); class keys are accepted in the same forms. `$MUSIC` balances are read on the gateway's
201
+ - Owners are spelled as the writes spell them (an Ethereum account in any form as
202
+ `eth|<checksummed>`, `client|` as written); class keys are accepted in the same forms. `$MUSIC` balances are read on the gateway's
201
203
  `music` channel.
202
204
  - Every answer is checked (GalaChain's `Status`, then each row) before it is returned; a balance of
203
205
  another owner than the one asked for is refused. Quantities stay the chain's whole-token decimal
204
206
  strings; hold totals are exact and never in exponent form.
205
207
  - A token class that does not exist is `TOKEN_CLASS_NOT_FOUND`; a `fetchAll...` read that would
206
208
  need more than `maxPages` pages is `PAGINATION_LIMIT_EXCEEDED` (never a truncated list).
209
+ - `fetchPublicKey(user)` reads the key GalaChain has registered for a user (`{ publicKey,
210
+ signing? }`, `undefined` when none is saved). The public gateways do not route the
211
+ public-key-contract; read it through a connect-api proxy:
212
+ `new GatewayReads({ gatewayBaseUrl: 'https://api-galaswap.gala.com/galachain' })`.
207
213
 
208
214
  ## Signing parity
209
215
 
@@ -245,7 +251,10 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
245
251
 
246
252
  ## Status
247
253
 
248
- 1.0.0-rc.4 (rc.4: `bridgeableTokenService` is required). In: signing, signers, transport and the error model (rc.0, from gswap-sdk); the
254
+ 1.0.0-rc.6 (rc.6: `fetchPublicKey`, MetaMask and Trust Wallet detection, silent `restore()`;
255
+ rc.5: every Ethereum account a read, write or GalaConnect client sends is
256
+ `eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
257
+ `bridgeableTokenService` is required). In: signing, signers, transport and the error model (rc.0, from gswap-sdk); the
249
258
  gateway token writes (rc.1, from launchpad-sdk's transfer and lock services, which now delegate
250
259
  here); the gateway token reads (rc.2: balances, token classes, NFT collection authorizations, from
251
260
  launchpad-sdk's balance and token services, which now delegate here) and the deployment endpoints;
package/dist/bridge.cjs CHANGED
@@ -1429,16 +1429,20 @@ var GalaConnectClient = class {
1429
1429
  /**
1430
1430
  * Creates a new GalaConnect client.
1431
1431
  *
1432
- * @param config - Client configuration (`httpRequestor` defaults to the global `fetch`)
1432
+ * @param config - Client configuration (`httpRequestor` defaults to the global `fetch`).
1433
+ * `walletAddress` is sent (the `X-Wallet-Address` header, the gateway balance read's `owner`)
1434
+ * in the gateway's spelling: an Ethereum account in any form as `eth|<checksummed>`, a `client|`
1435
+ * alias as written; `''` is a client with no wallet (the public token lists).
1433
1436
  * @throws GalaSDKError `INVALID_TIMEOUT` for a `requestTimeoutMs` that is not a positive number
1434
1437
  * of milliseconds or `Infinity`; `INVALID_BRIDGE_OPTION` (`baseUrl`, `galachainBaseUrl`) for a
1435
- * URL that is not http(s); (`requestsPerSecond`) for a rate that is not above zero
1438
+ * URL that is not http(s); (`requestsPerSecond`) for a rate that is not above zero;
1439
+ * `INVALID_WALLET_ADDRESS` (`walletAddress`) for a wallet address that is no user reference
1436
1440
  */
1437
1441
  constructor(config) {
1438
1442
  this.requestTimeoutMs = (0, _gala_chain_gala_core_sdk.validateTimeoutMs)(config.requestTimeoutMs ?? DEFAULT_CONFIG.requestTimeoutMs, "requestTimeoutMs");
1439
1443
  this.baseUrl = assertHttpUrlOption(config.baseUrl ?? DEFAULT_CONFIG.baseUrl, "baseUrl");
1440
1444
  this.galachainBaseUrl = assertHttpUrlOption(config.galachainBaseUrl ?? DEFAULT_CONFIG.galachainBaseUrl, "galachainBaseUrl");
1441
- this.walletAddress = config.walletAddress;
1445
+ this.walletAddress = config.walletAddress === "" ? "" : (0, _gala_chain_gala_core_sdk.galaChainUserRef)(config.walletAddress, "walletAddress");
1442
1446
  this.rateLimiter = new RateLimiter(config.requestsPerSecond ?? DEFAULT_CONFIG.requestsPerSecond);
1443
1447
  this.requestor = config.httpRequestor ?? ((url, init) => globalThis.fetch(url, init));
1444
1448
  this.defaultHeaders = {
@@ -1654,13 +1658,10 @@ var GalaConnectClient = class {
1654
1658
  /**
1655
1659
  * Address Validation Utilities
1656
1660
  *
1657
- * Shared functions for validating and normalizing blockchain addresses
1658
- * across different networks (Ethereum, Solana, GalaChain).
1661
+ * Shared functions for validating Ethereum addresses, keys and transaction hashes, and the bridge
1662
+ * token configuration lookups. A GalaChain user reference is spelled by the root's
1663
+ * `galaChainUserRef` (the one implementation the gateway reads, writes and the bridge share).
1659
1664
  */
1660
- /** `client|` plus letters, digits, `_` and `-`: a GalaChain user alias. */
1661
- const CLIENT_ADDRESS = /^client\|[a-zA-Z0-9_-]+$/u;
1662
- /** The 40 hex digits of `0x<40>`, `eth|<40>`, `eth|0x<40>` or `<40>`. */
1663
- const ACCOUNT_DIGITS = /^(?:0x|eth\|(?:0x)?)?([0-9a-fA-F]{40})$/u;
1664
1665
  /**
1665
1666
  * Validate Ethereum private key format.
1666
1667
  *
@@ -1697,40 +1698,6 @@ function isValidEthereumTransactionHash(hash) {
1697
1698
  return /^0x[a-fA-F0-9]{64}$/.test(hash);
1698
1699
  }
1699
1700
  /**
1700
- * Normalize a GalaChain address to the correct format: eth|{40-hex-checksummed}
1701
- *
1702
- * Handles various input formats:
1703
- * - client|{alias} → unchanged
1704
- * - eth|{40-hex}, eth|0x{40-hex} → eth|{40-hex-checksummed}
1705
- * - 0x{40-hex} → eth|{40-hex-checksummed}
1706
- * - {40-hex} → eth|{40-hex-checksummed}
1707
- *
1708
- * The digits may be all lower or all upper case, or the EIP-55 checksum casing; a mixed-case
1709
- * spelling whose casing is not the checksum is a typo (what EIP-55 exists to catch) and refused.
1710
- *
1711
- * @param address - Address in any supported format
1712
- * @param field - The field it is, named by the error (default `address`)
1713
- * @returns Normalized address as eth|{40-hex-checksummed}
1714
- * @throws GalaSDKError `INVALID_WALLET_ADDRESS` for any other form
1715
- *
1716
- * @example
1717
- * ```typescript
1718
- * normalizeGalaChainAddress('0x70997970c51812dc3a010c7d01b50e0d17dc79c8');
1719
- * // Returns: 'eth|70997970C51812dc3A010C7d01b50e0d17dc79C8'
1720
- * ```
1721
- */
1722
- function normalizeGalaChainAddress(address, field = "address") {
1723
- var _ACCOUNT_DIGITS$exec;
1724
- if (CLIENT_ADDRESS.test(address)) return address;
1725
- const digits = (_ACCOUNT_DIGITS$exec = ACCOUNT_DIGITS.exec(address)) === null || _ACCOUNT_DIGITS$exec === void 0 ? void 0 : _ACCOUNT_DIGITS$exec[1];
1726
- const account = digits === void 0 ? void 0 : (0, _gala_chain_gala_core_sdk.checksumEthereumAddress)(digits);
1727
- if (account === void 0) throw new _gala_chain_gala_core_sdk.GalaSDKError("INVALID_WALLET_ADDRESS", {
1728
- field,
1729
- value: String(address)
1730
- });
1731
- return `eth|${account.slice(2)}`;
1732
- }
1733
- /**
1734
1701
  * Create a token config lookup map from an array of configs.
1735
1702
  *
1736
1703
  * Normalizes symbols to uppercase for case-insensitive lookup.
@@ -2935,7 +2902,7 @@ var EthereumBridgeStrategy = class EthereumBridgeStrategy extends ConfiguredBrid
2935
2902
  validateBridgeAmount(amount);
2936
2903
  const hasSourceKey = sourcePrivateKey !== void 0 && sourcePrivateKey !== "";
2937
2904
  if (hasSourceKey) validateEthereumPrivateKeyFormat(sourcePrivateKey);
2938
- const recipient = normalizeGalaChainAddress(recipientAddress ?? this.galaChainWalletAddress);
2905
+ const recipient = (0, _gala_chain_gala_core_sdk.galaChainUserRef)(recipientAddress ?? this.galaChainWalletAddress, "address");
2939
2906
  const wallet = hasSourceKey ? new ethers.Wallet(sourcePrivateKey, this.ethereumProvider) : this.ethereumWallet;
2940
2907
  const tokenConfig = requireTokenConfig(this.tokenConfigs, tokenSymbol, "Ethereum");
2941
2908
  const metadata = await this.tokenMetadataResolver.getTokenMetadata(tokenSymbol);
@@ -3348,7 +3315,7 @@ var SolanaBridgeStrategy = class extends ConfiguredBridgeStrategy {
3348
3315
  const tokenSymbol = assertTokenSymbolResolved(resolvedSymbol);
3349
3316
  validateBridgeAmount(amount);
3350
3317
  const keypair = sourcePrivateKey !== void 0 && sourcePrivateKey !== "" ? keypairFromBase58(sourcePrivateKey) : this.solanaKeypair;
3351
- const recipient = normalizeGalaChainAddress(recipientAddress ?? this.galaChainWalletAddress);
3318
+ const recipient = (0, _gala_chain_gala_core_sdk.galaChainUserRef)(recipientAddress ?? this.galaChainWalletAddress, "address");
3352
3319
  const tokenConfig = requireTokenConfig(this.tokenConfigs, tokenSymbol, "Solana");
3353
3320
  const metadata = await this.tokenMetadataResolver.getTokenMetadata(tokenSymbol);
3354
3321
  const amountBaseUnits = toBaseUnits(amount, metadata.decimals);
@@ -3863,7 +3830,7 @@ var BridgeService = class {
3863
3830
  constructor(config) {
3864
3831
  var _config$bridgeableTok;
3865
3832
  if (typeof ((_config$bridgeableTok = config.bridgeableTokenService) === null || _config$bridgeableTok === void 0 ? void 0 : _config$bridgeableTok.getTokenByTokenId) !== "function") throw new _gala_chain_gala_core_sdk.GalaSDKError("INVALID_BRIDGE_OPTION", { option: "bridgeableTokenService" });
3866
- const galaChainWalletAddress = normalizeGalaChainAddress(config.galaChainWalletAddress, "galaChainWalletAddress");
3833
+ const galaChainWalletAddress = (0, _gala_chain_gala_core_sdk.galaChainUserRef)(config.galaChainWalletAddress, "galaChainWalletAddress");
3867
3834
  this.environment = config.environment ?? "prod";
3868
3835
  const urls = _gala_chain_gala_core_sdk.GALA_CHAIN_ENVIRONMENTS[this.environment];
3869
3836
  const rpcUrls = BRIDGE_RPC_URLS[this.environment];
@@ -4754,8 +4721,8 @@ var WrapService = class {
4754
4721
  validateBridgeAmount(amount);
4755
4722
  if (this.signer === void 0) throw new _gala_chain_gala_core_sdk.GalaSDKError("INVALID_BRIDGE_OPTION", { option: "signer" });
4756
4723
  if (this.walletAddress === void 0 || this.walletAddress === "") throw new _gala_chain_gala_core_sdk.GalaSDKError("INVALID_BRIDGE_OPTION", { option: "walletAddress" });
4757
- const senderAddress = normalizeGalaChainAddress(this.walletAddress, "walletAddress");
4758
- const recipient = options.recipient === void 0 || options.recipient === "" ? senderAddress : normalizeGalaChainAddress(options.recipient, "recipient");
4724
+ const senderAddress = (0, _gala_chain_gala_core_sdk.galaChainUserRef)(this.walletAddress, "walletAddress");
4725
+ const recipient = options.recipient === void 0 || options.recipient === "" ? senderAddress : (0, _gala_chain_gala_core_sdk.galaChainUserRef)(options.recipient, "recipient");
4759
4726
  const source = await this.sourceToken(options.tokenId, direction);
4760
4727
  const destination = await this.wrappableTokenService.getWrapCounterpart(options.tokenId);
4761
4728
  if (destination === void 0) throw new _gala_chain_gala_core_sdk.GalaSDKError("TOKEN_NOT_WRAPPABLE", {