@gala-chain/gala-core-sdk 1.1.0-beta.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.
package/README.md CHANGED
@@ -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
@@ -184,6 +189,17 @@ await writes.lockTokens({ tokens: [{ tokenClassKey: 'GALA|Unit|none|none', quant
184
189
  converted.
185
190
  - The signer is handed the bare DTO; the body sent is exactly the DTO plus the signature (a signer
186
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.
187
203
  - GalaChain's `Status` is checked before anything else is trusted; a timeout or broken connection is
188
204
  `GATEWAY_WRITE_OUTCOME_UNKNOWN`: the write may have been applied, so check its `uniqueKey` and
189
205
  never resend it under a fresh key.
@@ -222,7 +238,10 @@ const classes = await reads.fetchAllTokenClasses({ collection: 'BONKTactics' },
222
238
  The signing code is pinned byte-for-byte to `@gala-chain/api` and to the Gala Wallet's and the
223
239
  gSwap web app's signing code by the golden vectors in `tests/fixtures/wallet-signing-golden.json`
224
240
  and `tests/fixtures/frontend-signing-golden.json` (`tests/signing-golden.test.ts`). They are never
225
- 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.
226
245
 
227
246
  ## React Native
228
247
 
@@ -257,7 +276,7 @@ gzipped, before `ethers` and `@solana/*`) are loaded only by an app that imports
257
276
 
258
277
  ## Status
259
278
 
260
- <!-- docs:var version -->1.1.0-beta.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()`;
261
280
  rc.5: every Ethereum account a read, write or GalaConnect client sends is
262
281
  `eth|<EIP-55>`, the only spelling the gateway accepts, and `galaChainUserRef` is exported; rc.4:
263
282
  `bridgeableTokenService` is required). In: signing, signers, transport and the error model (rc.0, from gswap-sdk); the
@@ -1,2 +1,2 @@
1
- import{GalaSDKError as e,isGalaError as t,parseJson as n}from"../classes/gala_sdk_error.js";import"../version.js";function r(e,t){if(t===1/0)return()=>void 0;let n=setTimeout(()=>e.abort(),t);return()=>clearTimeout(n)}function i(t,n){if(t===1/0||Number.isFinite(t)&&t>0)return t;throw new e(`INVALID_TIMEOUT`,{field:n,value:t})}const a=/[A-Za-z0-9\-._~!'()*$|:,]/u;function o(e){let t=``;for(let n of e)n===` `?t+=`+`:a.test(n)?t+=n:t+=s(n);return t}function s(e){try{return encodeURIComponent(e)}catch{return`%EF%BF%BD`}}function c(e,t=`standard`){return t===`readable`?Object.entries(e).map(([e,t])=>`${o(e)}=${o(t)}`).join(`&`):new URLSearchParams(e).toString()}function l(e,t={}){let n=/* @__PURE__ */ new Map,r=(e,t=!1)=>{for(let[r,i]of Object.entries(e??{}))t&&n.delete(r.toLowerCase()),n.set(r.toLowerCase(),[r,i])};return e?.userAgent!==!1&&r({"User-Agent":e?.userAgent??`GalaChain-SDK/1.1.0-beta.0`}),r(t.defaults),r(e?.headers),t.json===!0&&!n.has(`content-type`)&&r({"Content-Type":`application/json`}),r(t.fixed,!0),Object.fromEntries(n.values())}const u=async(t,n)=>{try{return await fetch(t,n)}catch(r){throw n?.signal?.aborted===!0?r:new e(`TRANSPORT_ERROR`,{url:t},{url:t,cause:r})}};async function d(n,i,a,o,s){let c=new AbortController,l=r(c,o),u=a.signal,d=()=>c.abort();u?.addEventListener(`abort`,d,{once:!0});let f=s?.write===!1;try{return await n(i,{...a,signal:c.signal})}catch(n){throw u?.aborted===!0?n:c.signal.aborted?new e(`REQUEST_TIMEOUT`,{url:i,timeoutMs:o},{url:i,cause:n,...f?{write:!1}:{}}):f&&t(n,`TRANSPORT_ERROR`)&&n.write?new e(`TRANSPORT_ERROR`,{url:n.url??i},{url:n.url??i,cause:n.cause,write:!1}):n}finally{l(),u?.removeEventListener(`abort`,d)}}async function f(e){let t=await e.text();return n(t)??t}function p(e,t){let n=e.headers;if(n===void 0)return;if(g(n)){let e=n.get(t);return e===null||e===``?void 0:e}let r=Object.entries(n).find(([e])=>e.toLowerCase()===t.toLowerCase())?.[1];return r===void 0||r===``?void 0:r}function m(e){let t=p(e,`retry-after`);if(t===void 0)return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return n*1e3;let r=Date.parse(t);return Number.isNaN(r)?void 0:Math.max(0,r-Date.now())}function h(e,t=`x-block-number`){let n=p(e,t);if(n===void 0)return;let r=Number(n);return Number.isInteger(r)&&r>=0?r:void 0}function g(e){return`get`in e&&typeof e.get==`function`}export{r as armTimeout,c as buildQueryString,l as buildRequestHeaders,u as fetchRequestor,h as readBlockNumberHeader,p as readHeader,f as readResponseBody,m as readRetryAfter,d as requestWithTimeout,i as validateTimeoutMs};
1
+ import{GalaSDKError as e,isGalaError as t,parseJson as n}from"../classes/gala_sdk_error.js";import"../version.js";function r(e,t){if(t===1/0)return()=>void 0;let n=setTimeout(()=>e.abort(),t);return()=>clearTimeout(n)}function i(t,n){if(t===1/0||Number.isFinite(t)&&t>0)return t;throw new e(`INVALID_TIMEOUT`,{field:n,value:t})}const a=/[A-Za-z0-9\-._~!'()*$|:,]/u;function o(e){let t=``;for(let n of e)n===` `?t+=`+`:a.test(n)?t+=n:t+=s(n);return t}function s(e){try{return encodeURIComponent(e)}catch{return`%EF%BF%BD`}}function c(e,t=`standard`){return t===`readable`?Object.entries(e).map(([e,t])=>`${o(e)}=${o(t)}`).join(`&`):new URLSearchParams(e).toString()}function l(e,t={}){let n=/* @__PURE__ */ new Map,r=(e,t=!1)=>{for(let[r,i]of Object.entries(e??{}))t&&n.delete(r.toLowerCase()),n.set(r.toLowerCase(),[r,i])};return e?.userAgent!==!1&&r({"User-Agent":e?.userAgent??`GalaChain-SDK/1.1.0-beta.1`}),r(t.defaults),r(e?.headers),t.json===!0&&!n.has(`content-type`)&&r({"Content-Type":`application/json`}),r(t.fixed,!0),Object.fromEntries(n.values())}const u=async(t,n)=>{try{return await fetch(t,n)}catch(r){throw n?.signal?.aborted===!0?r:new e(`TRANSPORT_ERROR`,{url:t},{url:t,cause:r})}};async function d(n,i,a,o,s){let c=new AbortController,l=r(c,o),u=a.signal,d=()=>c.abort();u?.addEventListener(`abort`,d,{once:!0});let f=s?.write===!1;try{return await n(i,{...a,signal:c.signal})}catch(n){throw u?.aborted===!0?n:c.signal.aborted?new e(`REQUEST_TIMEOUT`,{url:i,timeoutMs:o},{url:i,cause:n,...f?{write:!1}:{}}):f&&t(n,`TRANSPORT_ERROR`)&&n.write?new e(`TRANSPORT_ERROR`,{url:n.url??i},{url:n.url??i,cause:n.cause,write:!1}):n}finally{l(),u?.removeEventListener(`abort`,d)}}async function f(e){let t=await e.text();return n(t)??t}function p(e,t){let n=e.headers;if(n===void 0)return;if(g(n)){let e=n.get(t);return e===null||e===``?void 0:e}let r=Object.entries(n).find(([e])=>e.toLowerCase()===t.toLowerCase())?.[1];return r===void 0||r===``?void 0:r}function m(e){let t=p(e,`retry-after`);if(t===void 0)return;let n=Number(t);if(Number.isFinite(n)&&n>=0)return n*1e3;let r=Date.parse(t);return Number.isNaN(r)?void 0:Math.max(0,r-Date.now())}function h(e,t=`x-block-number`){let n=p(e,t);if(n===void 0)return;let r=Number(n);return Number.isInteger(r)&&r>=0?r:void 0}function g(e){return`get`in e&&typeof e.get==`function`}export{r as armTimeout,c as buildQueryString,l as buildRequestHeaders,u as fetchRequestor,h as readBlockNumberHeader,p as readHeader,f as readResponseBody,m as readRetryAfter,d as requestWithTimeout,i as validateTimeoutMs};
2
2
  //# sourceMappingURL=transport.js.map
@@ -1,2 +1,2 @@
1
- const e=`1.1.0-beta.0`;export{e as GALA_CORE_SDK_VERSION};
1
+ const e=`1.1.0-beta.1`;export{e as GALA_CORE_SDK_VERSION};
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","names":["GALA_CORE_SDK_VERSION"],"sources":["../../src/version.ts"],"sourcesContent":["declare const __GALA_CORE_SDK_VERSION__: string | undefined;\n\n/**\n * The `@gala-chain/gala-core-sdk` package version, embedded by the bundler, with a source-test\n * fallback. It is the version in the default `User-Agent` (`GalaChain-SDK/<version>`) of every SDK\n * request, whichever product SDK sends it.\n */\nexport const GALA_CORE_SDK_VERSION =\n typeof __GALA_CORE_SDK_VERSION__ === 'string' ? __GALA_CORE_SDK_VERSION__ : '1.1.0-beta.0';\n"],"mappings":"AAOA,MAAaA,EAAA,e"}
1
+ {"version":3,"file":"version.js","names":["GALA_CORE_SDK_VERSION"],"sources":["../../src/version.ts"],"sourcesContent":["declare const __GALA_CORE_SDK_VERSION__: string | undefined;\n\n/**\n * The `@gala-chain/gala-core-sdk` package version, embedded by the bundler, with a source-test\n * fallback. It is the version in the default `User-Agent` (`GalaChain-SDK/<version>`) of every SDK\n * request, whichever product SDK sends it.\n */\nexport const GALA_CORE_SDK_VERSION =\n typeof __GALA_CORE_SDK_VERSION__ === 'string' ? __GALA_CORE_SDK_VERSION__ : '1.1.0-beta.1';\n"],"mappings":"AAOA,MAAaA,EAAA,e"}
package/dist/index.cjs CHANGED
@@ -2820,7 +2820,7 @@ async function signPreSend(signer, contractPath, method, dto) {
2820
2820
  * fallback. It is the version in the default `User-Agent` (`GalaChain-SDK/<version>`) of every SDK
2821
2821
  * request, whichever product SDK sends it.
2822
2822
  */
2823
- const GALA_CORE_SDK_VERSION = "1.1.0-beta.0";
2823
+ const GALA_CORE_SDK_VERSION = "1.1.0-beta.1";
2824
2824
 
2825
2825
  //#endregion
2826
2826
  //#region src/utils/transport.ts
@@ -2881,7 +2881,7 @@ function buildRequestHeaders(wire, parts = {}) {
2881
2881
  entries.set(name.toLowerCase(), [name, value]);
2882
2882
  }
2883
2883
  };
2884
- if ((wire === null || wire === void 0 ? void 0 : wire.userAgent) !== false) put({ "User-Agent": (wire === null || wire === void 0 ? void 0 : wire.userAgent) ?? `GalaChain-SDK/${"1.1.0-beta.0"}` });
2884
+ if ((wire === null || wire === void 0 ? void 0 : wire.userAgent) !== false) put({ "User-Agent": (wire === null || wire === void 0 ? void 0 : wire.userAgent) ?? `GalaChain-SDK/${"1.1.0-beta.1"}` });
2885
2885
  put(parts.defaults);
2886
2886
  put(wire === null || wire === void 0 ? void 0 : wire.headers);
2887
2887
  if (parts.json === true && !entries.has("content-type")) put({ "Content-Type": "application/json" });