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

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 (68) hide show
  1. package/README.md +28 -7
  2. package/dist/bridge.cjs +6 -1
  3. package/dist/bridge.cjs.map +1 -1
  4. package/dist/bridge.mjs +7 -2
  5. package/dist/bridge.mjs.map +1 -1
  6. package/dist/browser/bridge.js +1 -1
  7. package/dist/browser/bridge.js.map +1 -1
  8. package/dist/browser/classes/error_catalog.js.map +1 -1
  9. package/dist/browser/classes/error_phase_table.js.map +1 -1
  10. package/dist/browser/classes/error_phases.js.map +1 -1
  11. package/dist/browser/classes/gala_sdk_error.js +1 -1
  12. package/dist/browser/classes/gala_sdk_error.js.map +1 -1
  13. package/dist/browser/classes/signers.js +1 -1
  14. package/dist/browser/classes/signers.js.map +1 -1
  15. package/dist/browser/config/environments.js.map +1 -1
  16. package/dist/browser/index.js +1 -1
  17. package/dist/browser/providers.js.map +1 -1
  18. package/dist/browser/react.js.map +1 -1
  19. package/dist/browser/reads/gateway_reads.js +1 -1
  20. package/dist/browser/reads/gateway_reads.js.map +1 -1
  21. package/dist/browser/reads/parse.js.map +1 -1
  22. package/dist/browser/reads/request.js.map +1 -1
  23. package/dist/browser/reads/types.js.map +1 -1
  24. package/dist/browser/utils/axios_requestor.js.map +1 -1
  25. package/dist/browser/utils/chain_dto_signing.js.map +1 -1
  26. package/dist/browser/utils/class_key.js.map +1 -1
  27. package/dist/browser/utils/dto_operation.js +2 -0
  28. package/dist/browser/utils/dto_operation.js.map +1 -0
  29. package/dist/browser/utils/eip712.js.map +1 -1
  30. package/dist/browser/utils/error_brand.js.map +1 -1
  31. package/dist/browser/utils/eth_address.js.map +1 -1
  32. package/dist/browser/utils/ethers_provider.js.map +1 -1
  33. package/dist/browser/utils/failure_outcomes.js.map +1 -1
  34. package/dist/browser/utils/failure_view.js.map +1 -1
  35. package/dist/browser/utils/fetch_failure.js.map +1 -1
  36. package/dist/browser/utils/pre_send.js +1 -1
  37. package/dist/browser/utils/pre_send.js.map +1 -1
  38. package/dist/browser/utils/signing.js.map +1 -1
  39. package/dist/browser/utils/transport.js +1 -1
  40. package/dist/browser/utils/transport.js.map +1 -1
  41. package/dist/browser/utils/typed_data.js.map +1 -1
  42. package/dist/browser/utils/unique_key.js.map +1 -1
  43. package/dist/browser/utils/unique_key_syntax.js.map +1 -1
  44. package/dist/browser/utils/wallet_keys.js.map +1 -1
  45. package/dist/browser/utils/wallet_rejection.js.map +1 -1
  46. package/dist/browser/version.js +1 -1
  47. package/dist/browser/version.js.map +1 -1
  48. package/dist/browser/wallet.js.map +1 -1
  49. package/dist/browser/writes/gateway_writes.js +1 -1
  50. package/dist/browser/writes/gateway_writes.js.map +1 -1
  51. package/dist/browser/writes/identity.js.map +1 -1
  52. package/dist/browser/writes/lock.js.map +1 -1
  53. package/dist/browser/writes/submit.js +1 -1
  54. package/dist/browser/writes/submit.js.map +1 -1
  55. package/dist/browser/writes/token_ref.js.map +1 -1
  56. package/dist/browser/writes/transfer.js.map +1 -1
  57. package/dist/browser/writes/types.js.map +1 -1
  58. package/dist/index.cjs +119 -8
  59. package/dist/index.cjs.map +1 -1
  60. package/dist/index.d.cts +95 -3
  61. package/dist/index.d.ts +95 -3
  62. package/dist/index.mjs +117 -9
  63. package/dist/index.mjs.map +1 -1
  64. package/package.json +30 -30
  65. /package/dist/browser/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/defineProperty.js +0 -0
  66. /package/dist/browser/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPrimitive.js +0 -0
  67. /package/dist/browser/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/toPropertyKey.js +0 -0
  68. /package/dist/browser/_virtual/{_@oxc-project_runtime@0.153.0 → _@oxc-project_runtime@0.154.0}/helpers/esm/typeof.js +0 -0
package/README.md CHANGED
@@ -13,7 +13,7 @@ gateway generically; product backends (the DEX and Launchpad backends) have thei
13
13
  ## Install
14
14
 
15
15
  ```bash
16
- npm install @gala-chain/gala-core-sdk
16
+ npm install @gala-chain/gala-core-sdk@next
17
17
  ```
18
18
 
19
19
  Pin the exact version in an app build. A product SDK takes core as a **peer dependency**: install it
@@ -22,10 +22,13 @@ next to the product SDK, once.
22
22
  ## Quick start
23
23
 
24
24
  ```typescript
25
- import { PrivateKeySigner, serialize, signNative, normalizePrivateKey } from '@gala-chain/gala-core-sdk';
25
+ import { PrivateKeySigner, serialize, signNative, normalizePrivateKey, withDtoOperation } from '@gala-chain/gala-core-sdk';
26
26
 
27
27
  const signer = new PrivateKeySigner(process.env.GALACHAIN_PRIVATE_KEY!);
28
- const signed = await signer.signObject('TransferToken', { quantity: '1', uniqueKey: 'k-1' });
28
+ // The chain refuses a signed DTO without the `dtoOperation` of the call it is sent to, and the field is
29
+ // part of what is signed: set it BEFORE signing (GatewayWrites and the product SDKs already do).
30
+ const dto = withDtoOperation('asset/token-contract', 'TransferToken', { quantity: '1', uniqueKey: 'k-1' });
31
+ const signed = await signer.signObject('TransferToken', dto);
29
32
 
30
33
  // The primitives the signer is built on, byte-identical to @gala-chain/api:
31
34
  const key = normalizePrivateKey(process.env.GALACHAIN_PRIVATE_KEY!);
@@ -38,7 +41,7 @@ key.fill(0);
38
41
  | Area | Exports |
39
42
  | --- | --- |
40
43
  | Signers | `PrivateKeySigner`, `createLazyPrivateKeySigner`, `GalaWalletSigner`, `BrowserWalletSigner`, `signPreSend`, type `GalaChainSigner` |
41
- | Signing | `serialize`, `getPayloadToSign`, `signNative`, `signPersonalMessage`, `personalSignPrefixFor`, `fixpointPrefixFor`, `signChainDto*`, `signRawObject`, `generateEIP712Types`, `buildEIP712Payload`, `hashTypedData`, `signTypedDataPayload` |
44
+ | Signing | `serialize`, `getPayloadToSign`, `signNative`, `signPersonalMessage`, `personalSignPrefixFor`, `fixpointPrefixFor`, `signChainDto*`, `signRawObject`, `generateEIP712Types`, `buildEIP712Payload`, `hashTypedData`, `signTypedDataPayload`; the signed `dtoOperation`: `withDtoOperation`, `dtoOperationOf`, `CHAIN_CONTRACT_OPERATION_PREFIXES`, type `ChainContractPath` |
42
45
  | 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` |
43
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` |
44
47
  | 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` |
@@ -96,7 +99,9 @@ bridge-out request was accepted the tokens may be locked: a later failure is
96
99
  `BRIDGE_OUT_OUTCOME_UNKNOWN` (with the step, the bridge request id and the `uniqueKey`), and a
97
100
  deposit that may have been sent is `BRIDGE_DEPOSIT_OUTCOME_UNKNOWN`; neither is ever retried by the
98
101
  SDK. `WrapService` wraps a token from its own channel to the asset channel (MUSIC to GMUSIC) and
99
- back, signed natively by a `GalaChainSigner`.
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.
100
105
 
101
106
  TypeScript: the `./bridge` declarations name `@solana/web3.js` types, whose own declarations import
102
107
  Node's `http` and `https`, so a TypeScript app that imports `./bridge` has `@types/node` (with
@@ -104,6 +109,8 @@ TypeScript 6, `"types": ["node"]`) or `skipLibCheck`. The other entries need no
104
109
 
105
110
  ## Wallet providers
106
111
 
112
+ The Gala Wallet browser extension (install, what it signs, its provider methods) has its own page: [docs/wallet-extension.md](./docs/wallet-extension.md).
113
+
107
114
  ```typescript
108
115
  import { detectWallets, ExternalWalletProvider, PrivateKeyProvider } from '@gala-chain/gala-core-sdk/providers';
109
116
 
@@ -182,6 +189,17 @@ await writes.lockTokens({ tokens: [{ tokenClassKey: 'GALA|Unit|none|none', quant
182
189
  converted.
183
190
  - The signer is handed the bare DTO; the body sent is exactly the DTO plus the signature (a signer
184
191
  that adds or changes a field is refused). A `uniqueKey` is minted per write unless you pass one.
192
+ - Every DTO carries a `dtoOperation` (`<channel>_<chaincode>_<Contract>:<Method>`, for example
193
+ `asset-channel_basic-asset_GalaChainToken:TransferToken`), set before the signer runs because it is
194
+ part of what is signed. The chain refuses a DTO without it ("DTO operation is not provided. Signed
195
+ requests must include dtoOperation.") or with one that is not the call it is sent to ("The dto was
196
+ signed to call X operation, but the current operation is Y"). The URL of a write and its operation
197
+ come from one table (`CHAIN_CONTRACT_OPERATION_PREFIXES`), so they cannot disagree. For a call the
198
+ SDK does not make, use `withDtoOperation(contractPath, method, dto)` (the contract path is the
199
+ route's `<channel>/<contract>`, such as `asset/token-contract`) or `signPreSend(signer,
200
+ contractPath, method, dto)`, which sets it and signs; a DTO that already names a different
201
+ operation is refused as `SIGNING_FAILED`. Never add it after signing: the signature would not
202
+ cover it.
185
203
  - GalaChain's `Status` is checked before anything else is trusted; a timeout or broken connection is
186
204
  `GATEWAY_WRITE_OUTCOME_UNKNOWN`: the write may have been applied, so check its `uniqueKey` and
187
205
  never resend it under a fresh key.
@@ -220,7 +238,10 @@ const classes = await reads.fetchAllTokenClasses({ collection: 'BONKTactics' },
220
238
  The signing code is pinned byte-for-byte to `@gala-chain/api` and to the Gala Wallet's and the
221
239
  gSwap web app's signing code by the golden vectors in `tests/fixtures/wallet-signing-golden.json`
222
240
  and `tests/fixtures/frontend-signing-golden.json` (`tests/signing-golden.test.ts`). They are never
223
- regenerated to make a test pass.
241
+ regenerated to make a test pass. Those two pin the signing primitives and the web apps' bytes, which
242
+ carry no `dtoOperation`; the SDK's own write and bridge recordings
243
+ (`tests/fixtures/writes-signing-golden.json`, `bridge-out-recorded.json`) pin the signed bodies
244
+ including it.
224
245
 
225
246
  ## React Native
226
247
 
@@ -255,7 +276,7 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
255
276
 
256
277
  ## Status
257
278
 
258
- <!-- docs:var version -->1.0.0<!-- /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()`;
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()`;
259
280
  rc.5: every Ethereum account a read, write or GalaConnect client sends is
260
281
  `eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
261
282
  `bridgeableTokenService` is required). In: signing, signers, transport and the error model (rc.0, from gswap-sdk); the
package/dist/bridge.cjs CHANGED
@@ -78,6 +78,10 @@ const GALA_TRANSACTION_TYPE = [
78
78
  name: "destinationChainTxFee",
79
79
  type: "destinationChainTxFee"
80
80
  },
81
+ {
82
+ name: "dtoOperation",
83
+ type: "string"
84
+ },
81
85
  {
82
86
  name: "quantity",
83
87
  type: "string"
@@ -2274,6 +2278,7 @@ async function buildBridgeOutPayload(dto, config) {
2274
2278
  const message = {
2275
2279
  destinationChainId,
2276
2280
  destinationChainTxFee: sanitizeObject(sanitizedFeeObj),
2281
+ dtoOperation: (0, _gala_chain_gala_core_sdk.dtoOperationOf)("asset/bridge-contract", BRIDGE_OUT_METHOD),
2277
2282
  quantity: dto.quantity,
2278
2283
  recipient: dto.recipient,
2279
2284
  tokenInstance: dto.tokenInstance,
@@ -4753,7 +4758,7 @@ var WrapService = class {
4753
4758
  wrap: true,
4754
4759
  uniqueKey
4755
4760
  };
4756
- const requestBody = await (0, _gala_chain_gala_core_sdk.signPreSend)(this.signer, "RequestTokenBridgeOut", message);
4761
+ const requestBody = await (0, _gala_chain_gala_core_sdk.signPreSend)(this.signer, "asset/bridge-contract", "RequestTokenBridgeOut", message);
4757
4762
  const response = await this.galaConnectClient.requestBridgeOut(requestBody);
4758
4763
  assertRequestAccepted("RequestTokenBridgeOut", response, uniqueKey);
4759
4764
  return {