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

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 +4 -2
  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
@@ -1 +1 @@
1
- {"version":3,"file":"error_catalog.js","names":["INVALID_PRIVATE_KEY_REASONS","SIGNING_FAILURE_REASONS","INVALID_TOKEN_REFERENCE_REASONS","GATEWAY_WRITES_OPTIONS","GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS","GATEWAY_READS_OPTIONS","PAGE_REQUEST_FIELDS","WALLET_NOT_CONNECTED_REASONS","WALLET_CONNECTION_FAILURE_REASONS","WALLET_PROVIDER_CONFIG_MISSING","WALLET_INPUT_PROBLEMS","BRIDGE_NETWORKS","BRIDGE_AMOUNT_PROBLEMS","BRIDGE_OUT_STEPS","BRIDGE_DEPOSIT_STEPS","WRAP_REFUSAL_REASONS","WRAP_DIRECTIONS","GALA_ERROR_CATALOG","galaErrorTemplates","code","entry","PLACEHOLDER","renderGalaErrorTemplate","template","value","params","name","whole","templatePlaceholders","match"],"sources":["../../../src/classes/error_catalog.ts"],"sourcesContent":["/**\n * The catalog of every error `@gala-chain/gala-core-sdk` throws: the SINGLE source of truth for\n * its `code`, the named parameters it carries and the English template its `message` is generated\n * from. A product SDK (gswap-sdk, launchpad-sdk) keeps its OWN catalog of the codes only it throws,\n * and its error class (a subclass of `GalaSDKError`) reads both; no code is defined twice.\n *\n * - `code` is the only discriminator. It is stable: apps branch on it, never on message text.\n * - `params` are the named placeholders of the error: a flat object of primitives (string,\n * number, boolean) that an app feeds to its own localization (i18next, ICU, FormatJS).\n * Raw server payloads are never params (they are `error.body` / `error.bodyText`), and no\n * secret (private key, signature, raw DTO) ever is.\n * - `template` is English with `{placeholder}` markers. `error.message` is generated from it\n * and the params, so the two cannot drift. It is for logs and developers: it is not stable and\n * must not be shown to users or matched on.\n *\n * Every placeholder in a template is a declared param and every declared param is a placeholder,\n * except the few `unrendered` params that carry server text for the app and are kept out of\n * `message` on purpose (pinned by tests/error_catalog.test.ts). Facts that are not placeholders\n * (HTTP status, URL, `uniqueKey`, transaction ids, the raw body, the cause) are typed properties of\n * the error, see {@link GalaErrorContext}.\n */\n\nimport type { GalaErrorPhase } from './error_phases.js';\n\n/**\n * The kinds a param can have: a primitive, or a CLOSED set of string tokens (a readonly tuple).\n * A closed set is a documented union: an app maps each member to its own text and can check that\n * it covered all of them, and a new member is a compile error until it does.\n */\nexport type GalaErrorParamKind = 'string' | 'number' | 'boolean' | readonly string[];\n\n/** One catalog entry (of this catalog, or of a product SDK's own catalog). */\nexport interface GalaErrorCatalogEntry {\n /** The phase this code is thrown in, unless a throw site says otherwise (see {@link GalaErrorPhase}). */\n readonly phase: GalaErrorPhase;\n /** English message template with `{placeholder}` markers. */\n readonly template: string;\n /** Param name to kind. Every param is required and appears in the template, except `unrendered`. */\n readonly params: Readonly<Record<string, GalaErrorParamKind>>;\n /**\n * Params that are carried for the app but deliberately NOT placeholders of the template. Used\n * for `serverMessage` on the codes whose failing answer may be anything (a proxy's page, a\n * validation list): the server's text is data for the app to relay or ignore, and keeping it out\n * of `message` means it cannot reach a log line or a user interface by accident.\n */\n readonly unrendered?: readonly string[];\n}\n\n/**\n * Why a private key was refused (`INVALID_PRIVATE_KEY.params.reason`). A token for the app to map\n * to its own text, never English and never any part of the key.\n *\n * - `wrong_length`: raw bytes that are not 32 bytes long (a `./bridge` Solana secret key: not 64\n * bytes once decoded).\n * - `bad_encoding`: a string that is neither 64 hex characters (optionally `0x`-prefixed, 63 is\n * left-padded) nor a 44-character base64 string (`./bridge`: an Ethereum key that is not `0x`\n * and 64 hex characters; a Solana secret key that is not base58, or whose public half does not\n * match its secret half).\n * - `not_on_curve`: 32 bytes that are not a valid secp256k1 secret scalar.\n * - `no_key_provided`: a lazy key provider returned something that is not a string.\n */\nexport const INVALID_PRIVATE_KEY_REASONS = [\n 'wrong_length',\n 'bad_encoding',\n 'not_on_curve',\n 'no_key_provided',\n] as const;\n\n/** One member of {@link INVALID_PRIVATE_KEY_REASONS}. */\nexport type InvalidPrivateKeyReason = (typeof INVALID_PRIVATE_KEY_REASONS)[number];\n\n/**\n * Why a signer could not produce a signature (`SIGNING_FAILED.params.reason`). A token for the\n * app to map to its own text.\n *\n * - `user_rejected`: the person declined in their wallet (an EIP-1193 `4001`, an ethers\n * `ACTION_REJECTED`, or a wallet that words it \"User rejected/denied ...\"). Nothing is wrong:\n * they may simply try again.\n * - `failed`: anything else the signer threw (a locked wallet, an unreachable extension, a wallet\n * that refused). The original error is `cause`.\n */\nexport const SIGNING_FAILURE_REASONS = ['user_rejected', 'failed'] as const;\n\n/** One member of {@link SIGNING_FAILURE_REASONS}. */\nexport type SigningFailureReason = (typeof SIGNING_FAILURE_REASONS)[number];\n\n/**\n * Why a gateway write refused the token it was asked to move\n * (`INVALID_TOKEN_REFERENCE.params.reason`). A token for the app to map to its own text.\n *\n * - `missing`: neither `tokenClassKey` nor `tokenName` was given.\n * - `ambiguous`: more than one way of naming the token was given (`tokenClassKey` and\n * `tokenName`, or a `tokenName` with an `instance`: a resolved name decides its own instance).\n * - `bad_class_key`: `tokenClassKey` is not a class key: a pipe string needs exactly four\n * non-empty parts, a `$` string at least four (split from the right), an object four non-empty\n * strings. A bare symbol is never a class key and none is derived from it.\n * - `bad_instance`: `instance` is not a string of decimal digits.\n */\nexport const INVALID_TOKEN_REFERENCE_REASONS = [\n 'missing',\n 'ambiguous',\n 'bad_class_key',\n 'bad_instance',\n] as const;\n\n/** One member of {@link INVALID_TOKEN_REFERENCE_REASONS}. */\nexport type InvalidTokenReferenceReason = (typeof INVALID_TOKEN_REFERENCE_REASONS)[number];\n\n/**\n * The `GatewayWrites` options that are refused when missing or of the wrong type\n * (`INVALID_WRITES_OPTION.params.option`). `walletAddress`, `requestTimeoutMs` and\n * `uniqueKeyPrefix` have codes of their own (`INVALID_WALLET_ADDRESS`, `INVALID_TIMEOUT`,\n * `INVALID_UNIQUE_KEY_PREFIX`).\n */\nexport const GATEWAY_WRITES_OPTIONS = [\n 'signer',\n 'gatewayBaseUrl',\n 'httpRequestor',\n 'tokenNameResolver',\n] as const;\n\n/** One member of {@link GATEWAY_WRITES_OPTIONS}. */\nexport type GatewayWritesOption = (typeof GATEWAY_WRITES_OPTIONS)[number];\n\n/**\n * Why the outcome of a gateway write is unknown (`GATEWAY_WRITE_OUTCOME_UNKNOWN.params.reason`).\n * Both say the same thing about the write (it MAY have been applied: never send it again under a\n * fresh key, check `error.uniqueKey` instead) and differ only in what happened to the request.\n *\n * - `timeout`: the POST exceeded `requestTimeoutMs`; the request may still be running.\n * - `transport`: the POST failed before an answer was read (offline, connection reset, DNS, CORS,\n * a body that broke off). The bytes may have reached the gateway.\n */\nexport const GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS = ['timeout', 'transport'] as const;\n\n/** One member of {@link GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS}. */\nexport type GatewayWriteOutcomeUnknownReason =\n (typeof GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS)[number];\n\n/**\n * The `GatewayReads` options that are refused when missing or of the wrong type\n * (`INVALID_READS_OPTION.params.option`). `requestTimeoutMs` has its own code (`INVALID_TIMEOUT`).\n */\nexport const GATEWAY_READS_OPTIONS = ['gatewayBaseUrl', 'httpRequestor'] as const;\n\n/** One member of {@link GATEWAY_READS_OPTIONS}. */\nexport type GatewayReadsOption = (typeof GATEWAY_READS_OPTIONS)[number];\n\n/**\n * The part of a paginated read that was refused (`INVALID_PAGE_REQUEST.params.field`):\n *\n * - `limit` / `pageSize`: results per page, a whole number from 1 to 10 000;\n * - `maxPages`: how many pages a `fetchAll...` read may walk, a whole number from 1 to 10 000;\n * - `bookmark`: the previous page's `nextPageBookmark`, a string.\n */\nexport const PAGE_REQUEST_FIELDS = ['limit', 'pageSize', 'maxPages', 'bookmark'] as const;\n\n/** One member of {@link PAGE_REQUEST_FIELDS}. */\nexport type PageRequestField = (typeof PAGE_REQUEST_FIELDS)[number];\n\n/**\n * Why a wallet provider is not connected (`WALLET_NOT_CONNECTED.params.reason`):\n *\n * - `not_connected`: `connect()` was never called, or `disconnect()` was;\n * - `disconnected`: the wallet reported it is disconnected (EIP-1193 `4900` / `4901`, a\n * `disconnect` event, or an `accountsChanged` with no account);\n * - `unauthorized`: the wallet refused the account (EIP-1193 `4100`): the person has not granted\n * this app access to it.\n */\nexport const WALLET_NOT_CONNECTED_REASONS = [\n 'not_connected',\n 'disconnected',\n 'unauthorized',\n] as const;\n\n/** One member of {@link WALLET_NOT_CONNECTED_REASONS}. */\nexport type WalletNotConnectedReason = (typeof WALLET_NOT_CONNECTED_REASONS)[number];\n\n/**\n * Why connecting a wallet provider failed (`WALLET_CONNECTION_FAILED.params.reason`):\n *\n * - `no_accounts`: the wallet answered `eth_requestAccounts` with no account;\n * - `user_rejected`: the person declined the connection in their wallet (EIP-1193 `4001`);\n * - `failed`: anything else the wallet threw (the original error is `cause`).\n */\nexport const WALLET_CONNECTION_FAILURE_REASONS = [\n 'no_accounts',\n 'user_rejected',\n 'failed',\n] as const;\n\n/** One member of {@link WALLET_CONNECTION_FAILURE_REASONS}. */\nexport type WalletConnectionFailureReason = (typeof WALLET_CONNECTION_FAILURE_REASONS)[number];\n\n/**\n * What a wallet provider was built without (`INVALID_WALLET_PROVIDER_CONFIG.params.missing`):\n *\n * - `eip1193_provider`: an `ExternalWalletProvider` / `GalaWalletProvider` needs the wallet's\n * provider object (`window.ethereum`, an EIP-6963 announcement, `window.gala`);\n * - `private_key_or_eip1193_provider`: `createWalletProvider` needs one of the two.\n */\nexport const WALLET_PROVIDER_CONFIG_MISSING = [\n 'eip1193_provider',\n 'private_key_or_eip1193_provider',\n] as const;\n\n/** One member of {@link WALLET_PROVIDER_CONFIG_MISSING}. */\nexport type WalletProviderConfigMissing = (typeof WALLET_PROVIDER_CONFIG_MISSING)[number];\n\n/**\n * Why `createWallet` refused its input (`INVALID_WALLET_INPUT.params.reason`), never naming any part\n * of it (it may be a key or a mnemonic):\n *\n * - `empty`: nothing but whitespace;\n * - `unrecognized_format`: neither 64 hex digits nor 12 / 24 words of letters;\n * - `unknown_mnemonic_word`: a word that is not in the BIP-39 English wordlist;\n * - `mnemonic_checksum`: every word is known but the phrase's checksum is wrong (a typo or a\n * swapped word).\n */\nexport const WALLET_INPUT_PROBLEMS = [\n 'empty',\n 'unrecognized_format',\n 'unknown_mnemonic_word',\n 'mnemonic_checksum',\n] as const;\n\n/** One member of {@link WALLET_INPUT_PROBLEMS}. */\nexport type WalletInputProblem = (typeof WALLET_INPUT_PROBLEMS)[number];\n\n/** The external networks `./bridge` bridges to and from. */\nexport const BRIDGE_NETWORKS = ['Ethereum', 'Solana'] as const;\n\n/** One member of {@link BRIDGE_NETWORKS}. */\nexport type BridgeNetwork = (typeof BRIDGE_NETWORKS)[number];\n\n/**\n * Why a bridge amount was refused (`INVALID_BRIDGE_AMOUNT.params.reason`):\n *\n * - `not_a_number`: not a finite decimal number;\n * - `not_positive`: zero or negative (a bridge of nothing only wastes the fee);\n * - `too_many_decimals`: more decimal places than the token has (it would be rounded).\n */\nexport const BRIDGE_AMOUNT_PROBLEMS = [\n 'not_a_number',\n 'not_positive',\n 'too_many_decimals',\n] as const;\n\n/** One member of {@link BRIDGE_AMOUNT_PROBLEMS}. */\nexport type BridgeAmountProblem = (typeof BRIDGE_AMOUNT_PROBLEMS)[number];\n\n/**\n * Where a bridge-out failed AFTER GalaConnect accepted its `RequestTokenBridgeOut`\n * (`BRIDGE_OUT_OUTCOME_UNKNOWN.params.step`):\n *\n * - `request_id`: the answer had no bridge request id;\n * - `bridge_token_out`: the `BridgeTokenOut` call failed;\n * - `transaction_hash`: the `BridgeTokenOut` answer had no transaction hash.\n */\nexport const BRIDGE_OUT_STEPS = ['request_id', 'bridge_token_out', 'transaction_hash'] as const;\n\n/** One member of {@link BRIDGE_OUT_STEPS}. */\nexport type BridgeOutStep = (typeof BRIDGE_OUT_STEPS)[number];\n\n/**\n * Where a bridge-in deposit failed once it was being sent (`BRIDGE_DEPOSIT_OUTCOME_UNKNOWN.params.step`):\n *\n * - `send`: sending the deposit transaction failed (it may have reached the network);\n * - `confirmation`: the deposit was sent and its confirmation failed or is unknown;\n * - `registration`: the deposit is confirmed and registering it with GalaConnect failed.\n */\nexport const BRIDGE_DEPOSIT_STEPS = ['send', 'confirmation', 'registration'] as const;\n\n/** One member of {@link BRIDGE_DEPOSIT_STEPS}. */\nexport type BridgeDepositStep = (typeof BRIDGE_DEPOSIT_STEPS)[number];\n\n/**\n * Why a token cannot be wrapped or unwrapped (`TOKEN_NOT_WRAPPABLE.params.reason`):\n *\n * - `not_listed`: the wrappable token list does not have it;\n * - `no_counterpart`: the token it wraps to / unwraps from is not listed;\n * - `unknown_channel`: its channel (or its counterpart's) is not one a wrap moves between.\n */\nexport const WRAP_REFUSAL_REASONS = ['not_listed', 'no_counterpart', 'unknown_channel'] as const;\n\n/** One member of {@link WRAP_REFUSAL_REASONS}. */\nexport type WrapRefusalReason = (typeof WRAP_REFUSAL_REASONS)[number];\n\n/** The two cross-channel directions (`INVALID_WRAP_DIRECTION.params.direction`). */\nexport const WRAP_DIRECTIONS = ['wrap', 'unwrap'] as const;\n\n/** One member of {@link WRAP_DIRECTIONS}. */\nexport type WrapDirection = (typeof WRAP_DIRECTIONS)[number];\n\n/** The whole core catalog. Add a code here before throwing it anywhere in this package. */\nexport const GALA_ERROR_CATALOG = {\n // ---------------------------------------------------------------------------------- transport\n REQUEST_TIMEOUT: {\n phase: 'in_flight',\n template: 'Request to {url} timed out after {timeoutMs} ms.',\n params: { url: 'string', timeoutMs: 'number' },\n },\n TRANSPORT_ERROR: {\n phase: 'in_flight',\n template: 'The request to {url} failed before the server answered.',\n params: { url: 'string' },\n },\n INVALID_TIMEOUT: {\n phase: 'pre_send',\n template:\n '{field} must be a positive number of milliseconds, or Infinity for no timeout (got {value}).',\n params: { field: 'string', value: 'number' },\n },\n\n // ------------------------------------------------------------------------------ wallet / keys\n GALA_WALLET_NOT_AVAILABLE: {\n phase: 'pre_send',\n template: 'Gala wallet is not available. Please ensure the Gala wallet is connected.',\n params: {},\n },\n WALLET_UNAVAILABLE: {\n phase: 'pre_send',\n template: 'No wallet is connected.',\n params: {},\n },\n MALFORMED_WALLET_REQUEST: {\n phase: 'pre_send',\n template: 'Wallet {method} request is malformed.',\n params: { method: 'string' },\n },\n UNSUPPORTED_WALLET_METHOD: {\n phase: 'pre_send',\n template: 'Unsupported wallet method {method}.',\n params: { method: 'string' },\n },\n INVALID_SIGNATURE: {\n phase: 'pre_send',\n template: 'Wallet returned an invalid {scheme} signature.',\n params: { scheme: 'string' },\n },\n INVALID_CHAIN_ID: {\n phase: 'pre_send',\n template: 'Wallet returned an invalid chain id ({chainId}).',\n params: { chainId: 'string' },\n },\n SIGNER_ADDRESS_MISMATCH: {\n phase: 'pre_send',\n template: 'The signing key does not belong to the expected account.',\n params: {},\n },\n INVALID_PRIVATE_KEY: {\n phase: 'pre_send',\n template: 'Invalid private key: {reason}.',\n params: { reason: INVALID_PRIVATE_KEY_REASONS },\n },\n SIGNING_FAILED: {\n phase: 'pre_send',\n template: 'Signing the {method} request failed ({reason}); nothing was sent.',\n params: { method: 'string', reason: SIGNING_FAILURE_REASONS },\n },\n KEY_PROVIDER_FAILED: {\n phase: 'pre_send',\n template: 'The signing key could not be fetched; nothing was sent.',\n params: {},\n },\n INVALID_SIGNING_HASH_LENGTH: {\n phase: 'pre_send',\n template: 'secp256k1 can only sign a 32-byte hash (got {length}).',\n params: { length: 'number' },\n },\n INVALID_WALLET_ADDRESS: {\n phase: 'pre_send',\n template: 'Invalid {field}: \"{value}\" is not an accepted wallet address form.',\n params: { field: 'string', value: 'string' },\n },\n INVALID_ETH_USER_REF_PREFIX: {\n phase: 'pre_send',\n template:\n 'Invalid {field}: \"{value}\" is not a GalaChain user reference. An eth| reference takes the 40 hex digits of the account with no 0x prefix; write it as \"{expected}\".',\n params: { field: 'string', value: 'string', expected: 'string' },\n },\n INVALID_DECIMAL: {\n phase: 'pre_send',\n template: 'Invalid decimal quantity: {value}',\n params: { value: 'string' },\n },\n\n // ------------------------------------------------------------------------- personal-sign DTOs\n PERSONAL_SIGN_NOT_JSON: {\n phase: 'pre_send',\n template: 'Personal-sign DTO is not valid JSON',\n params: {},\n },\n PERSONAL_SIGN_NOT_OBJECT: {\n phase: 'pre_send',\n template: 'Personal-sign DTO must be a JSON object',\n params: {},\n },\n PERSONAL_SIGN_BAD_PREFIX: {\n phase: 'pre_send',\n template: 'Personal-sign DTO prefix is not an EIP-191 \"Ethereum Signed Message\" header',\n params: {},\n },\n PERSONAL_SIGN_ENVELOPE_FIELDS: {\n phase: 'pre_send',\n template: 'Personal-sign DTO carries signing-envelope field(s): {fields}',\n params: { fields: 'string' },\n },\n PERSONAL_SIGN_NOT_CANONICAL: {\n phase: 'pre_send',\n template: 'Personal-sign DTO is not in canonical serialized form',\n params: {},\n },\n\n // ------------------------------------------------------------------ EIP-712 payload derivation\n EIP712_NAME_COLLISION: {\n phase: 'pre_send',\n template: 'Name collisions are not supported when deriving EIP-712 types ({name}).',\n params: { name: 'string' },\n },\n EIP712_UNSUPPORTED_VALUE: {\n phase: 'pre_send',\n template: 'Unsupported EIP-712 value of type {valueType}.',\n params: { valueType: 'string' },\n },\n\n // ----------------------------------------------------------------------------- EIP-712 typed data\n TYPED_DATA_NOT_STRING: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be a string',\n params: { what: 'string' },\n },\n TYPED_DATA_UNPAIRED_SURROGATE: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} has an unpaired surrogate',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_HEX_BYTES: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be an even-length 0x hex string',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_SAFE_INTEGER: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be a safe integer',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_INTEGER: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be an integer',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_BOOLEAN: {\n phase: 'pre_send',\n template: 'Invalid typed data: bool must be a boolean',\n params: {},\n },\n TYPED_DATA_BAD_ADDRESS: {\n phase: 'pre_send',\n template: 'Invalid typed data: address must be 0x followed by 40 hex digits',\n params: {},\n },\n TYPED_DATA_BAD_CHECKSUM: {\n phase: 'pre_send',\n template: 'Invalid typed data: address has a bad checksum',\n params: {},\n },\n TYPED_DATA_BYTES_LENGTH: {\n phase: 'pre_send',\n template: 'Invalid typed data: {type} must be exactly {width} bytes',\n params: { type: 'string', width: 'number' },\n },\n TYPED_DATA_OUT_OF_BOUNDS: {\n phase: 'pre_send',\n template: 'Invalid typed data: value out of bounds for {type}',\n params: { type: 'string' },\n },\n TYPED_DATA_UNSUPPORTED_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: unsupported type \"{type}\"',\n params: { type: 'string' },\n },\n TYPED_DATA_FIELDS_NOT_LIST: {\n phase: 'pre_send',\n template: 'Invalid typed data: type {typeName} must be a list of fields',\n params: { typeName: 'string' },\n },\n TYPED_DATA_FIELD_MALFORMED: {\n phase: 'pre_send',\n template: 'Invalid typed data: type {typeName} has a field without a string name and type',\n params: { typeName: 'string' },\n },\n TYPED_DATA_INVALID_FIELD_NAME: {\n phase: 'pre_send',\n template: 'Invalid typed data: invalid field name \"{name}\"',\n params: { name: 'string' },\n },\n TYPED_DATA_DUPLICATE_FIELD: {\n phase: 'pre_send',\n template: 'Invalid typed data: duplicate field \"{name}\" in {typeName}',\n params: { name: 'string', typeName: 'string' },\n },\n TYPED_DATA_INVALID_TYPE_NAME: {\n phase: 'pre_send',\n template: 'Invalid typed data: invalid type name \"{name}\"',\n params: { name: 'string' },\n },\n TYPED_DATA_CIRCULAR_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: circular type reference in {typeName}',\n params: { typeName: 'string' },\n },\n TYPED_DATA_UNKNOWN_FIELD_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: unknown type \"{type}\" in {typeName}',\n params: { type: 'string', typeName: 'string' },\n },\n TYPED_DATA_NO_PRIMARY_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: missing primary type',\n params: {},\n },\n TYPED_DATA_AMBIGUOUS_PRIMARY_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: ambiguous primary types or unused types ({roots})',\n params: { roots: 'string' },\n },\n TYPED_DATA_ARRAY_EXPECTED: {\n phase: 'pre_send',\n template: 'Invalid typed data: {type} array value must be an array',\n params: { type: 'string' },\n },\n TYPED_DATA_ARRAY_LENGTH_MISMATCH: {\n phase: 'pre_send',\n template: 'Invalid typed data: array length mismatch',\n params: {},\n },\n TYPED_DATA_STRUCT_NOT_OBJECT: {\n phase: 'pre_send',\n template: 'Invalid typed data: {typeName} value must be an object',\n params: { typeName: 'string' },\n },\n TYPED_DATA_MISSING_FIELD: {\n phase: 'pre_send',\n template: 'Invalid typed data: {typeName} value is missing field \"{field}\"',\n params: { typeName: 'string', field: 'string' },\n },\n TYPED_DATA_DOMAIN_NOT_OBJECT: {\n phase: 'pre_send',\n template: 'Invalid typed data: domain must be an object',\n params: {},\n },\n TYPED_DATA_INVALID_DOMAIN_KEY: {\n phase: 'pre_send',\n template: 'Invalid typed data: invalid typed-data domain key {key}',\n params: { key: 'string' },\n },\n\n // ---------------------------------------------------------------------------------- unique keys\n INVALID_UNIQUE_KEY: {\n phase: 'pre_send',\n template:\n 'The uniqueKey \"{uniqueKey}\" must be 1-128 characters of A-Z, a-z, 0-9, \".\", \"_\", \":\" or \"-\".',\n params: { uniqueKey: 'string' },\n },\n INVALID_UNIQUE_KEY_PREFIX: {\n phase: 'pre_send',\n template:\n 'uniqueKeyPrefix \"{uniqueKeyPrefix}\" must be at most {maxLength} characters of A-Z, a-z, 0-9, \".\", \"_\", \":\" or \"-\".',\n params: { uniqueKeyPrefix: 'string', maxLength: 'number' },\n },\n CSPRNG_UNAVAILABLE: {\n phase: 'pre_send',\n template:\n 'No cryptographically secure random source (globalThis.crypto.getRandomValues) is available to mint a uniqueKey or a new wallet; install a getRandomValues polyfill (react-native-get-random-values on Hermes).',\n params: {},\n },\n\n // ----------------------------------------------------------------------------- gateway writes\n INVALID_WRITES_OPTION: {\n phase: 'pre_send',\n template: 'GatewayWrites option {option} is missing or is not of the expected type.',\n params: { option: GATEWAY_WRITES_OPTIONS },\n },\n INVALID_QUANTITY: {\n phase: 'pre_send',\n template:\n '{field} must be a positive decimal number of whole tokens, written as a string (got \"{value}\").',\n params: { field: 'string', value: 'string' },\n },\n INVALID_TOKEN_REFERENCE: {\n phase: 'pre_send',\n template: 'Invalid token reference {field}: {reason}.',\n params: { field: 'string', reason: INVALID_TOKEN_REFERENCE_REASONS },\n },\n INVALID_TOKEN_BATCH: {\n phase: 'pre_send',\n template: '{method} takes 1 to {max} tokens (got {count}).',\n params: { method: 'string', count: 'number', max: 'number' },\n },\n INVALID_LOCK_EXPIRES: {\n phase: 'pre_send',\n template:\n 'expires must be a non-negative whole number of epoch milliseconds, 0 for none (got {value}).',\n params: { value: 'string' },\n },\n INVALID_LOCK_NAME: {\n phase: 'pre_send',\n template: 'The lock name must be a string (got a {valueType}).',\n params: { valueType: 'string' },\n },\n NO_TOKEN_NAME_RESOLVER: {\n phase: 'pre_send',\n template:\n 'The token name \"{tokenName}\" cannot be resolved: no tokenNameResolver is configured. Pass its tokenClassKey instead.',\n params: { tokenName: 'string' },\n },\n TOKEN_NAME_RESOLUTION_FAILED: {\n phase: 'pre_send',\n template:\n 'The token name \"{tokenName}\" could not be resolved to a token class key; nothing was sent.',\n params: { tokenName: 'string' },\n },\n GATEWAY_WRITE_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'The outcome of {method} is unknown ({reason}): the request may have reached the gateway. Check the write by its uniqueKey before sending it again.',\n params: { method: 'string', reason: GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS },\n },\n GATEWAY_HTTP_ERROR: {\n phase: 'post_send',\n template: 'The gateway answered {method} with HTTP {status}.',\n params: { method: 'string', status: 'number', serverMessage: 'string' },\n unrendered: ['serverMessage'],\n },\n GATEWAY_WRITE_REJECTED: {\n phase: 'post_send',\n template: 'GalaChain rejected {method} (Status {chainStatus}, error key \"{errorKey}\").',\n params: {\n method: 'string',\n chainStatus: 'number',\n errorKey: 'string',\n serverMessage: 'string',\n },\n unrendered: ['serverMessage'],\n },\n GATEWAY_RESPONSE_INVALID: {\n phase: 'post_send',\n template:\n 'The gateway answered {method} with something that is not a GalaChain result; the write may have been applied.',\n params: { method: 'string' },\n },\n\n // ------------------------------------------------------------------------------ gateway reads\n INVALID_READS_OPTION: {\n phase: 'pre_send',\n template: 'GatewayReads option {option} is missing or is not of the expected type.',\n params: { option: GATEWAY_READS_OPTIONS },\n },\n INVALID_PAGE_REQUEST: {\n phase: 'pre_send',\n template:\n '{field} is not valid for a paginated read (got {value}): a page size or page count is a whole number from 1 to 10000, a bookmark a string.',\n params: { field: PAGE_REQUEST_FIELDS, value: 'string' },\n },\n GATEWAY_READ_REJECTED: {\n phase: 'post_send',\n template: 'GalaChain refused {method} (Status {chainStatus}, error key \"{errorKey}\").',\n params: {\n method: 'string',\n chainStatus: 'number',\n errorKey: 'string',\n serverMessage: 'string',\n },\n unrendered: ['serverMessage'],\n },\n GATEWAY_READ_RESPONSE_INVALID: {\n phase: 'post_send',\n template: 'The gateway answered {method} with something that is not a usable GalaChain result.',\n params: { method: 'string' },\n },\n TOKEN_CLASS_NOT_FOUND: {\n phase: 'post_send',\n template: 'GalaChain has no token class {tokenClassKey}.',\n params: { tokenClassKey: 'string' },\n },\n PAGINATION_LIMIT_EXCEEDED: {\n phase: 'post_send',\n template:\n 'Reading every page of {method} takes more than {maxPages} pages; narrow the filter or raise maxPages.',\n params: { method: 'string', maxPages: 'number' },\n },\n\n // ------------------------------------------------------------- wallet providers (`./providers`)\n WALLET_NOT_CONNECTED: {\n phase: 'pre_send',\n template: 'The wallet is not connected ({reason}): connect it before {operation}.',\n params: { reason: WALLET_NOT_CONNECTED_REASONS, operation: 'string' },\n },\n WALLET_CONNECTION_FAILED: {\n phase: 'pre_send',\n template: 'Connecting to the wallet failed ({reason}).',\n params: { reason: WALLET_CONNECTION_FAILURE_REASONS },\n },\n INVALID_WALLET_PROVIDER_CONFIG: {\n phase: 'pre_send',\n template: 'A wallet provider cannot be built without {missing}.',\n params: { missing: WALLET_PROVIDER_CONFIG_MISSING },\n },\n PRIVATE_KEY_NOT_ACCESSIBLE: {\n phase: 'pre_send',\n template:\n 'This wallet provider signs in the wallet and cannot give out a private key; only a PrivateKeyProvider holds one.',\n params: {},\n },\n\n // ----------------------------------------------------------------------------- wallet helpers\n INVALID_WALLET_INPUT: {\n phase: 'pre_send',\n template:\n 'The wallet input was refused ({reason}): give a private key (64 hex digits) or a 12- or 24-word mnemonic.',\n params: { reason: WALLET_INPUT_PROBLEMS },\n },\n\n // ------------------------------------------------------------------------ bridge (`./bridge`)\n INVALID_BRIDGE_AMOUNT: {\n phase: 'pre_send',\n template: 'The bridge amount \"{value}\" was refused ({reason}).',\n params: { value: 'string', reason: BRIDGE_AMOUNT_PROBLEMS },\n },\n UNSUPPORTED_BRIDGE_TOKEN: {\n phase: 'pre_send',\n template: '{symbol} cannot be bridged with {network}.',\n params: { network: 'string', symbol: 'string' },\n },\n BRIDGE_NOT_CONFIGURED: {\n phase: 'pre_send',\n template:\n '{network} bridging is not configured: give the bridge a {network} private key (ethereumPrivateKey / solanaPrivateKey).',\n params: { network: BRIDGE_NETWORKS },\n },\n INVALID_TRANSACTION_HASH: {\n phase: 'pre_send',\n template: '\"{value}\" is not a {network} transaction hash.',\n params: { network: BRIDGE_NETWORKS, value: 'string' },\n },\n INVALID_BRIDGE_OPTION: {\n phase: 'pre_send',\n template: 'The bridge option {option} is missing or out of range.',\n params: { option: 'string' },\n },\n BRIDGE_RESPONSE_INVALID: {\n phase: 'post_send',\n template:\n 'GalaConnect answered {method} without a usable {missing}; the request may have been accepted.',\n params: { method: 'string', missing: 'string' },\n },\n BRIDGE_READ_RESPONSE_INVALID: {\n phase: 'post_send',\n template: 'GalaConnect answered {method} with something that is not a usable result.',\n params: { method: 'string' },\n },\n BRIDGE_WRITE_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'The outcome of {method} is unknown: the request failed in transit and may have reached GalaConnect. Check it before sending it again.',\n params: { method: 'string' },\n },\n GALACONNECT_HTTP_ERROR: {\n phase: 'post_send',\n template: 'GalaConnect answered {method} with HTTP {status}.',\n params: { method: 'string', status: 'number', serverMessage: 'string' },\n unrendered: ['serverMessage'],\n },\n BRIDGE_TOKEN_NOT_FOUND: {\n phase: 'post_send',\n template: 'GalaConnect has no verified bridge configuration for {symbol}.',\n params: { symbol: 'string' },\n },\n TOKEN_NOT_WRAPPABLE: {\n phase: 'post_send',\n template: '{tokenId} cannot be wrapped or unwrapped ({reason}).',\n params: { tokenId: 'string', reason: WRAP_REFUSAL_REASONS },\n },\n INVALID_WRAP_DIRECTION: {\n phase: 'pre_send',\n template:\n 'Cannot {direction} {symbol}: it is on the wrong channel for it (use the other direction).',\n params: { symbol: 'string', direction: WRAP_DIRECTIONS },\n },\n BRIDGE_REQUEST_REJECTED: {\n phase: 'post_send',\n template: 'GalaChain refused {method} (Status {chainStatus}, error key \"{errorKey}\").',\n params: {\n method: 'string',\n chainStatus: 'number',\n errorKey: 'string',\n serverMessage: 'string',\n },\n unrendered: ['serverMessage'],\n },\n BRIDGE_OUT_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'GalaConnect accepted the bridge-out request, which may have locked the tokens, then the bridge-out failed at {step}. Check it before bridging again.',\n params: { step: BRIDGE_OUT_STEPS, bridgeRequestId: 'string' },\n unrendered: ['bridgeRequestId'],\n },\n BRIDGE_DEPOSIT_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'The {network} bridge deposit may have been sent, then its {step} failed. Check the deposit before sending another.',\n params: { network: BRIDGE_NETWORKS, step: BRIDGE_DEPOSIT_STEPS, transactionHash: 'string' },\n unrendered: ['transactionHash'],\n },\n BRIDGE_CHAIN_READ_FAILED: {\n phase: 'post_send',\n template: 'The {network} read {call} failed or answered something unusable; nothing was sent.',\n params: { network: BRIDGE_NETWORKS, call: 'string' },\n },\n INSUFFICIENT_BRIDGE_BALANCE: {\n phase: 'pre_send',\n template: 'The {network} balance of {symbol} is {available}; the bridge needs {needed}.',\n params: { network: BRIDGE_NETWORKS, symbol: 'string', needed: 'string', available: 'string' },\n },\n BRIDGE_STATUS_TIMEOUT: {\n phase: 'in_flight',\n template:\n 'The bridge transaction did not reach a final status within {timeoutMs} ms (last status {lastStatus}); it may still complete.',\n params: { transactionHash: 'string', timeoutMs: 'number', lastStatus: 'number' },\n unrendered: ['transactionHash'],\n },\n\n // ------------------------------------------------------------------- React context (`./react`)\n WALLET_CONTEXT_MISSING: {\n phase: 'pre_send',\n template: 'The wallet hooks and the wallet context need a WalletProvider above them.',\n params: {},\n },\n} as const satisfies Record<string, GalaErrorCatalogEntry>;\n\n/** Every error code the core SDK can throw. */\nexport type GalaErrorCode = keyof typeof GALA_ERROR_CATALOG;\n\ninterface KindToType {\n string: string;\n number: number;\n boolean: boolean;\n}\n\n/** The value type of a param kind: a primitive, or the union of a closed set's members. */\ntype ParamValue<K> = K extends readonly (infer Member)[]\n ? Member\n : K extends keyof KindToType\n ? KindToType[K]\n : never;\n\n/**\n * The named params of code `C` of ANY catalog object (`typeof SOME_CATALOG`): a flat object of\n * primitives (or closed string tokens). A product SDK derives its own params type from its\n * catalog with it, so every catalog types its params the same way.\n */\nexport type ErrorParamsOf<\n Catalog extends Readonly<Record<string, GalaErrorCatalogEntry>>,\n C extends keyof Catalog,\n> = {\n readonly [P in keyof Catalog[C]['params']]: ParamValue<Catalog[C]['params'][P]>;\n};\n\n/** The named params of one core error code. */\nexport type GalaErrorParams<C extends GalaErrorCode> = ErrorParamsOf<typeof GALA_ERROR_CATALOG, C>;\n\n/**\n * The English template of every core error code, `{placeholder}` markers included. An optional\n * seed or fallback for an app's own translations; the SDK's `message` is generated from it. A\n * product SDK exports the templates of its own codes next to it.\n */\nexport const galaErrorTemplates: { readonly [C in GalaErrorCode]: string } = Object.fromEntries(\n Object.entries(GALA_ERROR_CATALOG).map(([code, entry]) => [code, entry.template]),\n) as { readonly [C in GalaErrorCode]: string };\n\nconst PLACEHOLDER = /\\{([A-Za-z0-9_]+)\\}/gu;\n\n/** Fills a template's `{placeholders}` from `params`; an unknown placeholder is left as written. */\nexport function renderGalaErrorTemplate(\n template: string,\n params: Readonly<Record<string, unknown>>,\n): string {\n return template.replace(PLACEHOLDER, (whole, name: string) => {\n const value = params[name];\n return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'\n ? String(value)\n : whole;\n });\n}\n\n/** The placeholder names a template uses, in order of first appearance. */\nexport function templatePlaceholders(template: string): string[] {\n return [...new Set([...template.matchAll(PLACEHOLDER)].map((match) => match[1] as string))];\n}\n"],"mappings":"AA6DA,MAAaA,EAA8B,CACzC,eACA,eACA,eACA,iBACF,EAeaC,EAA0B,CAAC,gBAAiB,QAAQ,EAiBpDC,EAAkC,CAC7C,UACA,YACA,gBACA,cACF,EAWaC,EAAyB,CACpC,SACA,iBACA,gBACA,mBACF,EAcaC,EAAwC,CAAC,UAAW,WAAW,EAU/DC,EAAwB,CAAC,iBAAkB,eAAe,EAY1DC,EAAsB,CAAC,QAAS,WAAY,WAAY,UAAU,EAclEC,EAA+B,CAC1C,gBACA,eACA,cACF,EAYaC,EAAoC,CAC/C,cACA,gBACA,QACF,EAYaC,EAAiC,CAC5C,mBACA,iCACF,EAeaC,EAAwB,CACnC,QACA,sBACA,wBACA,mBACF,EAMaC,EAAkB,CAAC,WAAY,QAAQ,EAYvCC,EAAyB,CACpC,eACA,eACA,mBACF,EAaaC,EAAmB,CAAC,aAAc,mBAAoB,kBAAkB,EAYxEC,EAAuB,CAAC,OAAQ,eAAgB,cAAc,EAY9DC,EAAuB,CAAC,aAAc,iBAAkB,iBAAiB,EAMzEC,EAAkB,CAAC,OAAQ,QAAQ,EAMnCC,EAAqB,CAEhC,gBAAiB,CACf,MAAO,YACP,SAAU,mDACV,OAAQ,CAAE,IAAK,SAAU,UAAW,QAA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AC9F,EACA,sBAAuB,CACrB,MAAO,YACP,SACE,+HACF,OAAQ,CAAE,gBAAiB,SAAU,UAAW,SAAU,WAAY,QAAS,EAC/E,WAAY,CAAC,iBAAiB,CAChC,EAGA,uBAAwB,CACtB,MAAO,WACP,SAAU,4EACV,OAAQ,CAAC,CACX,CACF,EAsCaO,EAAgE,OAAO,YAClF,OAAO,QAAQD,CAAkB,CAAC,CAAC,KAAK,CAACE,EAAMC,KAAW,CAACD,EAAMC,EAAM,QAAQ,CAAC,CAClF,EAEMC,EAAc,wBAGpB,SAAgBC,EACd,EACA,EACQ,CACR,OAAOC,EAAS,QAAQF,GAAc,EAAO,IAAiB,CAC5D,IAAMG,EAAQC,EAAOC,GACrB,OAAO,OAAOF,GAAU,UAAY,OAAOA,GAAU,UAAY,OAAOA,GAAU,UAC9E,OAAOA,CAAK,EACZG,CACN,CAAC,CACH,CAGA,SAAgBC,EAAqB,EAA4B,CAC/D,MAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAGL,EAAS,SAASF,CAAW,CAAC,CAAC,CAAC,IAAK,GAAUQ,EAAM,EAAY,CAAC,CAAC,CAC5F"}
1
+ {"version":3,"file":"error_catalog.js","names":["INVALID_PRIVATE_KEY_REASONS","SIGNING_FAILURE_REASONS","INVALID_TOKEN_REFERENCE_REASONS","GATEWAY_WRITES_OPTIONS","GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS","GATEWAY_READS_OPTIONS","PAGE_REQUEST_FIELDS","WALLET_NOT_CONNECTED_REASONS","WALLET_CONNECTION_FAILURE_REASONS","WALLET_PROVIDER_CONFIG_MISSING","WALLET_INPUT_PROBLEMS","BRIDGE_NETWORKS","BRIDGE_AMOUNT_PROBLEMS","BRIDGE_OUT_STEPS","BRIDGE_DEPOSIT_STEPS","WRAP_REFUSAL_REASONS","WRAP_DIRECTIONS","GALA_ERROR_CATALOG","galaErrorTemplates","code","entry","PLACEHOLDER","renderGalaErrorTemplate","template","value","params","name","whole","templatePlaceholders","match"],"sources":["../../../src/classes/error_catalog.ts"],"sourcesContent":["/**\n * The catalog of every error `@gala-chain/gala-core-sdk` throws: the SINGLE source of truth for\n * its `code`, the named parameters it carries and the English template its `message` is generated\n * from. A product SDK (gswap-sdk, launchpad-sdk) keeps its OWN catalog of the codes only it throws,\n * and its error class (a subclass of `GalaSDKError`) reads both; no code is defined twice.\n *\n * - `code` is the only discriminator. It is stable: apps branch on it, never on message text.\n * - `params` are the named placeholders of the error: a flat object of primitives (string,\n * number, boolean) that an app feeds to its own localization (i18next, ICU, FormatJS).\n * Raw server payloads are never params (they are `error.body` / `error.bodyText`), and no\n * secret (private key, signature, raw DTO) ever is.\n * - `template` is English with `{placeholder}` markers. `error.message` is generated from it\n * and the params, so the two cannot drift. It is for logs and developers: it is not stable and\n * must not be shown to users or matched on.\n *\n * Every placeholder in a template is a declared param and every declared param is a placeholder,\n * except the few `unrendered` params that carry server text for the app and are kept out of\n * `message` on purpose (pinned by tests/error_catalog.test.ts). Facts that are not placeholders\n * (HTTP status, URL, `uniqueKey`, transaction ids, the raw body, the cause) are typed properties of\n * the error, see {@link GalaErrorContext}.\n */\n\nimport type { GalaErrorPhase } from './error_phases.js';\n\n/**\n * The kinds a param can have: a primitive, or a CLOSED set of string tokens (a readonly tuple).\n * A closed set is a documented union: an app maps each member to its own text and can check that\n * it covered all of them, and a new member is a compile error until it does.\n */\nexport type GalaErrorParamKind = 'string' | 'number' | 'boolean' | readonly string[];\n\n/** One catalog entry (of this catalog, or of a product SDK's own catalog). */\nexport interface GalaErrorCatalogEntry {\n /** The phase this code is thrown in, unless a throw site says otherwise (see {@link GalaErrorPhase}). */\n readonly phase: GalaErrorPhase;\n /** English message template with `{placeholder}` markers. */\n readonly template: string;\n /** Param name to kind. Every param is required and appears in the template, except `unrendered`. */\n readonly params: Readonly<Record<string, GalaErrorParamKind>>;\n /**\n * Params that are carried for the app but deliberately NOT placeholders of the template. Used\n * for `serverMessage` on the codes whose failing answer may be anything (a proxy's page, a\n * validation list): the server's text is data for the app to relay or ignore, and keeping it out\n * of `message` means it cannot reach a log line or a user interface by accident.\n */\n readonly unrendered?: readonly string[];\n}\n\n/**\n * Why a private key was refused (`INVALID_PRIVATE_KEY.params.reason`). A token for the app to map\n * to its own text, never English and never any part of the key.\n *\n * - `wrong_length`: raw bytes that are not 32 bytes long (a `./bridge` Solana secret key: not 64\n * bytes once decoded).\n * - `bad_encoding`: a string that is neither 64 hex characters (optionally `0x`-prefixed, 63 is\n * left-padded) nor a 44-character base64 string (`./bridge`: an Ethereum key that is not `0x`\n * and 64 hex characters; a Solana secret key that is not base58, or whose public half does not\n * match its secret half).\n * - `not_on_curve`: 32 bytes that are not a valid secp256k1 secret scalar.\n * - `no_key_provided`: a lazy key provider returned something that is not a string.\n */\nexport const INVALID_PRIVATE_KEY_REASONS = [\n 'wrong_length',\n 'bad_encoding',\n 'not_on_curve',\n 'no_key_provided',\n] as const;\n\n/** One member of {@link INVALID_PRIVATE_KEY_REASONS}. */\nexport type InvalidPrivateKeyReason = (typeof INVALID_PRIVATE_KEY_REASONS)[number];\n\n/**\n * Why a signer could not produce a signature (`SIGNING_FAILED.params.reason`). A token for the\n * app to map to its own text.\n *\n * - `user_rejected`: the person declined in their wallet (an EIP-1193 `4001`, an ethers\n * `ACTION_REJECTED`, or a wallet that words it \"User rejected/denied ...\"). Nothing is wrong:\n * they may simply try again.\n * - `failed`: anything else the signer threw (a locked wallet, an unreachable extension, a wallet\n * that refused). The original error is `cause`.\n */\nexport const SIGNING_FAILURE_REASONS = ['user_rejected', 'failed'] as const;\n\n/** One member of {@link SIGNING_FAILURE_REASONS}. */\nexport type SigningFailureReason = (typeof SIGNING_FAILURE_REASONS)[number];\n\n/**\n * Why a gateway write refused the token it was asked to move\n * (`INVALID_TOKEN_REFERENCE.params.reason`). A token for the app to map to its own text.\n *\n * - `missing`: neither `tokenClassKey` nor `tokenName` was given.\n * - `ambiguous`: more than one way of naming the token was given (`tokenClassKey` and\n * `tokenName`, or a `tokenName` with an `instance`: a resolved name decides its own instance).\n * - `bad_class_key`: `tokenClassKey` is not a class key: a pipe string needs exactly four\n * non-empty parts, a `$` string at least four (split from the right), an object four non-empty\n * strings. A bare symbol is never a class key and none is derived from it.\n * - `bad_instance`: `instance` is not a string of decimal digits.\n */\nexport const INVALID_TOKEN_REFERENCE_REASONS = [\n 'missing',\n 'ambiguous',\n 'bad_class_key',\n 'bad_instance',\n] as const;\n\n/** One member of {@link INVALID_TOKEN_REFERENCE_REASONS}. */\nexport type InvalidTokenReferenceReason = (typeof INVALID_TOKEN_REFERENCE_REASONS)[number];\n\n/**\n * The `GatewayWrites` options that are refused when missing or of the wrong type\n * (`INVALID_WRITES_OPTION.params.option`). `walletAddress`, `requestTimeoutMs` and\n * `uniqueKeyPrefix` have codes of their own (`INVALID_WALLET_ADDRESS`, `INVALID_TIMEOUT`,\n * `INVALID_UNIQUE_KEY_PREFIX`).\n */\nexport const GATEWAY_WRITES_OPTIONS = [\n 'signer',\n 'gatewayBaseUrl',\n 'httpRequestor',\n 'tokenNameResolver',\n] as const;\n\n/** One member of {@link GATEWAY_WRITES_OPTIONS}. */\nexport type GatewayWritesOption = (typeof GATEWAY_WRITES_OPTIONS)[number];\n\n/**\n * Why the outcome of a gateway write is unknown (`GATEWAY_WRITE_OUTCOME_UNKNOWN.params.reason`).\n * Both say the same thing about the write (it MAY have been applied: never send it again under a\n * fresh key, check `error.uniqueKey` instead) and differ only in what happened to the request.\n *\n * - `timeout`: the POST exceeded `requestTimeoutMs`; the request may still be running.\n * - `transport`: the POST failed before an answer was read (offline, connection reset, DNS, CORS,\n * a body that broke off). The bytes may have reached the gateway.\n */\nexport const GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS = ['timeout', 'transport'] as const;\n\n/** One member of {@link GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS}. */\nexport type GatewayWriteOutcomeUnknownReason =\n (typeof GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS)[number];\n\n/**\n * The `GatewayReads` options that are refused when missing or of the wrong type\n * (`INVALID_READS_OPTION.params.option`). `requestTimeoutMs` has its own code (`INVALID_TIMEOUT`).\n */\nexport const GATEWAY_READS_OPTIONS = ['gatewayBaseUrl', 'httpRequestor'] as const;\n\n/** One member of {@link GATEWAY_READS_OPTIONS}. */\nexport type GatewayReadsOption = (typeof GATEWAY_READS_OPTIONS)[number];\n\n/**\n * The part of a paginated read that was refused (`INVALID_PAGE_REQUEST.params.field`):\n *\n * - `limit` / `pageSize`: results per page, a whole number from 1 to 10 000;\n * - `maxPages`: how many pages a `fetchAll...` read may walk, a whole number from 1 to 10 000;\n * - `bookmark`: the previous page's `nextPageBookmark`, a string.\n */\nexport const PAGE_REQUEST_FIELDS = ['limit', 'pageSize', 'maxPages', 'bookmark'] as const;\n\n/** One member of {@link PAGE_REQUEST_FIELDS}. */\nexport type PageRequestField = (typeof PAGE_REQUEST_FIELDS)[number];\n\n/**\n * Why a wallet provider is not connected (`WALLET_NOT_CONNECTED.params.reason`):\n *\n * - `not_connected`: `connect()` was never called, or `disconnect()` was;\n * - `disconnected`: the wallet reported it is disconnected (EIP-1193 `4900` / `4901`, a\n * `disconnect` event, or an `accountsChanged` with no account);\n * - `unauthorized`: the wallet refused the account (EIP-1193 `4100`): the person has not granted\n * this app access to it.\n */\nexport const WALLET_NOT_CONNECTED_REASONS = [\n 'not_connected',\n 'disconnected',\n 'unauthorized',\n] as const;\n\n/** One member of {@link WALLET_NOT_CONNECTED_REASONS}. */\nexport type WalletNotConnectedReason = (typeof WALLET_NOT_CONNECTED_REASONS)[number];\n\n/**\n * Why connecting a wallet provider failed (`WALLET_CONNECTION_FAILED.params.reason`):\n *\n * - `no_accounts`: the wallet answered `eth_requestAccounts` with no account;\n * - `user_rejected`: the person declined the connection in their wallet (EIP-1193 `4001`);\n * - `failed`: anything else the wallet threw (the original error is `cause`).\n */\nexport const WALLET_CONNECTION_FAILURE_REASONS = [\n 'no_accounts',\n 'user_rejected',\n 'failed',\n] as const;\n\n/** One member of {@link WALLET_CONNECTION_FAILURE_REASONS}. */\nexport type WalletConnectionFailureReason = (typeof WALLET_CONNECTION_FAILURE_REASONS)[number];\n\n/**\n * What a wallet provider was built without (`INVALID_WALLET_PROVIDER_CONFIG.params.missing`):\n *\n * - `eip1193_provider`: an `ExternalWalletProvider` / `GalaWalletProvider` needs the wallet's\n * provider object (`window.ethereum`, an EIP-6963 announcement, `window.gala`);\n * - `private_key_or_eip1193_provider`: `createWalletProvider` needs one of the two.\n */\nexport const WALLET_PROVIDER_CONFIG_MISSING = [\n 'eip1193_provider',\n 'private_key_or_eip1193_provider',\n] as const;\n\n/** One member of {@link WALLET_PROVIDER_CONFIG_MISSING}. */\nexport type WalletProviderConfigMissing = (typeof WALLET_PROVIDER_CONFIG_MISSING)[number];\n\n/**\n * Why `createWallet` refused its input (`INVALID_WALLET_INPUT.params.reason`), never naming any part\n * of it (it may be a key or a mnemonic):\n *\n * - `empty`: nothing but whitespace;\n * - `unrecognized_format`: neither 64 hex digits nor 12 / 24 words of letters;\n * - `unknown_mnemonic_word`: a word that is not in the BIP-39 English wordlist;\n * - `mnemonic_checksum`: every word is known but the phrase's checksum is wrong (a typo or a\n * swapped word).\n */\nexport const WALLET_INPUT_PROBLEMS = [\n 'empty',\n 'unrecognized_format',\n 'unknown_mnemonic_word',\n 'mnemonic_checksum',\n] as const;\n\n/** One member of {@link WALLET_INPUT_PROBLEMS}. */\nexport type WalletInputProblem = (typeof WALLET_INPUT_PROBLEMS)[number];\n\n/** The external networks `./bridge` bridges to and from. */\nexport const BRIDGE_NETWORKS = ['Ethereum', 'Solana'] as const;\n\n/** One member of {@link BRIDGE_NETWORKS}. */\nexport type BridgeNetwork = (typeof BRIDGE_NETWORKS)[number];\n\n/**\n * Why a bridge amount was refused (`INVALID_BRIDGE_AMOUNT.params.reason`):\n *\n * - `not_a_number`: not a finite decimal number;\n * - `not_positive`: zero or negative (a bridge of nothing only wastes the fee);\n * - `too_many_decimals`: more decimal places than the token has (it would be rounded).\n */\nexport const BRIDGE_AMOUNT_PROBLEMS = [\n 'not_a_number',\n 'not_positive',\n 'too_many_decimals',\n] as const;\n\n/** One member of {@link BRIDGE_AMOUNT_PROBLEMS}. */\nexport type BridgeAmountProblem = (typeof BRIDGE_AMOUNT_PROBLEMS)[number];\n\n/**\n * Where a bridge-out failed AFTER GalaConnect accepted its `RequestTokenBridgeOut`\n * (`BRIDGE_OUT_OUTCOME_UNKNOWN.params.step`):\n *\n * - `request_id`: the answer had no bridge request id;\n * - `bridge_token_out`: the `BridgeTokenOut` call failed;\n * - `transaction_hash`: the `BridgeTokenOut` answer had no transaction hash.\n */\nexport const BRIDGE_OUT_STEPS = ['request_id', 'bridge_token_out', 'transaction_hash'] as const;\n\n/** One member of {@link BRIDGE_OUT_STEPS}. */\nexport type BridgeOutStep = (typeof BRIDGE_OUT_STEPS)[number];\n\n/**\n * Where a bridge-in deposit failed once it was being sent (`BRIDGE_DEPOSIT_OUTCOME_UNKNOWN.params.step`):\n *\n * - `send`: sending the deposit transaction failed (it may have reached the network);\n * - `confirmation`: the deposit was sent and its confirmation failed or is unknown;\n * - `registration`: the deposit is confirmed and registering it with GalaConnect failed.\n */\nexport const BRIDGE_DEPOSIT_STEPS = ['send', 'confirmation', 'registration'] as const;\n\n/** One member of {@link BRIDGE_DEPOSIT_STEPS}. */\nexport type BridgeDepositStep = (typeof BRIDGE_DEPOSIT_STEPS)[number];\n\n/**\n * Why a token cannot be wrapped or unwrapped (`TOKEN_NOT_WRAPPABLE.params.reason`):\n *\n * - `not_listed`: the wrappable token list does not have it;\n * - `no_counterpart`: the token it wraps to / unwraps from is not listed;\n * - `unknown_channel`: its channel (or its counterpart's) is not one a wrap moves between.\n */\nexport const WRAP_REFUSAL_REASONS = ['not_listed', 'no_counterpart', 'unknown_channel'] as const;\n\n/** One member of {@link WRAP_REFUSAL_REASONS}. */\nexport type WrapRefusalReason = (typeof WRAP_REFUSAL_REASONS)[number];\n\n/** The two cross-channel directions (`INVALID_WRAP_DIRECTION.params.direction`). */\nexport const WRAP_DIRECTIONS = ['wrap', 'unwrap'] as const;\n\n/** One member of {@link WRAP_DIRECTIONS}. */\nexport type WrapDirection = (typeof WRAP_DIRECTIONS)[number];\n\n/** The whole core catalog. Add a code here before throwing it anywhere in this package. */\nexport const GALA_ERROR_CATALOG = {\n // ---------------------------------------------------------------------------------- transport\n REQUEST_TIMEOUT: {\n phase: 'in_flight',\n template: 'Request to {url} timed out after {timeoutMs} ms.',\n params: { url: 'string', timeoutMs: 'number' },\n },\n TRANSPORT_ERROR: {\n phase: 'in_flight',\n template: 'The request to {url} failed before the server answered.',\n params: { url: 'string' },\n },\n INVALID_TIMEOUT: {\n phase: 'pre_send',\n template:\n '{field} must be a positive number of milliseconds, or Infinity for no timeout (got {value}).',\n params: { field: 'string', value: 'number' },\n },\n\n // ------------------------------------------------------------------------------ wallet / keys\n GALA_WALLET_NOT_AVAILABLE: {\n phase: 'pre_send',\n template: 'Gala wallet is not available. Please ensure the Gala wallet is connected.',\n params: {},\n },\n WALLET_UNAVAILABLE: {\n phase: 'pre_send',\n template: 'No wallet is connected.',\n params: {},\n },\n MALFORMED_WALLET_REQUEST: {\n phase: 'pre_send',\n template: 'Wallet {method} request is malformed.',\n params: { method: 'string' },\n },\n UNSUPPORTED_WALLET_METHOD: {\n phase: 'pre_send',\n template: 'Unsupported wallet method {method}.',\n params: { method: 'string' },\n },\n INVALID_SIGNATURE: {\n phase: 'pre_send',\n template: 'Wallet returned an invalid {scheme} signature.',\n params: { scheme: 'string' },\n },\n INVALID_CHAIN_ID: {\n phase: 'pre_send',\n template: 'Wallet returned an invalid chain id ({chainId}).',\n params: { chainId: 'string' },\n },\n SIGNER_ADDRESS_MISMATCH: {\n phase: 'pre_send',\n template: 'The signing key does not belong to the expected account.',\n params: {},\n },\n INVALID_PRIVATE_KEY: {\n phase: 'pre_send',\n template: 'Invalid private key: {reason}.',\n params: { reason: INVALID_PRIVATE_KEY_REASONS },\n },\n SIGNING_FAILED: {\n phase: 'pre_send',\n template: 'Signing the {method} request failed ({reason}); nothing was sent.',\n params: { method: 'string', reason: SIGNING_FAILURE_REASONS },\n },\n KEY_PROVIDER_FAILED: {\n phase: 'pre_send',\n template: 'The signing key could not be fetched; nothing was sent.',\n params: {},\n },\n INVALID_SIGNING_HASH_LENGTH: {\n phase: 'pre_send',\n template: 'secp256k1 can only sign a 32-byte hash (got {length}).',\n params: { length: 'number' },\n },\n INVALID_WALLET_ADDRESS: {\n phase: 'pre_send',\n template: 'Invalid {field}: \"{value}\" is not an accepted wallet address form.',\n params: { field: 'string', value: 'string' },\n },\n INVALID_ETH_USER_REF_PREFIX: {\n phase: 'pre_send',\n template:\n 'Invalid {field}: \"{value}\" is not a GalaChain user reference. An eth| reference takes the 40 hex digits of the account with no 0x prefix; write it as \"{expected}\".',\n params: { field: 'string', value: 'string', expected: 'string' },\n },\n INVALID_DECIMAL: {\n phase: 'pre_send',\n template: 'Invalid decimal quantity: {value}',\n params: { value: 'string' },\n },\n\n // ------------------------------------------------------------------------- personal-sign DTOs\n PERSONAL_SIGN_NOT_JSON: {\n phase: 'pre_send',\n template: 'Personal-sign DTO is not valid JSON',\n params: {},\n },\n PERSONAL_SIGN_NOT_OBJECT: {\n phase: 'pre_send',\n template: 'Personal-sign DTO must be a JSON object',\n params: {},\n },\n PERSONAL_SIGN_BAD_PREFIX: {\n phase: 'pre_send',\n template: 'Personal-sign DTO prefix is not an EIP-191 \"Ethereum Signed Message\" header',\n params: {},\n },\n PERSONAL_SIGN_ENVELOPE_FIELDS: {\n phase: 'pre_send',\n template: 'Personal-sign DTO carries signing-envelope field(s): {fields}',\n params: { fields: 'string' },\n },\n PERSONAL_SIGN_NOT_CANONICAL: {\n phase: 'pre_send',\n template: 'Personal-sign DTO is not in canonical serialized form',\n params: {},\n },\n\n // ------------------------------------------------------------------ EIP-712 payload derivation\n EIP712_NAME_COLLISION: {\n phase: 'pre_send',\n template: 'Name collisions are not supported when deriving EIP-712 types ({name}).',\n params: { name: 'string' },\n },\n EIP712_UNSUPPORTED_VALUE: {\n phase: 'pre_send',\n template: 'Unsupported EIP-712 value of type {valueType}.',\n params: { valueType: 'string' },\n },\n\n // ----------------------------------------------------------------------------- EIP-712 typed data\n TYPED_DATA_NOT_STRING: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be a string',\n params: { what: 'string' },\n },\n TYPED_DATA_UNPAIRED_SURROGATE: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} has an unpaired surrogate',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_HEX_BYTES: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be an even-length 0x hex string',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_SAFE_INTEGER: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be a safe integer',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_INTEGER: {\n phase: 'pre_send',\n template: 'Invalid typed data: {what} must be an integer',\n params: { what: 'string' },\n },\n TYPED_DATA_NOT_BOOLEAN: {\n phase: 'pre_send',\n template: 'Invalid typed data: bool must be a boolean',\n params: {},\n },\n TYPED_DATA_BAD_ADDRESS: {\n phase: 'pre_send',\n template: 'Invalid typed data: address must be 0x followed by 40 hex digits',\n params: {},\n },\n TYPED_DATA_BAD_CHECKSUM: {\n phase: 'pre_send',\n template: 'Invalid typed data: address has a bad checksum',\n params: {},\n },\n TYPED_DATA_BYTES_LENGTH: {\n phase: 'pre_send',\n template: 'Invalid typed data: {type} must be exactly {width} bytes',\n params: { type: 'string', width: 'number' },\n },\n TYPED_DATA_OUT_OF_BOUNDS: {\n phase: 'pre_send',\n template: 'Invalid typed data: value out of bounds for {type}',\n params: { type: 'string' },\n },\n TYPED_DATA_UNSUPPORTED_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: unsupported type \"{type}\"',\n params: { type: 'string' },\n },\n TYPED_DATA_FIELDS_NOT_LIST: {\n phase: 'pre_send',\n template: 'Invalid typed data: type {typeName} must be a list of fields',\n params: { typeName: 'string' },\n },\n TYPED_DATA_FIELD_MALFORMED: {\n phase: 'pre_send',\n template: 'Invalid typed data: type {typeName} has a field without a string name and type',\n params: { typeName: 'string' },\n },\n TYPED_DATA_INVALID_FIELD_NAME: {\n phase: 'pre_send',\n template: 'Invalid typed data: invalid field name \"{name}\"',\n params: { name: 'string' },\n },\n TYPED_DATA_DUPLICATE_FIELD: {\n phase: 'pre_send',\n template: 'Invalid typed data: duplicate field \"{name}\" in {typeName}',\n params: { name: 'string', typeName: 'string' },\n },\n TYPED_DATA_INVALID_TYPE_NAME: {\n phase: 'pre_send',\n template: 'Invalid typed data: invalid type name \"{name}\"',\n params: { name: 'string' },\n },\n TYPED_DATA_CIRCULAR_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: circular type reference in {typeName}',\n params: { typeName: 'string' },\n },\n TYPED_DATA_UNKNOWN_FIELD_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: unknown type \"{type}\" in {typeName}',\n params: { type: 'string', typeName: 'string' },\n },\n TYPED_DATA_NO_PRIMARY_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: missing primary type',\n params: {},\n },\n TYPED_DATA_AMBIGUOUS_PRIMARY_TYPE: {\n phase: 'pre_send',\n template: 'Invalid typed data: ambiguous primary types or unused types ({roots})',\n params: { roots: 'string' },\n },\n TYPED_DATA_ARRAY_EXPECTED: {\n phase: 'pre_send',\n template: 'Invalid typed data: {type} array value must be an array',\n params: { type: 'string' },\n },\n TYPED_DATA_ARRAY_LENGTH_MISMATCH: {\n phase: 'pre_send',\n template: 'Invalid typed data: array length mismatch',\n params: {},\n },\n TYPED_DATA_STRUCT_NOT_OBJECT: {\n phase: 'pre_send',\n template: 'Invalid typed data: {typeName} value must be an object',\n params: { typeName: 'string' },\n },\n TYPED_DATA_MISSING_FIELD: {\n phase: 'pre_send',\n template: 'Invalid typed data: {typeName} value is missing field \"{field}\"',\n params: { typeName: 'string', field: 'string' },\n },\n TYPED_DATA_DOMAIN_NOT_OBJECT: {\n phase: 'pre_send',\n template: 'Invalid typed data: domain must be an object',\n params: {},\n },\n TYPED_DATA_INVALID_DOMAIN_KEY: {\n phase: 'pre_send',\n template: 'Invalid typed data: invalid typed-data domain key {key}',\n params: { key: 'string' },\n },\n\n // ---------------------------------------------------------------------------------- unique keys\n INVALID_UNIQUE_KEY: {\n phase: 'pre_send',\n template:\n 'The uniqueKey \"{uniqueKey}\" must be 1-128 characters of A-Z, a-z, 0-9, \".\", \"_\", \":\" or \"-\".',\n params: { uniqueKey: 'string' },\n },\n INVALID_UNIQUE_KEY_PREFIX: {\n phase: 'pre_send',\n template:\n 'uniqueKeyPrefix \"{uniqueKeyPrefix}\" must be at most {maxLength} characters of A-Z, a-z, 0-9, \".\", \"_\", \":\" or \"-\".',\n params: { uniqueKeyPrefix: 'string', maxLength: 'number' },\n },\n CSPRNG_UNAVAILABLE: {\n phase: 'pre_send',\n template:\n 'No cryptographically secure random source (globalThis.crypto.getRandomValues) is available to mint a uniqueKey or a new wallet; install a getRandomValues polyfill (react-native-get-random-values on Hermes).',\n params: {},\n },\n\n // ----------------------------------------------------------------------------- gateway writes\n INVALID_WRITES_OPTION: {\n phase: 'pre_send',\n template: 'GatewayWrites option {option} is missing or is not of the expected type.',\n params: { option: GATEWAY_WRITES_OPTIONS },\n },\n INVALID_QUANTITY: {\n phase: 'pre_send',\n template:\n '{field} must be a positive decimal number of whole tokens, written as a string (got \"{value}\").',\n params: { field: 'string', value: 'string' },\n },\n INVALID_TOKEN_REFERENCE: {\n phase: 'pre_send',\n template: 'Invalid token reference {field}: {reason}.',\n params: { field: 'string', reason: INVALID_TOKEN_REFERENCE_REASONS },\n },\n INVALID_TOKEN_BATCH: {\n phase: 'pre_send',\n template: '{method} takes 1 to {max} tokens (got {count}).',\n params: { method: 'string', count: 'number', max: 'number' },\n },\n INVALID_LOCK_EXPIRES: {\n phase: 'pre_send',\n template:\n 'expires must be a non-negative whole number of epoch milliseconds, 0 for none (got {value}).',\n params: { value: 'string' },\n },\n INVALID_LOCK_NAME: {\n phase: 'pre_send',\n template: 'The lock name must be a string (got a {valueType}).',\n params: { valueType: 'string' },\n },\n NO_TOKEN_NAME_RESOLVER: {\n phase: 'pre_send',\n template:\n 'The token name \"{tokenName}\" cannot be resolved: no tokenNameResolver is configured. Pass its tokenClassKey instead.',\n params: { tokenName: 'string' },\n },\n TOKEN_NAME_RESOLUTION_FAILED: {\n phase: 'pre_send',\n template:\n 'The token name \"{tokenName}\" could not be resolved to a token class key; nothing was sent.',\n params: { tokenName: 'string' },\n },\n GATEWAY_WRITE_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'The outcome of {method} is unknown ({reason}): the request may have reached the gateway. Check the write by its uniqueKey before sending it again.',\n params: { method: 'string', reason: GATEWAY_WRITE_OUTCOME_UNKNOWN_REASONS },\n },\n GATEWAY_HTTP_ERROR: {\n phase: 'post_send',\n template: 'The gateway answered {method} with HTTP {status}.',\n params: { method: 'string', status: 'number', serverMessage: 'string' },\n unrendered: ['serverMessage'],\n },\n GATEWAY_WRITE_REJECTED: {\n phase: 'post_send',\n template: 'GalaChain rejected {method} (Status {chainStatus}, error key \"{errorKey}\").',\n params: {\n method: 'string',\n chainStatus: 'number',\n errorKey: 'string',\n serverMessage: 'string',\n },\n unrendered: ['serverMessage'],\n },\n GATEWAY_RESPONSE_INVALID: {\n phase: 'post_send',\n template:\n 'The gateway answered {method} with something that is not a GalaChain result; the write may have been applied.',\n params: { method: 'string' },\n },\n\n // ------------------------------------------------------------------------------ gateway reads\n INVALID_READS_OPTION: {\n phase: 'pre_send',\n template: 'GatewayReads option {option} is missing or is not of the expected type.',\n params: { option: GATEWAY_READS_OPTIONS },\n },\n INVALID_PAGE_REQUEST: {\n phase: 'pre_send',\n template:\n '{field} is not valid for a paginated read (got {value}): a page size or page count is a whole number from 1 to 10000, a bookmark a string.',\n params: { field: PAGE_REQUEST_FIELDS, value: 'string' },\n },\n GATEWAY_READ_REJECTED: {\n phase: 'post_send',\n template: 'GalaChain refused {method} (Status {chainStatus}, error key \"{errorKey}\").',\n params: {\n method: 'string',\n chainStatus: 'number',\n errorKey: 'string',\n serverMessage: 'string',\n },\n unrendered: ['serverMessage'],\n },\n GATEWAY_READ_RESPONSE_INVALID: {\n phase: 'post_send',\n template: 'The gateway answered {method} with something that is not a usable GalaChain result.',\n params: { method: 'string' },\n },\n TOKEN_CLASS_NOT_FOUND: {\n phase: 'post_send',\n template: 'GalaChain has no token class {tokenClassKey}.',\n params: { tokenClassKey: 'string' },\n },\n PAGINATION_LIMIT_EXCEEDED: {\n phase: 'post_send',\n template:\n 'Reading every page of {method} takes more than {maxPages} pages; narrow the filter or raise maxPages.',\n params: { method: 'string', maxPages: 'number' },\n },\n\n // ------------------------------------------------------------- wallet providers (`./providers`)\n WALLET_NOT_CONNECTED: {\n phase: 'pre_send',\n template: 'The wallet is not connected ({reason}): connect it before {operation}.',\n params: { reason: WALLET_NOT_CONNECTED_REASONS, operation: 'string' },\n },\n WALLET_CONNECTION_FAILED: {\n phase: 'pre_send',\n template: 'Connecting to the wallet failed ({reason}).',\n params: { reason: WALLET_CONNECTION_FAILURE_REASONS },\n },\n INVALID_WALLET_PROVIDER_CONFIG: {\n phase: 'pre_send',\n template: 'A wallet provider cannot be built without {missing}.',\n params: { missing: WALLET_PROVIDER_CONFIG_MISSING },\n },\n PRIVATE_KEY_NOT_ACCESSIBLE: {\n phase: 'pre_send',\n template:\n 'This wallet provider signs in the wallet and cannot give out a private key; only a PrivateKeyProvider holds one.',\n params: {},\n },\n\n // ----------------------------------------------------------------------------- wallet helpers\n INVALID_WALLET_INPUT: {\n phase: 'pre_send',\n template:\n 'The wallet input was refused ({reason}): give a private key (64 hex digits) or a 12- or 24-word mnemonic.',\n params: { reason: WALLET_INPUT_PROBLEMS },\n },\n\n // ------------------------------------------------------------------------ bridge (`./bridge`)\n INVALID_BRIDGE_AMOUNT: {\n phase: 'pre_send',\n template: 'The bridge amount \"{value}\" was refused ({reason}).',\n params: { value: 'string', reason: BRIDGE_AMOUNT_PROBLEMS },\n },\n UNSUPPORTED_BRIDGE_TOKEN: {\n phase: 'pre_send',\n template: '{symbol} cannot be bridged with {network}.',\n params: { network: 'string', symbol: 'string' },\n },\n BRIDGE_NOT_CONFIGURED: {\n phase: 'pre_send',\n template:\n '{network} bridging is not configured: give the bridge a {network} private key (ethereumPrivateKey / solanaPrivateKey).',\n params: { network: BRIDGE_NETWORKS },\n },\n INVALID_TRANSACTION_HASH: {\n phase: 'pre_send',\n template: '\"{value}\" is not a {network} transaction hash.',\n params: { network: BRIDGE_NETWORKS, value: 'string' },\n },\n INVALID_BRIDGE_OPTION: {\n phase: 'pre_send',\n template: 'The bridge option {option} is missing or out of range.',\n params: { option: 'string' },\n },\n BRIDGE_RESPONSE_INVALID: {\n phase: 'post_send',\n template:\n 'GalaConnect answered {method} without a usable {missing}; the request may have been accepted.',\n params: { method: 'string', missing: 'string' },\n },\n BRIDGE_READ_RESPONSE_INVALID: {\n phase: 'post_send',\n template: 'GalaConnect answered {method} with something that is not a usable result.',\n params: { method: 'string' },\n },\n BRIDGE_WRITE_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'The outcome of {method} is unknown: the request failed in transit and may have reached GalaConnect. Check it before sending it again.',\n params: { method: 'string' },\n },\n GALACONNECT_HTTP_ERROR: {\n phase: 'post_send',\n template: 'GalaConnect answered {method} with HTTP {status}.',\n params: { method: 'string', status: 'number', serverMessage: 'string' },\n unrendered: ['serverMessage'],\n },\n BRIDGE_TOKEN_NOT_FOUND: {\n phase: 'post_send',\n template: 'GalaConnect has no verified bridge configuration for {symbol}.',\n params: { symbol: 'string' },\n },\n TOKEN_NOT_WRAPPABLE: {\n phase: 'post_send',\n template: '{tokenId} cannot be wrapped or unwrapped ({reason}).',\n params: { tokenId: 'string', reason: WRAP_REFUSAL_REASONS },\n },\n INVALID_WRAP_DIRECTION: {\n phase: 'pre_send',\n template:\n 'Cannot {direction} {symbol}: it is on the wrong channel for it (use the other direction).',\n params: { symbol: 'string', direction: WRAP_DIRECTIONS },\n },\n BRIDGE_REQUEST_REJECTED: {\n phase: 'post_send',\n template: 'GalaChain refused {method} (Status {chainStatus}, error key \"{errorKey}\").',\n params: {\n method: 'string',\n chainStatus: 'number',\n errorKey: 'string',\n serverMessage: 'string',\n },\n unrendered: ['serverMessage'],\n },\n BRIDGE_OUT_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'GalaConnect accepted the bridge-out request, which may have locked the tokens, then the bridge-out failed at {step}. Check it before bridging again.',\n params: { step: BRIDGE_OUT_STEPS, bridgeRequestId: 'string' },\n unrendered: ['bridgeRequestId'],\n },\n BRIDGE_DEPOSIT_OUTCOME_UNKNOWN: {\n phase: 'in_flight',\n template:\n 'The {network} bridge deposit may have been sent, then its {step} failed. Check the deposit before sending another.',\n params: { network: BRIDGE_NETWORKS, step: BRIDGE_DEPOSIT_STEPS, transactionHash: 'string' },\n unrendered: ['transactionHash'],\n },\n BRIDGE_CHAIN_READ_FAILED: {\n phase: 'post_send',\n template: 'The {network} read {call} failed or answered something unusable; nothing was sent.',\n params: { network: BRIDGE_NETWORKS, call: 'string' },\n },\n INSUFFICIENT_BRIDGE_BALANCE: {\n phase: 'pre_send',\n template: 'The {network} balance of {symbol} is {available}; the bridge needs {needed}.',\n params: { network: BRIDGE_NETWORKS, symbol: 'string', needed: 'string', available: 'string' },\n },\n BRIDGE_STATUS_TIMEOUT: {\n phase: 'in_flight',\n template:\n 'The bridge transaction did not reach a final status within {timeoutMs} ms (last status {lastStatus}); it may still complete.',\n params: { transactionHash: 'string', timeoutMs: 'number', lastStatus: 'number' },\n unrendered: ['transactionHash'],\n },\n\n // ------------------------------------------------------------------- React context (`./react`)\n WALLET_CONTEXT_MISSING: {\n phase: 'pre_send',\n template: 'The wallet hooks and the wallet context need a WalletProvider above them.',\n params: {},\n },\n} as const satisfies Record<string, GalaErrorCatalogEntry>;\n\n/** Every error code the core SDK can throw. */\nexport type GalaErrorCode = keyof typeof GALA_ERROR_CATALOG;\n\ninterface KindToType {\n string: string;\n number: number;\n boolean: boolean;\n}\n\n/** The value type of a param kind: a primitive, or the union of a closed set's members. */\ntype ParamValue<K> = K extends readonly (infer Member)[]\n ? Member\n : K extends keyof KindToType\n ? KindToType[K]\n : never;\n\n/**\n * The named params of code `C` of ANY catalog object (`typeof SOME_CATALOG`): a flat object of\n * primitives (or closed string tokens). A product SDK derives its own params type from its\n * catalog with it, so every catalog types its params the same way.\n */\nexport type ErrorParamsOf<\n Catalog extends Readonly<Record<string, GalaErrorCatalogEntry>>,\n C extends keyof Catalog,\n> = {\n readonly [P in keyof Catalog[C]['params']]: ParamValue<Catalog[C]['params'][P]>;\n};\n\n/** The named params of one core error code. */\nexport type GalaErrorParams<C extends GalaErrorCode> = ErrorParamsOf<typeof GALA_ERROR_CATALOG, C>;\n\n/**\n * The English template of every core error code, `{placeholder}` markers included. An optional\n * seed or fallback for an app's own translations; the SDK's `message` is generated from it. A\n * product SDK exports the templates of its own codes next to it.\n */\nexport const galaErrorTemplates: { readonly [C in GalaErrorCode]: string } = Object.fromEntries(\n Object.entries(GALA_ERROR_CATALOG).map(([code, entry]) => [code, entry.template]),\n) as { readonly [C in GalaErrorCode]: string };\n\nconst PLACEHOLDER = /\\{([A-Za-z0-9_]+)\\}/gu;\n\n/** Fills a template's `{placeholders}` from `params`; an unknown placeholder is left as written. */\nexport function renderGalaErrorTemplate(\n template: string,\n params: Readonly<Record<string, unknown>>,\n): string {\n return template.replace(PLACEHOLDER, (whole, name: string) => {\n const value = params[name];\n return typeof value === 'string' || typeof value === 'number' || typeof value === 'boolean'\n ? String(value)\n : whole;\n });\n}\n\n/** The placeholder names a template uses, in order of first appearance. */\nexport function templatePlaceholders(template: string): string[] {\n return [...new Set([...template.matchAll(PLACEHOLDER)].map((match) => match[1] as string))];\n}\n"],"mappings":"AA6DA,MAAaA,EAA8B,CACzC,eACA,eACA,eACA,iBACF,EAeaC,EAA0B,CAAC,gBAAiB,QAAQ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H,CAGA,SAAgBC,EAAqB,EAA4B,CAC/D,MAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAGL,EAAS,SAASF,CAAW,CAAC,CAAC,CAAC,IAAK,GAAUQ,EAAM,EAAY,CAAC,CAAC,CAC5F,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"error_phase_table.js","names":["GALA_ERROR_PHASE_BY_CODE","isGalaCatalogCode","code"],"sources":["../../../src/classes/error_phase_table.ts"],"sourcesContent":["import type { GALA_ERROR_CATALOG, GalaErrorCode } from './error_catalog.js';\n\n/**\n * The phase of every core catalog code, WITHOUT the catalog. A failure guard (a product SDK's\n * `classifyFailure`, `mayHaveBeenQueued`, ...) needs only a code's phase, and the catalog's English\n * templates are several kB: reading the phase from here keeps an app shell that imports a guard\n * from loading them. The catalog entry is still where a code is declared; this table is checked\n * against it AT COMPILE TIME, in both directions (a missing code, an extra code or a different\n * phase is a type error), so the two cannot drift. A product SDK keeps the same kind of table for\n * its own codes.\n */\nexport const GALA_ERROR_PHASE_BY_CODE = {\n REQUEST_TIMEOUT: 'in_flight',\n TRANSPORT_ERROR: 'in_flight',\n INVALID_TIMEOUT: 'pre_send',\n GALA_WALLET_NOT_AVAILABLE: 'pre_send',\n WALLET_UNAVAILABLE: 'pre_send',\n MALFORMED_WALLET_REQUEST: 'pre_send',\n UNSUPPORTED_WALLET_METHOD: 'pre_send',\n INVALID_SIGNATURE: 'pre_send',\n INVALID_CHAIN_ID: 'pre_send',\n SIGNER_ADDRESS_MISMATCH: 'pre_send',\n INVALID_PRIVATE_KEY: 'pre_send',\n SIGNING_FAILED: 'pre_send',\n KEY_PROVIDER_FAILED: 'pre_send',\n INVALID_SIGNING_HASH_LENGTH: 'pre_send',\n INVALID_WALLET_ADDRESS: 'pre_send',\n INVALID_ETH_USER_REF_PREFIX: 'pre_send',\n INVALID_DECIMAL: 'pre_send',\n PERSONAL_SIGN_NOT_JSON: 'pre_send',\n PERSONAL_SIGN_NOT_OBJECT: 'pre_send',\n PERSONAL_SIGN_BAD_PREFIX: 'pre_send',\n PERSONAL_SIGN_ENVELOPE_FIELDS: 'pre_send',\n PERSONAL_SIGN_NOT_CANONICAL: 'pre_send',\n EIP712_NAME_COLLISION: 'pre_send',\n EIP712_UNSUPPORTED_VALUE: 'pre_send',\n TYPED_DATA_NOT_STRING: 'pre_send',\n TYPED_DATA_UNPAIRED_SURROGATE: 'pre_send',\n TYPED_DATA_NOT_HEX_BYTES: 'pre_send',\n TYPED_DATA_NOT_SAFE_INTEGER: 'pre_send',\n TYPED_DATA_NOT_INTEGER: 'pre_send',\n TYPED_DATA_NOT_BOOLEAN: 'pre_send',\n TYPED_DATA_BAD_ADDRESS: 'pre_send',\n TYPED_DATA_BAD_CHECKSUM: 'pre_send',\n TYPED_DATA_BYTES_LENGTH: 'pre_send',\n TYPED_DATA_OUT_OF_BOUNDS: 'pre_send',\n TYPED_DATA_UNSUPPORTED_TYPE: 'pre_send',\n TYPED_DATA_FIELDS_NOT_LIST: 'pre_send',\n TYPED_DATA_FIELD_MALFORMED: 'pre_send',\n TYPED_DATA_INVALID_FIELD_NAME: 'pre_send',\n TYPED_DATA_DUPLICATE_FIELD: 'pre_send',\n TYPED_DATA_INVALID_TYPE_NAME: 'pre_send',\n TYPED_DATA_CIRCULAR_TYPE: 'pre_send',\n TYPED_DATA_UNKNOWN_FIELD_TYPE: 'pre_send',\n TYPED_DATA_NO_PRIMARY_TYPE: 'pre_send',\n TYPED_DATA_AMBIGUOUS_PRIMARY_TYPE: 'pre_send',\n TYPED_DATA_ARRAY_EXPECTED: 'pre_send',\n TYPED_DATA_ARRAY_LENGTH_MISMATCH: 'pre_send',\n TYPED_DATA_STRUCT_NOT_OBJECT: 'pre_send',\n TYPED_DATA_MISSING_FIELD: 'pre_send',\n TYPED_DATA_DOMAIN_NOT_OBJECT: 'pre_send',\n TYPED_DATA_INVALID_DOMAIN_KEY: 'pre_send',\n INVALID_UNIQUE_KEY: 'pre_send',\n INVALID_UNIQUE_KEY_PREFIX: 'pre_send',\n CSPRNG_UNAVAILABLE: 'pre_send',\n INVALID_WRITES_OPTION: 'pre_send',\n INVALID_QUANTITY: 'pre_send',\n INVALID_TOKEN_REFERENCE: 'pre_send',\n INVALID_TOKEN_BATCH: 'pre_send',\n INVALID_LOCK_EXPIRES: 'pre_send',\n INVALID_LOCK_NAME: 'pre_send',\n NO_TOKEN_NAME_RESOLVER: 'pre_send',\n TOKEN_NAME_RESOLUTION_FAILED: 'pre_send',\n GATEWAY_WRITE_OUTCOME_UNKNOWN: 'in_flight',\n GATEWAY_HTTP_ERROR: 'post_send',\n GATEWAY_WRITE_REJECTED: 'post_send',\n GATEWAY_RESPONSE_INVALID: 'post_send',\n INVALID_READS_OPTION: 'pre_send',\n INVALID_PAGE_REQUEST: 'pre_send',\n GATEWAY_READ_REJECTED: 'post_send',\n GATEWAY_READ_RESPONSE_INVALID: 'post_send',\n TOKEN_CLASS_NOT_FOUND: 'post_send',\n PAGINATION_LIMIT_EXCEEDED: 'post_send',\n WALLET_NOT_CONNECTED: 'pre_send',\n WALLET_CONNECTION_FAILED: 'pre_send',\n INVALID_WALLET_PROVIDER_CONFIG: 'pre_send',\n PRIVATE_KEY_NOT_ACCESSIBLE: 'pre_send',\n INVALID_WALLET_INPUT: 'pre_send',\n INVALID_BRIDGE_AMOUNT: 'pre_send',\n UNSUPPORTED_BRIDGE_TOKEN: 'pre_send',\n BRIDGE_NOT_CONFIGURED: 'pre_send',\n INVALID_TRANSACTION_HASH: 'pre_send',\n INVALID_BRIDGE_OPTION: 'pre_send',\n BRIDGE_RESPONSE_INVALID: 'post_send',\n BRIDGE_READ_RESPONSE_INVALID: 'post_send',\n BRIDGE_WRITE_OUTCOME_UNKNOWN: 'in_flight',\n GALACONNECT_HTTP_ERROR: 'post_send',\n BRIDGE_TOKEN_NOT_FOUND: 'post_send',\n TOKEN_NOT_WRAPPABLE: 'post_send',\n INVALID_WRAP_DIRECTION: 'pre_send',\n BRIDGE_REQUEST_REJECTED: 'post_send',\n BRIDGE_OUT_OUTCOME_UNKNOWN: 'in_flight',\n BRIDGE_DEPOSIT_OUTCOME_UNKNOWN: 'in_flight',\n BRIDGE_CHAIN_READ_FAILED: 'post_send',\n INSUFFICIENT_BRIDGE_BALANCE: 'pre_send',\n BRIDGE_STATUS_TIMEOUT: 'in_flight',\n WALLET_CONTEXT_MISSING: 'pre_send',\n} as const satisfies {\n readonly [C in GalaErrorCode]: (typeof GALA_ERROR_CATALOG)[C]['phase'];\n};\n\n/** True for a code the CORE catalog defines (a product SDK's own codes are not). */\nexport function isGalaCatalogCode(code: string): code is GalaErrorCode {\n return Object.hasOwn(GALA_ERROR_PHASE_BY_CODE, code);\n}\n"],"mappings":"AAWA,MAAaA,EAA2B,CACtC,gBAAiB,YACjB,gBAAiB,YACjB,gBAAiB,WACjB,0BAA2B,WAC3B,mBAAoB,WACpB,yBAA0B,WAC1B,0BAA2B,WAC3B,kBAAmB,WACnB,iBAAkB,WAClB,wBAAyB,WACzB,oBAAqB,WACrB,eAAgB,WAChB,oBAAqB,WACrB,4BAA6B,WAC7B,uBAAwB,WACxB,4BAA6B,WAC7B,gBAAiB,WACjB,uBAAwB,WACxB,yBAA0B,WAC1B,yBAA0B,WAC1B,8BAA+B,WAC/B,4BAA6B,WAC7B,sBAAuB,WACvB,yBAA0B,WAC1B,sBAAuB,WACvB,8BAA+B,WAC/B,yBAA0B,WAC1B,4BAA6B,WAC7B,uBAAwB,WACxB,uBAAwB,WACxB,uBAAwB,WACxB,wBAAyB,WACzB,wBAAyB,WACzB,yBAA0B,WAC1B,4BAA6B,WAC7B,2BAA4B,WAC5B,2BAA4B,WAC5B,8BAA+B,WAC/B,2BAA4B,WAC5B,6BAA8B,WAC9B,yBAA0B,WAC1B,8BAA+B,WAC/B,2BAA4B,WAC5B,kCAAmC,WACnC,0BAA2B,WAC3B,iCAAkC,WAClC,6BAA8B,WAC9B,yBAA0B,WAC1B,6BAA8B,WAC9B,8BAA+B,WAC/B,mBAAoB,WACpB,0BAA2B,WAC3B,mBAAoB,WACpB,sBAAuB,WACvB,iBAAkB,WAClB,wBAAyB,WACzB,oBAAqB,WACrB,qBAAsB,WACtB,kBAAmB,WACnB,uBAAwB,WACxB,6BAA8B,WAC9B,8BAA+B,YAC/B,mBAAoB,YACpB,uBAAwB,YACxB,yBAA0B,YAC1B,qBAAsB,WACtB,qBAAsB,WACtB,sBAAuB,YACvB,8BAA+B,YAC/B,sBAAuB,YACvB,0BAA2B,YAC3B,qBAAsB,WACtB,yBAA0B,WAC1B,+BAAgC,WAChC,2BAA4B,WAC5B,qBAAsB,WACtB,sBAAuB,WACvB,yBAA0B,WAC1B,sBAAuB,WACvB,yBAA0B,WAC1B,sBAAuB,WACvB,wBAAyB,YACzB,6BAA8B,YAC9B,6BAA8B,YAC9B,uBAAwB,YACxB,uBAAwB,YACxB,oBAAqB,YACrB,uBAAwB,WACxB,wBAAyB,YACzB,2BAA4B,YAC5B,+BAAgC,YAChC,yBAA0B,YAC1B,4BAA6B,WAC7B,sBAAuB,YACvB,uBAAwB,UAC1B,EAKA,SAAgBC,EAAkB,EAAqC,CACrE,OAAO,OAAO,OAAOD,EAA0BE,CAAI,CACrD"}
1
+ {"version":3,"file":"error_phase_table.js","names":["GALA_ERROR_PHASE_BY_CODE","isGalaCatalogCode","code"],"sources":["../../../src/classes/error_phase_table.ts"],"sourcesContent":["import type { GALA_ERROR_CATALOG, GalaErrorCode } from './error_catalog.js';\n\n/**\n * The phase of every core catalog code, WITHOUT the catalog. A failure guard (a product SDK's\n * `classifyFailure`, `mayHaveBeenQueued`, ...) needs only a code's phase, and the catalog's English\n * templates are several kB: reading the phase from here keeps an app shell that imports a guard\n * from loading them. The catalog entry is still where a code is declared; this table is checked\n * against it AT COMPILE TIME, in both directions (a missing code, an extra code or a different\n * phase is a type error), so the two cannot drift. A product SDK keeps the same kind of table for\n * its own codes.\n */\nexport const GALA_ERROR_PHASE_BY_CODE = {\n REQUEST_TIMEOUT: 'in_flight',\n TRANSPORT_ERROR: 'in_flight',\n INVALID_TIMEOUT: 'pre_send',\n GALA_WALLET_NOT_AVAILABLE: 'pre_send',\n WALLET_UNAVAILABLE: 'pre_send',\n MALFORMED_WALLET_REQUEST: 'pre_send',\n UNSUPPORTED_WALLET_METHOD: 'pre_send',\n INVALID_SIGNATURE: 'pre_send',\n INVALID_CHAIN_ID: 'pre_send',\n SIGNER_ADDRESS_MISMATCH: 'pre_send',\n INVALID_PRIVATE_KEY: 'pre_send',\n SIGNING_FAILED: 'pre_send',\n KEY_PROVIDER_FAILED: 'pre_send',\n INVALID_SIGNING_HASH_LENGTH: 'pre_send',\n INVALID_WALLET_ADDRESS: 'pre_send',\n INVALID_ETH_USER_REF_PREFIX: 'pre_send',\n INVALID_DECIMAL: 'pre_send',\n PERSONAL_SIGN_NOT_JSON: 'pre_send',\n PERSONAL_SIGN_NOT_OBJECT: 'pre_send',\n PERSONAL_SIGN_BAD_PREFIX: 'pre_send',\n PERSONAL_SIGN_ENVELOPE_FIELDS: 'pre_send',\n PERSONAL_SIGN_NOT_CANONICAL: 'pre_send',\n EIP712_NAME_COLLISION: 'pre_send',\n EIP712_UNSUPPORTED_VALUE: 'pre_send',\n TYPED_DATA_NOT_STRING: 'pre_send',\n TYPED_DATA_UNPAIRED_SURROGATE: 'pre_send',\n TYPED_DATA_NOT_HEX_BYTES: 'pre_send',\n TYPED_DATA_NOT_SAFE_INTEGER: 'pre_send',\n TYPED_DATA_NOT_INTEGER: 'pre_send',\n TYPED_DATA_NOT_BOOLEAN: 'pre_send',\n TYPED_DATA_BAD_ADDRESS: 'pre_send',\n TYPED_DATA_BAD_CHECKSUM: 'pre_send',\n TYPED_DATA_BYTES_LENGTH: 'pre_send',\n TYPED_DATA_OUT_OF_BOUNDS: 'pre_send',\n TYPED_DATA_UNSUPPORTED_TYPE: 'pre_send',\n TYPED_DATA_FIELDS_NOT_LIST: 'pre_send',\n TYPED_DATA_FIELD_MALFORMED: 'pre_send',\n TYPED_DATA_INVALID_FIELD_NAME: 'pre_send',\n TYPED_DATA_DUPLICATE_FIELD: 'pre_send',\n TYPED_DATA_INVALID_TYPE_NAME: 'pre_send',\n TYPED_DATA_CIRCULAR_TYPE: 'pre_send',\n TYPED_DATA_UNKNOWN_FIELD_TYPE: 'pre_send',\n TYPED_DATA_NO_PRIMARY_TYPE: 'pre_send',\n TYPED_DATA_AMBIGUOUS_PRIMARY_TYPE: 'pre_send',\n TYPED_DATA_ARRAY_EXPECTED: 'pre_send',\n TYPED_DATA_ARRAY_LENGTH_MISMATCH: 'pre_send',\n TYPED_DATA_STRUCT_NOT_OBJECT: 'pre_send',\n TYPED_DATA_MISSING_FIELD: 'pre_send',\n TYPED_DATA_DOMAIN_NOT_OBJECT: 'pre_send',\n TYPED_DATA_INVALID_DOMAIN_KEY: 'pre_send',\n INVALID_UNIQUE_KEY: 'pre_send',\n INVALID_UNIQUE_KEY_PREFIX: 'pre_send',\n CSPRNG_UNAVAILABLE: 'pre_send',\n INVALID_WRITES_OPTION: 'pre_send',\n INVALID_QUANTITY: 'pre_send',\n INVALID_TOKEN_REFERENCE: 'pre_send',\n INVALID_TOKEN_BATCH: 'pre_send',\n INVALID_LOCK_EXPIRES: 'pre_send',\n INVALID_LOCK_NAME: 'pre_send',\n NO_TOKEN_NAME_RESOLVER: 'pre_send',\n TOKEN_NAME_RESOLUTION_FAILED: 'pre_send',\n GATEWAY_WRITE_OUTCOME_UNKNOWN: 'in_flight',\n GATEWAY_HTTP_ERROR: 'post_send',\n GATEWAY_WRITE_REJECTED: 'post_send',\n GATEWAY_RESPONSE_INVALID: 'post_send',\n INVALID_READS_OPTION: 'pre_send',\n INVALID_PAGE_REQUEST: 'pre_send',\n GATEWAY_READ_REJECTED: 'post_send',\n GATEWAY_READ_RESPONSE_INVALID: 'post_send',\n TOKEN_CLASS_NOT_FOUND: 'post_send',\n PAGINATION_LIMIT_EXCEEDED: 'post_send',\n WALLET_NOT_CONNECTED: 'pre_send',\n WALLET_CONNECTION_FAILED: 'pre_send',\n INVALID_WALLET_PROVIDER_CONFIG: 'pre_send',\n PRIVATE_KEY_NOT_ACCESSIBLE: 'pre_send',\n INVALID_WALLET_INPUT: 'pre_send',\n INVALID_BRIDGE_AMOUNT: 'pre_send',\n UNSUPPORTED_BRIDGE_TOKEN: 'pre_send',\n BRIDGE_NOT_CONFIGURED: 'pre_send',\n INVALID_TRANSACTION_HASH: 'pre_send',\n INVALID_BRIDGE_OPTION: 'pre_send',\n BRIDGE_RESPONSE_INVALID: 'post_send',\n BRIDGE_READ_RESPONSE_INVALID: 'post_send',\n BRIDGE_WRITE_OUTCOME_UNKNOWN: 'in_flight',\n GALACONNECT_HTTP_ERROR: 'post_send',\n BRIDGE_TOKEN_NOT_FOUND: 'post_send',\n TOKEN_NOT_WRAPPABLE: 'post_send',\n INVALID_WRAP_DIRECTION: 'pre_send',\n BRIDGE_REQUEST_REJECTED: 'post_send',\n BRIDGE_OUT_OUTCOME_UNKNOWN: 'in_flight',\n BRIDGE_DEPOSIT_OUTCOME_UNKNOWN: 'in_flight',\n BRIDGE_CHAIN_READ_FAILED: 'post_send',\n INSUFFICIENT_BRIDGE_BALANCE: 'pre_send',\n BRIDGE_STATUS_TIMEOUT: 'in_flight',\n WALLET_CONTEXT_MISSING: 'pre_send',\n} as const satisfies {\n readonly [C in GalaErrorCode]: (typeof GALA_ERROR_CATALOG)[C]['phase'];\n};\n\n/** True for a code the CORE catalog defines (a product SDK's own codes are not). */\nexport function isGalaCatalogCode(code: string): code is GalaErrorCode {\n return Object.hasOwn(GALA_ERROR_PHASE_BY_CODE, code);\n}\n"],"mappings":"AAWA,MAAaA,EAA2B,CACtC,gBAAiB,YACjB,gBAAiB,YACjB,gBAAiB,WACjB,0BAA2B,WAC3B,mBAAoB,WACpB,yBAA0B,WAC1B,0BAA2B,WAC3B,kBAAmB,WACnB,iBAAkB,WAClB,wBAAyB,WACzB,oBAAqB,WACrB,eAAgB,WAChB,oBAAqB,WACrB,4BAA6B,WAC7B,uBAAwB,WACxB,4BA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E,OAAO,OAAO,OAAOD,EAA0BE,CAAI,CACrD,C"}
@@ -1 +1 @@
1
- {"version":3,"file":"error_phases.js","names":["GALA_ERROR_PHASES"],"sources":["../../../src/classes/error_phases.ts"],"sourcesContent":["/**\n * How far an operation had got when it failed, measured against the request it exists to send:\n * for a write, the POST that carries the signed DTO to the gateway; for a read, the GET.\n *\n * - `pre_send`: NOTHING was transmitted. Everything up to the request (validation, symbol\n * resolution, the signer, the wallet, a key provider) ran and failed, so no write can have been\n * queued. A write that failed `pre_send` is never \"maybe applied\".\n * - `in_flight`: the request left (or may have left) and no answer was read: a timeout, a broken\n * connection, a stream that dropped. For a write the outcome is unknown.\n * - `post_send`: an answer was read, or the write was already accepted: a refusal, an\n * acknowledgement that proves nothing, an unusable body, and every failure of a confirmation.\n *\n * Each catalog entry (core's and every product SDK's) declares the phase its code is thrown in; a\n * throw site where the same code can occur in another phase overrides it\n * (`GalaErrorContext.phase`). It is a typed property of every `GalaSDKError` (`error.phase`).\n *\n * This module has no imports, on purpose: it is the closed set of phases, shared by the catalogs,\n * the light phase tables (`error_phase_table.ts`) and the failure view.\n */\nexport const GALA_ERROR_PHASES = ['pre_send', 'in_flight', 'post_send'] as const;\n\n/** One member of {@link GALA_ERROR_PHASES}. */\nexport type GalaErrorPhase = (typeof GALA_ERROR_PHASES)[number];\n"],"mappings":"AAmBA,MAAaA,EAAoB,CAAC,WAAY,YAAa,WAAW"}
1
+ {"version":3,"file":"error_phases.js","names":["GALA_ERROR_PHASES"],"sources":["../../../src/classes/error_phases.ts"],"sourcesContent":["/**\n * How far an operation had got when it failed, measured against the request it exists to send:\n * for a write, the POST that carries the signed DTO to the gateway; for a read, the GET.\n *\n * - `pre_send`: NOTHING was transmitted. Everything up to the request (validation, symbol\n * resolution, the signer, the wallet, a key provider) ran and failed, so no write can have been\n * queued. A write that failed `pre_send` is never \"maybe applied\".\n * - `in_flight`: the request left (or may have left) and no answer was read: a timeout, a broken\n * connection, a stream that dropped. For a write the outcome is unknown.\n * - `post_send`: an answer was read, or the write was already accepted: a refusal, an\n * acknowledgement that proves nothing, an unusable body, and every failure of a confirmation.\n *\n * Each catalog entry (core's and every product SDK's) declares the phase its code is thrown in; a\n * throw site where the same code can occur in another phase overrides it\n * (`GalaErrorContext.phase`). It is a typed property of every `GalaSDKError` (`error.phase`).\n *\n * This module has no imports, on purpose: it is the closed set of phases, shared by the catalogs,\n * the light phase tables (`error_phase_table.ts`) and the failure view.\n */\nexport const GALA_ERROR_PHASES = ['pre_send', 'in_flight', 'post_send'] as const;\n\n/** One member of {@link GALA_ERROR_PHASES}. */\nexport type GalaErrorPhase = (typeof GALA_ERROR_PHASES)[number];\n"],"mappings":"AAmBA,MAAaA,EAAoB,CAAC,WAAY,YAAa,WAAW,E"}
@@ -1,2 +1,2 @@
1
- import{GALA_ERROR_CATALOG as e,renderGalaErrorTemplate as t}from"./error_catalog.js";import{GALA_ERROR_BRAND as n}from"../utils/error_brand.js";import r from"../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/defineProperty.js";function i(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(n===void 0)throw TypeError(`${t} is not a code of this error class's catalog`);return n}var a=class extends Error{constructor(e,n,a={}){let o=i(new.target.catalog,e);super(t(o.template,n),a.cause===void 0?void 0:{cause:a.cause}),r(this,`code`,void 0),r(this,`params`,void 0),r(this,`retryAfterMs`,void 0),r(this,`status`,void 0),r(this,`body`,void 0),r(this,`bodyText`,void 0),r(this,`url`,void 0),r(this,`uniqueKey`,void 0),r(this,`requestTransactionId`,void 0),r(this,`applyTransactionId`,void 0),r(this,`blockNumber`,void 0),r(this,`phase`,void 0),r(this,`shadow`,void 0),r(this,`write`,void 0),r(this,`walletCode`,void 0),this.name=`GalaSDKError`,this.code=e,this.params=n,this.retryAfterMs=a.retryAfterMs,this.status=a.status,this.body=typeof a.body==`string`?void 0:a.body,this.bodyText=typeof a.body==`string`?a.body:void 0,this.url=a.url,this.uniqueKey=a.uniqueKey,this.requestTransactionId=a.requestTransactionId,this.applyTransactionId=a.applyTransactionId,this.blockNumber=a.blockNumber,this.phase=a.phase??o.phase,this.shadow=a.shadow??!1,this.write=a.uniqueKey!==void 0&&a.uniqueKey!==``||a.write!==!1,this.walletCode=a.walletCode}get[n](){return!0}get notFound(){return this.status===404}};r(a,`catalog`,e);function o(e,t){return e instanceof a&&(t===void 0||e.code===t)}function s(e){try{return JSON.parse(e)}catch{return}}export{a as GalaSDKError,o as isGalaError,s as parseJson};
1
+ import{GALA_ERROR_CATALOG as e,renderGalaErrorTemplate as t}from"./error_catalog.js";import{GALA_ERROR_BRAND as n}from"../utils/error_brand.js";import r from"../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/defineProperty.js";function i(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(n===void 0)throw TypeError(`${t} is not a code of this error class's catalog`);return n}var a=class extends Error{constructor(e,n,a={}){let o=i(new.target.catalog,e);super(t(o.template,n),a.cause===void 0?void 0:{cause:a.cause}),r(this,`code`,void 0),r(this,`params`,void 0),r(this,`retryAfterMs`,void 0),r(this,`status`,void 0),r(this,`body`,void 0),r(this,`bodyText`,void 0),r(this,`url`,void 0),r(this,`uniqueKey`,void 0),r(this,`requestTransactionId`,void 0),r(this,`applyTransactionId`,void 0),r(this,`blockNumber`,void 0),r(this,`phase`,void 0),r(this,`shadow`,void 0),r(this,`write`,void 0),r(this,`walletCode`,void 0),this.name=`GalaSDKError`,this.code=e,this.params=n,this.retryAfterMs=a.retryAfterMs,this.status=a.status,this.body=typeof a.body==`string`?void 0:a.body,this.bodyText=typeof a.body==`string`?a.body:void 0,this.url=a.url,this.uniqueKey=a.uniqueKey,this.requestTransactionId=a.requestTransactionId,this.applyTransactionId=a.applyTransactionId,this.blockNumber=a.blockNumber,this.phase=a.phase??o.phase,this.shadow=a.shadow??!1,this.write=a.uniqueKey!==void 0&&a.uniqueKey!==``||a.write!==!1,this.walletCode=a.walletCode}get[n](){return!0}get notFound(){return this.status===404}};r(a,`catalog`,e);function o(e,t){return e instanceof a&&(t===void 0||e.code===t)}function s(e){try{return JSON.parse(e)}catch{return}}export{a as GalaSDKError,o as isGalaError,s as parseJson};
2
2
  //# sourceMappingURL=gala_sdk_error.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"gala_sdk_error.js","names":["_defineProperty","catalogEntry","entry","catalog","code","GalaSDKError","renderGalaErrorTemplate","params","context","GALA_ERROR_BRAND","GALA_ERROR_CATALOG","isGalaError","value","parseJson","text"],"sources":["../../../src/classes/gala_sdk_error.ts"],"sourcesContent":["import { GALA_ERROR_BRAND } from '../utils/error_brand.js';\nimport {\n GALA_ERROR_CATALOG,\n renderGalaErrorTemplate,\n type GalaErrorCatalogEntry,\n type GalaErrorCode,\n type GalaErrorParams,\n} from './error_catalog.js';\nimport type { GalaErrorPhase } from './error_phases.js';\n\n/**\n * The facts of an error that are not placeholders of its message: where it happened and what the\n * server said. All optional; none is localized text.\n */\nexport interface GalaErrorContext {\n /** The HTTP status of the response that caused the error. */\n status?: number | undefined;\n /**\n * The response body: parsed JSON when the failing response had it, else the raw text (which\n * the error then exposes as {@link GalaSDKError.bodyText}).\n */\n body?: unknown;\n /** The URL the failing request went to. */\n url?: string | undefined;\n /** The `uniqueKey` of the write this error is about: the handle for `confirm()` and recovery. */\n uniqueKey?: string | undefined;\n /** The transaction id of the queued request, `null` when unknown. */\n requestTransactionId?: string | null | undefined;\n /** The transaction id of the apply, `null` when unknown. */\n applyTransactionId?: string | null | undefined;\n /** The block the apply landed in, `null` when unknown. */\n blockNumber?: number | null | undefined;\n /** How long to wait before retrying, from the server's `Retry-After`. */\n retryAfterMs?: number | undefined;\n /** The error that caused this one (a transport failure, a wallet rejection). */\n cause?: unknown;\n /**\n * The phase of THIS occurrence when it differs from the code's catalog phase (see\n * {@link GalaErrorPhase}): for example a product code that is `pre_send` from a local registry\n * but `post_send` when it is derived from a server answer.\n */\n phase?: GalaErrorPhase | undefined;\n /** True when the failing operation was on the shadow (dark) path; see {@link GalaSDKError.shadow}. */\n shadow?: boolean | undefined;\n /**\n * `false` for the failure of a READ (see {@link GalaSDKError.write}); anything else, including\n * absent, is a write (fail-closed). Ignored when `uniqueKey` is set: that is a write.\n */\n write?: boolean | undefined;\n /** The wallet's own code on the error a signer threw; see {@link GalaSDKError.walletCode}. */\n walletCode?: number | string | undefined;\n}\n\n/** What the params of ANY SDK error are: a flat object of primitives. */\nexport type GalaErrorParamsShape = Readonly<Record<string, string | number | boolean>>;\n\n/**\n * The params type of a CORE code, and `never` for any other string: constructing a `GalaSDKError`\n * itself with a code the core catalog does not define is a compile error. A product SDK's subclass\n * supplies its own params type for its codes.\n */\nexport type GalaParamsOf<C extends string> = C extends GalaErrorCode ? GalaErrorParams<C> : never;\n\n/** Reads the catalog entry of `code`, failing loudly for a code the catalog does not define. */\nfunction catalogEntry(\n catalog: Readonly<Record<string, GalaErrorCatalogEntry>>,\n code: string,\n): GalaErrorCatalogEntry {\n const entry = Object.hasOwn(catalog, code) ? catalog[code] : undefined;\n if (entry === undefined) {\n // Unreachable through the types (the code parameter is the catalog's own key union); a cast\n // that smuggles in a foreign code is a programming error, so it fails at the throw site.\n throw new TypeError(`${code} is not a code of this error class's catalog`);\n }\n return entry;\n}\n\n/**\n * Error raised by the SDKs for validation, signing, transport, gateway, chain, or transaction\n * failures. Every product SDK's error class (`GSwapSDKError`, ...) extends it, so\n * `error instanceof GalaSDKError` (or {@link isGalaError}) recognises an error from ANY of them.\n *\n * Branch on {@link code} (stable) and render {@link params} through your own localization.\n * {@link message} is English generated from the catalog template for logs and developers: it\n * is not stable and must never be shown to a user or matched on.\n *\n * The class reads a code's template and phase from its static {@link GalaSDKError.catalog}: the\n * core catalog here, core's plus a product's own codes on a product subclass. One code is defined\n * in exactly one catalog.\n */\nexport class GalaSDKError<C extends string = GalaErrorCode, P = GalaParamsOf<C>> extends Error {\n /**\n * The catalog this class reads templates and phases from. A product SDK's subclass overrides it\n * with an object holding core's codes AND its own (core's entries are never redefined there).\n */\n public static readonly catalog: Readonly<Record<string, GalaErrorCatalogEntry>> =\n GALA_ERROR_CATALOG;\n\n /** The stable, machine-readable code. */\n public readonly code: C;\n /** The named placeholders of the error: a flat object of primitives, safe to localize with. */\n public readonly params: P;\n /** The server's `Retry-After` in milliseconds (a rate-limited answer), when it sent one. */\n public readonly retryAfterMs: number | undefined;\n /** The HTTP status of the response that caused this error, when there was one. */\n public readonly status: number | undefined;\n /**\n * The response body parsed as JSON, when the failing response had one; `undefined` for a body\n * that was not JSON (see {@link bodyText}). Never part of {@link message}.\n */\n public readonly body: unknown;\n /**\n * The raw text of a failing response whose body was NOT JSON (a proxy's HTML 502, a WAF page,\n * an empty body). It is kept here for diagnostics and is never copied into {@link message},\n * so it cannot reach a user interface by accident.\n */\n public readonly bodyText: string | undefined;\n /** The URL the failing request went to, when there was one. */\n public readonly url: string | undefined;\n /** The `uniqueKey` of the write this error is about, when there is one. */\n public readonly uniqueKey: string | undefined;\n /** The transaction id of the queued request, when known. */\n public readonly requestTransactionId: string | null | undefined;\n /** The transaction id of the apply, when known. */\n public readonly applyTransactionId: string | null | undefined;\n /** The block the apply landed in, when known. */\n public readonly blockNumber: number | null | undefined;\n /**\n * How far the operation had got when this was thrown, against the request it exists to send\n * (see {@link GalaErrorPhase}): `pre_send` means NOTHING was transmitted, so a write that\n * failed this way cannot have been queued; `in_flight` means the request left and no answer was\n * read; `post_send` means an answer was read or the write was already accepted. Every catalog\n * code declares its phase, and a throw site can refine it. A product SDK's failure classifier\n * (gswap-sdk's `classifyFailure`, `isPreSendError`) folds it into its answers.\n */\n public readonly phase: GalaErrorPhase;\n /**\n * True when this error came from the shadow (dark) path of a product SDK (gswap-sdk's\n * `swapShadow`, `submitSwapShadow`, `ChainGateway.submitShadow`), whatever failed there. The\n * classification is the same as on the public path; this is how an app applies its own\n * dark-swap policy.\n */\n public readonly shadow: boolean;\n /**\n * Whether this failure is a WRITE's, as the guards read it: `false` only for the failure of a\n * READ (a quote, a list, a result read), which has no `uniqueKey` to confirm and nothing\n * pending, so a 5xx there is `transient` and retryable. It is `true` for everything else, and\n * always when {@link uniqueKey} is set. That is fail-closed: a failure that does not say it is a\n * read is judged a write, where a 5xx is `unknown` and never retried. Apps that carry an error\n * through their own wrapper copy this field next to `uniqueKey` (`FailureView.write`).\n */\n public readonly write: boolean;\n /**\n * On `SIGNING_FAILED`: the code the wallet put on the error its signer threw, when it set one: an\n * EIP-1193 / JSON-RPC number such as `4001` (the person declined) or `-32603`, or an ethers /\n * viem string such as `'ACTION_REJECTED'`. It is read from the `cause`'s own `code` and is\n * always a short primitive; `undefined` when the wallet sent none, and on every other code. It is\n * a typed field, not a param: it is data for an app's analytics or its own wallet-specific\n * wording, never part of `message`, and `params.reason` stays the stable thing to branch on.\n */\n public readonly walletCode: number | string | undefined;\n\n constructor(code: C, params: NoInfer<P>, context: GalaErrorContext = {}) {\n const entry = catalogEntry(new.target.catalog, code);\n super(\n renderGalaErrorTemplate(entry.template, params as Readonly<Record<string, unknown>>),\n context.cause === undefined ? undefined : { cause: context.cause },\n );\n this.name = 'GalaSDKError';\n this.code = code;\n this.params = params;\n this.retryAfterMs = context.retryAfterMs;\n this.status = context.status;\n this.body = typeof context.body === 'string' ? undefined : context.body;\n this.bodyText = typeof context.body === 'string' ? context.body : undefined;\n this.url = context.url;\n this.uniqueKey = context.uniqueKey;\n this.requestTransactionId = context.requestTransactionId;\n this.applyTransactionId = context.applyTransactionId;\n this.blockNumber = context.blockNumber;\n this.phase = context.phase ?? entry.phase;\n this.shadow = context.shadow ?? false;\n this.write =\n context.uniqueKey !== undefined && context.uniqueKey !== '' ? true : context.write !== false;\n this.walletCode = context.walletCode;\n }\n\n /**\n * The SDK error brand (`Symbol.for('@gala-chain/gala-core-sdk/error')`), always `true`, carried\n * by every product SDK's error class through inheritance. The dependency-free helpers\n * (`isWalletUserRejection`, `isGalaErrorLike`) recognise an SDK error by it instead of\n * `instanceof`, so they work across copies of the SDK and without importing this class. It lives\n * on the prototype: it is not an own property and is never copied or logged.\n */\n public get [GALA_ERROR_BRAND](): true {\n return true;\n }\n\n /**\n * True when the failure means \"that thing does not exist\" rather than \"something went wrong\":\n * an HTTP 404. A product SDK's subclass adds its own not-found codes (gswap-sdk: no pool, an\n * unknown token).\n */\n public get notFound(): boolean {\n return this.status === 404;\n }\n}\n\n/** Any thrown value that is a CORE SDK error, narrowed to the union of every core code. */\nexport type AnyGalaError = { [C in GalaErrorCode]: GalaSDKError<C> }[GalaErrorCode];\n\n/**\n * True when `value` is an SDK error (core's, or any product SDK's subclass) and, when `code` is\n * given, carries exactly that core code. With a code, `error.params` narrows to that code's\n * params. Without one it narrows only to \"an SDK error with some string code\": a product error's\n * code is not a core code, so it is not typed as one.\n *\n * @example\n * ```ts\n * if (isGalaError(error, 'INVALID_PRIVATE_KEY')) {\n * t(`errors.key.${error.params.reason}`);\n * }\n * ```\n */\nexport function isGalaError(value: unknown): value is GalaSDKError<string, GalaErrorParamsShape>;\nexport function isGalaError<C extends GalaErrorCode>(\n value: unknown,\n code: C,\n): value is GalaSDKError<C>;\nexport function isGalaError(value: unknown, code?: GalaErrorCode): boolean {\n return value instanceof GalaSDKError && (code === undefined || value.code === code);\n}\n\n/** Parse a response body, preserving non-JSON text for error reporting. */\nexport function parseJson(text: string): unknown {\n try {\n return JSON.parse(text) as unknown;\n } catch {\n return undefined;\n }\n}\n"],"mappings":"uOAgEA,SAASC,EACP,EACA,EACuB,CACvB,IAAMC,EAAQ,OAAO,OAAOC,EAASC,CAAI,EAAID,EAAQC,GAAQ,IAAA,GAC7D,GAAIF,IAAU,IAAA,GAGZ,MAAU,UAAU,GAAGE,EAAK,6CAA6C,EAE3E,OAAOF,CACT,CAeA,IAAaG,EAAb,cAAyF,KAAM,CAwE7F,YAAY,EAAS,EAAoB,EAA4B,CAAC,EAAG,CACvE,IAAMH,EAAQD,EAAa,WAAW,QAASG,CAAI,EACnD,MACEE,EAAwBJ,EAAM,SAAUK,CAA2C,EACnFC,EAAQ,QAAU,IAAA,GAAY,IAAA,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AAW,GACzB,CACF,EA/GyBT,EAAAK,EAAA,UACrBK,CAAA,EAqIJ,SAAgBC,EAAY,EAAgB,EAA+B,CACzE,OAAOC,aAAiBP,IAAiBD,IAAS,IAAA,IAAaQ,EAAM,OAASR,EAChF,CAGA,SAAgBS,EAAU,EAAuB,CAC/C,GAAI,CACF,OAAO,KAAK,MAAMC,CAAI,CACxB,MAAQ,CACN,MACF,CACF"}
1
+ {"version":3,"file":"gala_sdk_error.js","names":["_defineProperty","catalogEntry","entry","catalog","code","GalaSDKError","renderGalaErrorTemplate","params","context","GALA_ERROR_BRAND","GALA_ERROR_CATALOG","isGalaError","value","parseJson","text"],"sources":["../../../src/classes/gala_sdk_error.ts"],"sourcesContent":["import { GALA_ERROR_BRAND } from '../utils/error_brand.js';\nimport {\n GALA_ERROR_CATALOG,\n renderGalaErrorTemplate,\n type GalaErrorCatalogEntry,\n type GalaErrorCode,\n type GalaErrorParams,\n} from './error_catalog.js';\nimport type { GalaErrorPhase } from './error_phases.js';\n\n/**\n * The facts of an error that are not placeholders of its message: where it happened and what the\n * server said. All optional; none is localized text.\n */\nexport interface GalaErrorContext {\n /** The HTTP status of the response that caused the error. */\n status?: number | undefined;\n /**\n * The response body: parsed JSON when the failing response had it, else the raw text (which\n * the error then exposes as {@link GalaSDKError.bodyText}).\n */\n body?: unknown;\n /** The URL the failing request went to. */\n url?: string | undefined;\n /** The `uniqueKey` of the write this error is about: the handle for `confirm()` and recovery. */\n uniqueKey?: string | undefined;\n /** The transaction id of the queued request, `null` when unknown. */\n requestTransactionId?: string | null | undefined;\n /** The transaction id of the apply, `null` when unknown. */\n applyTransactionId?: string | null | undefined;\n /** The block the apply landed in, `null` when unknown. */\n blockNumber?: number | null | undefined;\n /** How long to wait before retrying, from the server's `Retry-After`. */\n retryAfterMs?: number | undefined;\n /** The error that caused this one (a transport failure, a wallet rejection). */\n cause?: unknown;\n /**\n * The phase of THIS occurrence when it differs from the code's catalog phase (see\n * {@link GalaErrorPhase}): for example a product code that is `pre_send` from a local registry\n * but `post_send` when it is derived from a server answer.\n */\n phase?: GalaErrorPhase | undefined;\n /** True when the failing operation was on the shadow (dark) path; see {@link GalaSDKError.shadow}. */\n shadow?: boolean | undefined;\n /**\n * `false` for the failure of a READ (see {@link GalaSDKError.write}); anything else, including\n * absent, is a write (fail-closed). Ignored when `uniqueKey` is set: that is a write.\n */\n write?: boolean | undefined;\n /** The wallet's own code on the error a signer threw; see {@link GalaSDKError.walletCode}. */\n walletCode?: number | string | undefined;\n}\n\n/** What the params of ANY SDK error are: a flat object of primitives. */\nexport type GalaErrorParamsShape = Readonly<Record<string, string | number | boolean>>;\n\n/**\n * The params type of a CORE code, and `never` for any other string: constructing a `GalaSDKError`\n * itself with a code the core catalog does not define is a compile error. A product SDK's subclass\n * supplies its own params type for its codes.\n */\nexport type GalaParamsOf<C extends string> = C extends GalaErrorCode ? GalaErrorParams<C> : never;\n\n/** Reads the catalog entry of `code`, failing loudly for a code the catalog does not define. */\nfunction catalogEntry(\n catalog: Readonly<Record<string, GalaErrorCatalogEntry>>,\n code: string,\n): GalaErrorCatalogEntry {\n const entry = Object.hasOwn(catalog, code) ? catalog[code] : undefined;\n if (entry === undefined) {\n // Unreachable through the types (the code parameter is the catalog's own key union); a cast\n // that smuggles in a foreign code is a programming error, so it fails at the throw site.\n throw new TypeError(`${code} is not a code of this error class's catalog`);\n }\n return entry;\n}\n\n/**\n * Error raised by the SDKs for validation, signing, transport, gateway, chain, or transaction\n * failures. Every product SDK's error class (`GSwapSDKError`, ...) extends it, so\n * `error instanceof GalaSDKError` (or {@link isGalaError}) recognises an error from ANY of them.\n *\n * Branch on {@link code} (stable) and render {@link params} through your own localization.\n * {@link message} is English generated from the catalog template for logs and developers: it\n * is not stable and must never be shown to a user or matched on.\n *\n * The class reads a code's template and phase from its static {@link GalaSDKError.catalog}: the\n * core catalog here, core's plus a product's own codes on a product subclass. One code is defined\n * in exactly one catalog.\n */\nexport class GalaSDKError<C extends string = GalaErrorCode, P = GalaParamsOf<C>> extends Error {\n /**\n * The catalog this class reads templates and phases from. A product SDK's subclass overrides it\n * with an object holding core's codes AND its own (core's entries are never redefined there).\n */\n public static readonly catalog: Readonly<Record<string, GalaErrorCatalogEntry>> =\n GALA_ERROR_CATALOG;\n\n /** The stable, machine-readable code. */\n public readonly code: C;\n /** The named placeholders of the error: a flat object of primitives, safe to localize with. */\n public readonly params: P;\n /** The server's `Retry-After` in milliseconds (a rate-limited answer), when it sent one. */\n public readonly retryAfterMs: number | undefined;\n /** The HTTP status of the response that caused this error, when there was one. */\n public readonly status: number | undefined;\n /**\n * The response body parsed as JSON, when the failing response had one; `undefined` for a body\n * that was not JSON (see {@link bodyText}). Never part of {@link message}.\n */\n public readonly body: unknown;\n /**\n * The raw text of a failing response whose body was NOT JSON (a proxy's HTML 502, a WAF page,\n * an empty body). It is kept here for diagnostics and is never copied into {@link message},\n * so it cannot reach a user interface by accident.\n */\n public readonly bodyText: string | undefined;\n /** The URL the failing request went to, when there was one. */\n public readonly url: string | undefined;\n /** The `uniqueKey` of the write this error is about, when there is one. */\n public readonly uniqueKey: string | undefined;\n /** The transaction id of the queued request, when known. */\n public readonly requestTransactionId: string | null | undefined;\n /** The transaction id of the apply, when known. */\n public readonly applyTransactionId: string | null | undefined;\n /** The block the apply landed in, when known. */\n public readonly blockNumber: number | null | undefined;\n /**\n * How far the operation had got when this was thrown, against the request it exists to send\n * (see {@link GalaErrorPhase}): `pre_send` means NOTHING was transmitted, so a write that\n * failed this way cannot have been queued; `in_flight` means the request left and no answer was\n * read; `post_send` means an answer was read or the write was already accepted. Every catalog\n * code declares its phase, and a throw site can refine it. A product SDK's failure classifier\n * (gswap-sdk's `classifyFailure`, `isPreSendError`) folds it into its answers.\n */\n public readonly phase: GalaErrorPhase;\n /**\n * True when this error came from the shadow (dark) path of a product SDK (gswap-sdk's\n * `swapShadow`, `submitSwapShadow`, `ChainGateway.submitShadow`), whatever failed there. The\n * classification is the same as on the public path; this is how an app applies its own\n * dark-swap policy.\n */\n public readonly shadow: boolean;\n /**\n * Whether this failure is a WRITE's, as the guards read it: `false` only for the failure of a\n * READ (a quote, a list, a result read), which has no `uniqueKey` to confirm and nothing\n * pending, so a 5xx there is `transient` and retryable. It is `true` for everything else, and\n * always when {@link uniqueKey} is set. That is fail-closed: a failure that does not say it is a\n * read is judged a write, where a 5xx is `unknown` and never retried. Apps that carry an error\n * through their own wrapper copy this field next to `uniqueKey` (`FailureView.write`).\n */\n public readonly write: boolean;\n /**\n * On `SIGNING_FAILED`: the code the wallet put on the error its signer threw, when it set one: an\n * EIP-1193 / JSON-RPC number such as `4001` (the person declined) or `-32603`, or an ethers /\n * viem string such as `'ACTION_REJECTED'`. It is read from the `cause`'s own `code` and is\n * always a short primitive; `undefined` when the wallet sent none, and on every other code. It is\n * a typed field, not a param: it is data for an app's analytics or its own wallet-specific\n * wording, never part of `message`, and `params.reason` stays the stable thing to branch on.\n */\n public readonly walletCode: number | string | undefined;\n\n constructor(code: C, params: NoInfer<P>, context: GalaErrorContext = {}) {\n const entry = catalogEntry(new.target.catalog, code);\n super(\n renderGalaErrorTemplate(entry.template, params as Readonly<Record<string, unknown>>),\n context.cause === undefined ? undefined : { cause: context.cause },\n );\n this.name = 'GalaSDKError';\n this.code = code;\n this.params = params;\n this.retryAfterMs = context.retryAfterMs;\n this.status = context.status;\n this.body = typeof context.body === 'string' ? undefined : context.body;\n this.bodyText = typeof context.body === 'string' ? context.body : undefined;\n this.url = context.url;\n this.uniqueKey = context.uniqueKey;\n this.requestTransactionId = context.requestTransactionId;\n this.applyTransactionId = context.applyTransactionId;\n this.blockNumber = context.blockNumber;\n this.phase = context.phase ?? entry.phase;\n this.shadow = context.shadow ?? false;\n this.write =\n context.uniqueKey !== undefined && context.uniqueKey !== '' ? true : context.write !== false;\n this.walletCode = context.walletCode;\n }\n\n /**\n * The SDK error brand (`Symbol.for('@gala-chain/gala-core-sdk/error')`), always `true`, carried\n * by every product SDK's error class through inheritance. The dependency-free helpers\n * (`isWalletUserRejection`, `isGalaErrorLike`) recognise an SDK error by it instead of\n * `instanceof`, so they work across copies of the SDK and without importing this class. It lives\n * on the prototype: it is not an own property and is never copied or logged.\n */\n public get [GALA_ERROR_BRAND](): true {\n return true;\n }\n\n /**\n * True when the failure means \"that thing does not exist\" rather than \"something went wrong\":\n * an HTTP 404. A product SDK's subclass adds its own not-found codes (gswap-sdk: no pool, an\n * unknown token).\n */\n public get notFound(): boolean {\n return this.status === 404;\n }\n}\n\n/** Any thrown value that is a CORE SDK error, narrowed to the union of every core code. */\nexport type AnyGalaError = { [C in GalaErrorCode]: GalaSDKError<C> }[GalaErrorCode];\n\n/**\n * True when `value` is an SDK error (core's, or any product SDK's subclass) and, when `code` is\n * given, carries exactly that core code. With a code, `error.params` narrows to that code's\n * params. Without one it narrows only to \"an SDK error with some string code\": a product error's\n * code is not a core code, so it is not typed as one.\n *\n * @example\n * ```ts\n * if (isGalaError(error, 'INVALID_PRIVATE_KEY')) {\n * t(`errors.key.${error.params.reason}`);\n * }\n * ```\n */\nexport function isGalaError(value: unknown): value is GalaSDKError<string, GalaErrorParamsShape>;\nexport function isGalaError<C extends GalaErrorCode>(\n value: unknown,\n code: C,\n): value is GalaSDKError<C>;\nexport function isGalaError(value: unknown, code?: GalaErrorCode): boolean {\n return value instanceof GalaSDKError && (code === undefined || value.code === code);\n}\n\n/** Parse a response body, preserving non-JSON text for error reporting. */\nexport function parseJson(text: string): unknown {\n try {\n return JSON.parse(text) as unknown;\n } catch {\n return undefined;\n }\n}\n"],"mappings":"A,uOAgEA,SAASC,EACP,EACA,EACuB,CACvB,IAAMC,EAAQ,OAAO,OAAOC,EAASC,CAAI,EAAID,EAAQC,GAAQ,IAAA,GAC7D,GAAIF,IAAU,IAAA,GAGZ,MAAU,UAAU,GAAGE,EAAK,6CAA6C,EAE3E,OAAOF,CACT,CAeA,IAAaG,EAAb,cAAyF,KAAM,CAwE7F,YAAY,EAAS,EAAoB,EAA4B,CAAC,EAAG,CACvE,IAAMH,E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,GACzF,KAAK,WAAaA,EAAQ,UAC5B,CASA,IAAYC,IAA0B,CACpC,MAAO,EACT,CAOA,IAAW,UAAoB,CAC7B,OAAO,KAAK,SAAW,GACzB,CACF,EA/GyBT,EAAAK,EAAA,UACrBK,CAAA,EAqIJ,SAAgBC,EAAY,EAAgB,EAA+B,CACzE,OAAOC,aAAiBP,IAAiBD,IAAS,IAAA,IAAaQ,EAAM,OAASR,EAChF,CAGA,SAAgBS,EAAU,EAAuB,CAC/C,GAAI,CACF,OAAO,KAAK,MAAMC,CAAI,CACxB,MAAQ,CACN,MACF,CACF,C"}
@@ -1,2 +1,2 @@
1
- import e from"../_virtual/_@oxc-project_runtime@0.153.0/helpers/esm/defineProperty.js";import{GalaSDKError as t,isGalaError as n}from"./gala_sdk_error.js";import{assertNoEthZeroXPrefix as r}from"../writes/identity.js";import{EIP712_CAPABLE_METHODS as i,buildEIP712Payload as a,eip712DomainFor as o}from"../utils/eip712.js";import{ethAddressOfPrivateKey as s,fixpointPrefixFor as c,normalizePrivateKey as l,personalSignPrefixFor as u,serialize as d,signNative as f}from"../utils/signing.js";function p(){let e=globalThis.window?.gala;if(!e)throw new t(`GALA_WALLET_NOT_AVAILABLE`,{});return e}function m(e){if(typeof e!=`string`||!/^(?:0x)?[0-9a-fA-F]{130}$/u.test(e))throw new t(`INVALID_SIGNATURE`,{scheme:`native`});return e}function h(e){if(typeof e!=`string`||!/^(?:0x)?[0-9a-fA-F]{130}$/u.test(e))throw new t(`INVALID_SIGNATURE`,{scheme:`personal-sign`});return e}function g(e){r(e,`account`);let t=/^(?:eth\||0x)([0-9a-fA-F]{40})$/u.exec(e);return t?.[1]===void 0?void 0:`0x${t[1]}`}function _(e,n,i=`walletAddress`){r(e,i);let a=n?g(e)??e:e;if(!/^0x[0-9a-fA-F]{40}$/u.test(a))throw new t(`INVALID_WALLET_ADDRESS`,{field:i,value:e});return a}function v(e){r(e,`walletAddress`);let n=/^eth\|([0-9a-fA-F]{40})$/u.exec(e);if(n?.[1]!==void 0)return`0x${n[1]}`;if(/^0x[0-9a-fA-F]{40}$/u.test(e)||/^(?:client\|)?[0-9a-fA-F]{24}$/u.test(e))return e;throw new t(`INVALID_WALLET_ADDRESS`,{field:`walletAddress`,value:e})}function y(e){if(r(e,`selectAddress`),!/^(?:eth\|[0-9a-fA-F]{40}|0x[0-9a-fA-F]{40}|(?:client\|)?[0-9a-fA-F]{24})$/u.test(e))throw new t(`INVALID_WALLET_ADDRESS`,{field:`selectAddress`,value:e})}const b=/* @__PURE__ */ new WeakMap;function x(e,t,n){let{setAddress:r}=e;if(t===void 0||typeof r!=`function`)return n();let i=(b.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>(await r.call(e,t),n()));return b.set(e,i),i}function S(e,t,n,r){let i=u(t),a={...t,prefix:i},o=r===void 0?[d(t),n]:[d(a),n,r];return e.request({method:r===void 0?`personal_sign`:`gala_signChainDto`,params:o}).then(e=>({...a,signature:h(e)}))}async function C(e,t,n,r){let{completedDto:i,types:s}=a(t,n),l=o(await e.request({method:`eth_chainId`,params:[]})),u=c(i),d={...i,prefix:u},f=[{name:`name`,type:`string`},{name:`chainId`,type:`uint256`}],p={domain:l,types:{...s,EIP712Domain:f},primaryType:t,message:d},m=await e.request({method:`eth_signTypedData_v4`,params:[r,JSON.stringify(p)]});return{...d,signature:h(m),types:s,domain:l}}var w=class{constructor(t){e(this,`privateKey`,void 0),this.privateKey=l(t)}signObject(e,t){let n=f(this.privateKey,t);return Promise.resolve({...t,signature:n})}};async function T(e){try{return await e()}catch(e){throw n(e)?e:new t(`KEY_PROVIDER_FAILED`,{},{cause:e})}}function E(e,n={}){let r=n.expectedAddress,i=r===void 0?void 0:_(r,!0,`expectedAddress`).toLowerCase();return{async signObject(n,r){let a=await T(e);if(typeof a!=`string`||a===``)throw new t(`INVALID_PRIVATE_KEY`,{reason:`no_key_provided`});let o=l(a);try{if(i!==void 0&&s(o)!==i)throw new t(`SIGNER_ADDRESS_MISMATCH`,{});return{...r,signature:f(o,r)}}finally{o.fill(0)}}}}var D=class{constructor(t,n={}){e(this,`walletAddress`,void 0),e(this,`scheme`,void 0),e(this,`selectAddress`,void 0),e(this,`wallet`,void 0),this.walletAddress=v(t),this.scheme=n.scheme??`native`,n.selectAddress!==void 0&&y(n.selectAddress),this.selectAddress=n.selectAddress,this.wallet=n.wallet}async signObject(e,t){let n=this.wallet??p();return x(n,this.selectAddress,async()=>{if(this.scheme===`personal-sign`)return S(n,t,this.walletAddress,e);let r=await n.request({method:`gala_signChainDto`,params:[d(t),this.walletAddress,e,`native`]});return{...t,signature:m(r)}})}},O=class{constructor(t,n,r={}){this.provider=t,e(this,`walletAddress`,void 0),e(this,`scheme`,void 0),this.walletAddress=_(n,!1),this.scheme=r.scheme??`personal-sign`}signObject(e,t){return this.scheme===`eip712`&&i.has(e)?C(this.provider,e,t,this.walletAddress):S(this.provider,t,this.walletAddress)}};export{O as BrowserWalletSigner,D as GalaWalletSigner,w as PrivateKeySigner,E as createLazyPrivateKeySigner,g as ethereumAddressOfAccount,x as withGalaWalletIdentity};
1
+ import e from"../_virtual/_@oxc-project_runtime@0.154.0/helpers/esm/defineProperty.js";import{GalaSDKError as t,isGalaError as n}from"./gala_sdk_error.js";import{assertNoEthZeroXPrefix as r}from"../writes/identity.js";import{EIP712_CAPABLE_METHODS as i,buildEIP712Payload as a,eip712DomainFor as o}from"../utils/eip712.js";import{ethAddressOfPrivateKey as s,fixpointPrefixFor as c,normalizePrivateKey as l,personalSignPrefixFor as u,serialize as d,signNative as f}from"../utils/signing.js";function p(){let e=globalThis.window?.gala;if(!e)throw new t(`GALA_WALLET_NOT_AVAILABLE`,{});return e}function m(e){if(typeof e!=`string`||!/^(?:0x)?[0-9a-fA-F]{130}$/u.test(e))throw new t(`INVALID_SIGNATURE`,{scheme:`native`});return e}function h(e){if(typeof e!=`string`||!/^(?:0x)?[0-9a-fA-F]{130}$/u.test(e))throw new t(`INVALID_SIGNATURE`,{scheme:`personal-sign`});return e}function g(e){r(e,`account`);let t=/^(?:eth\||0x)([0-9a-fA-F]{40})$/u.exec(e);return t?.[1]===void 0?void 0:`0x${t[1]}`}function _(e,n,i=`walletAddress`){r(e,i);let a=n?g(e)??e:e;if(!/^0x[0-9a-fA-F]{40}$/u.test(a))throw new t(`INVALID_WALLET_ADDRESS`,{field:i,value:e});return a}function v(e){r(e,`walletAddress`);let n=/^eth\|([0-9a-fA-F]{40})$/u.exec(e);if(n?.[1]!==void 0)return`0x${n[1]}`;if(/^0x[0-9a-fA-F]{40}$/u.test(e)||/^(?:client\|)?[0-9a-fA-F]{24}$/u.test(e))return e;throw new t(`INVALID_WALLET_ADDRESS`,{field:`walletAddress`,value:e})}function y(e){if(r(e,`selectAddress`),!/^(?:eth\|[0-9a-fA-F]{40}|0x[0-9a-fA-F]{40}|(?:client\|)?[0-9a-fA-F]{24})$/u.test(e))throw new t(`INVALID_WALLET_ADDRESS`,{field:`selectAddress`,value:e})}const b=/* @__PURE__ */ new WeakMap;function x(e,t,n){let{setAddress:r}=e;if(t===void 0||typeof r!=`function`)return n();let i=(b.get(e)??Promise.resolve()).catch(()=>void 0).then(async()=>(await r.call(e,t),n()));return b.set(e,i),i}function S(e,t,n,r){let i=u(t),a={...t,prefix:i},o=r===void 0?[d(t),n]:[d(a),n,r];return e.request({method:r===void 0?`personal_sign`:`gala_signChainDto`,params:o}).then(e=>({...a,signature:h(e)}))}async function C(e,t,n,r){let{completedDto:i,types:s}=a(t,n),l=o(await e.request({method:`eth_chainId`,params:[]})),u=c(i),d={...i,prefix:u},f=[{name:`name`,type:`string`},{name:`chainId`,type:`uint256`}],p={domain:l,types:{...s,EIP712Domain:f},primaryType:t,message:d},m=await e.request({method:`eth_signTypedData_v4`,params:[r,JSON.stringify(p)]});return{...d,signature:h(m),types:s,domain:l}}var w=class{constructor(t){e(this,`privateKey`,void 0),this.privateKey=l(t)}signObject(e,t){let n=f(this.privateKey,t);return Promise.resolve({...t,signature:n})}};async function T(e){try{return await e()}catch(e){throw n(e)?e:new t(`KEY_PROVIDER_FAILED`,{},{cause:e})}}function E(e,n={}){let r=n.expectedAddress,i=r===void 0?void 0:_(r,!0,`expectedAddress`).toLowerCase();return{async signObject(n,r){let a=await T(e);if(typeof a!=`string`||a===``)throw new t(`INVALID_PRIVATE_KEY`,{reason:`no_key_provided`});let o=l(a);try{if(i!==void 0&&s(o)!==i)throw new t(`SIGNER_ADDRESS_MISMATCH`,{});return{...r,signature:f(o,r)}}finally{o.fill(0)}}}}var D=class{constructor(t,n={}){e(this,`walletAddress`,void 0),e(this,`scheme`,void 0),e(this,`selectAddress`,void 0),e(this,`wallet`,void 0),this.walletAddress=v(t),this.scheme=n.scheme??`native`,n.selectAddress!==void 0&&y(n.selectAddress),this.selectAddress=n.selectAddress,this.wallet=n.wallet}async signObject(e,t){let n=this.wallet??p();return x(n,this.selectAddress,async()=>{if(this.scheme===`personal-sign`)return S(n,t,this.walletAddress,e);let r=await n.request({method:`gala_signChainDto`,params:[d(t),this.walletAddress,e,`native`]});return{...t,signature:m(r)}})}},O=class{constructor(t,n,r={}){this.provider=t,e(this,`walletAddress`,void 0),e(this,`scheme`,void 0),this.walletAddress=_(n,!1),this.scheme=r.scheme??`personal-sign`}signObject(e,t){return this.scheme===`eip712`&&i.has(e)?C(this.provider,e,t,this.walletAddress):S(this.provider,t,this.walletAddress)}};export{O as BrowserWalletSigner,D as GalaWalletSigner,w as PrivateKeySigner,E as createLazyPrivateKeySigner,g as ethereumAddressOfAccount,x as withGalaWalletIdentity};
2
2
  //# sourceMappingURL=signers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"signers.js","names":["globalObject","_defineProperty","getWalletProvider","wallet","GalaSDKError","getNativeSignature","value","getPersonalSignature","ethereumAddressOfAccount","assertNoEthZeroXPrefix","account","match","normalizeEthereumAccount","address","field","normalized","allowGalaPrefix","normalizeGalaWalletAccount","eth","assertWalletIdentity","identity","walletIdentityQueue","withGalaWalletIdentity","setAddress","signWith","run","personalSign","prefix","personalSignPrefixFor","dto","payload","params","methodName","serialize","walletAddress","provider","signEIP712","buildEIP712Payload","domain","eip712DomainFor","fixpointPrefixFor","completedDto","message","eip712Domain","types","PrivateKeySigner","normalizePrivateKey","privateKey","signature","signNative","keyFrom","getPrivateKey","cause","isGalaError","createLazyPrivateKeySigner","expected","options","expectedLower","provided","key","ethAddressOfPrivateKey","GalaWalletSigner","BrowserWalletSigner","EIP712_CAPABLE_METHODS"],"sources":["../../../src/classes/signers.ts"],"sourcesContent":["import { GalaSDKError, isGalaError } from './gala_sdk_error.js';\nimport { assertNoEthZeroXPrefix } from '../writes/identity.js';\nimport {\n buildEIP712Payload,\n EIP712_CAPABLE_METHODS,\n eip712DomainFor,\n type EIP712DomainValue,\n type EIP712Types,\n} from '../utils/eip712.js';\nimport {\n ethAddressOfPrivateKey,\n fixpointPrefixFor,\n normalizePrivateKey,\n personalSignPrefixFor,\n serialize,\n signNative,\n} from '../utils/signing.js';\n\n// Personal-sign prefix, computed the way THE CHAIN verifies it.\n//\n// GalaChain (SDK 3.x) recovers a personal-signed DTO from\n// keccak256(<prefix field> + <canonical JSON of the DTO WITHOUT the prefix field>)\n// and a browser wallet's `personal_sign` (EIP-191) hashes\n// \"\\u0019Ethereum Signed Message:\\n\" + <byte length of message> + <message>.\n// They agree exactly when the wallet signs the bare canonical DTO and `prefix` is the EIP-191\n// header for that message's UTF-8 BYTE length. Any other message still yields a valid-looking\n// signature — it just recovers to an address nobody holds. This SDK used to embed `prefix` in\n// the signed message (the SDK 1.10 client recipe): observed on stage 2026-09-23, such a\n// MetaMask-signed CreatePool executed on chain under a phantom creator, and the swap backend's\n// write guard now rejects that shape outright.\n//\n// `@gala-chain/connect`'s prefix helper must NOT be used for wallet `personal_sign`: its\n// fixpoint counts the prefix itself and targets the SDK's raw-payload signer. The same header\n// is also what Gala Wallet's `gala_signChainDto` (personal-sign scheme) prepends before hashing,\n// so one value serves both paths.\n//\n// The header itself is computed by `personalSignPrefixFor` in ../utils/signing.ts.\n\n/** The signing schemes supported by the Gala Wallet signer. */\nexport type GalaWalletScheme = 'native' | 'personal-sign';\n\n/** The request surface used by an EIP-1193 browser wallet. */\nexport interface BrowserWalletProvider {\n request(args: { method: string; params?: unknown[] }): Promise<unknown>;\n}\n\n/** The Gala Wallet extension's API (`window.gala`, or the same object from an EIP-6963 announcement). */\nexport interface GalaWalletApi {\n request(args: { method: string; params?: unknown[] }): Promise<unknown>;\n /** Gala Wallet's \"act as this account\" switch; absent on other providers. */\n setAddress?: (address: string) => Promise<void>;\n}\n\ninterface WindowWithGala {\n gala?: GalaWalletApi;\n}\n\ninterface GlobalWithWindow {\n window?: WindowWithGala;\n}\n\n/** A DTO together with the signature that belongs in the gateway request body. */\nexport type SignedDto<T extends Record<string, unknown>> = T & { signature: string };\n\n/**\n * A signer for complete GalaChain write bodies.\n *\n * Implementations return the DTO fields together with the signature that belongs in the\n * gateway request body. Signer identity is recovered from that signature; implementations do\n * not add signer hints, typed-data metadata, or a domain.\n */\nexport interface GalaChainSigner {\n /**\n * Signs a DTO for a named GalaChain contract method.\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n */\n signObject<T extends Record<string, unknown>>(methodName: string, dto: T): Promise<SignedDto<T>>;\n}\n\nfunction getWalletProvider(): GalaWalletApi {\n const globalObject = globalThis as GlobalWithWindow;\n const wallet = globalObject.window?.gala;\n if (!wallet) {\n throw new GalaSDKError('GALA_WALLET_NOT_AVAILABLE', {});\n }\n return wallet;\n}\n\nfunction getNativeSignature(value: unknown): string {\n if (typeof value !== 'string') {\n throw new GalaSDKError('INVALID_SIGNATURE', { scheme: 'native' });\n }\n // 130 hex digits (r || s || v), bare as Gala Wallet returns it or `0x`-prefixed; passed on\n // verbatim, because the backend recovers the signer from either spelling.\n if (!/^(?:0x)?[0-9a-fA-F]{130}$/u.test(value)) {\n throw new GalaSDKError('INVALID_SIGNATURE', { scheme: 'native' });\n }\n return value;\n}\n\nfunction getPersonalSignature(value: unknown): string {\n if (typeof value !== 'string' || !/^(?:0x)?[0-9a-fA-F]{130}$/u.test(value)) {\n throw new GalaSDKError('INVALID_SIGNATURE', { scheme: 'personal-sign' });\n }\n return value;\n}\n\n/**\n * The `0x`-prefixed Ethereum address a Gala account is signed by, or `undefined` when the account\n * names no key (a `client|` alias or a bare GalaChain id is not derivable from a key). Accepts\n * `0x` plus 40 hex digits and `eth|` plus 40 hex digits; the caller's casing is kept. `eth|0x...`\n * is not an address form and is refused. For {@link LazyPrivateKeySignerOptions.expectedAddress}, which should only be set for\n * an account whose key can be checked.\n *\n * @example\n * ```ts\n * createLazyPrivateKeySigner(getKey, { expectedAddress: ethereumAddressOfAccount(account) });\n * ```\n *\n * @throws GalaSDKError `INVALID_ETH_USER_REF_PREFIX` for `eth|0x...` (refused, never read as\n * \"names no key\", which would switch a signer's address check off).\n */\nexport function ethereumAddressOfAccount(account: string): string | undefined {\n assertNoEthZeroXPrefix(account, 'account');\n const match = /^(?:eth\\||0x)([0-9a-fA-F]{40})$/u.exec(account);\n return match?.[1] === undefined ? undefined : `0x${match[1]}`;\n}\n\nfunction normalizeEthereumAccount(\n address: string,\n allowGalaPrefix: boolean,\n field = 'walletAddress',\n): string {\n assertNoEthZeroXPrefix(address, field);\n const normalized = allowGalaPrefix ? (ethereumAddressOfAccount(address) ?? address) : address;\n if (!/^0x[0-9a-fA-F]{40}$/u.test(normalized)) {\n throw new GalaSDKError('INVALID_WALLET_ADDRESS', { field, value: address });\n }\n // The caller's casing is kept on purpose: the Gala web apps and the wallet hand the wallet the\n // checksummed account, and EIP-1193 / Gala Wallet accept any case, so passing the value through\n // unchanged is the only choice that cannot differ from what they send.\n return normalized;\n}\n\n/**\n * The account handed to Gala Wallet as the signer address. An Ethereum account is held to the\n * same strict check as ever (`0x` plus 40 hex digits; `eth|` plus 40 hex digits is normalized to\n * it; `eth|0x...` is refused). A GalaChain id the wallet can also be asked to sign for is passed\n * through verbatim: `client|` plus 24 hex digits, or the bare 24 hex digits that a web app keeps\n * after a direct `client|` login. Nothing else is accepted.\n */\nfunction normalizeGalaWalletAccount(address: string): string {\n assertNoEthZeroXPrefix(address, 'walletAddress');\n const eth = /^eth\\|([0-9a-fA-F]{40})$/u.exec(address);\n if (eth?.[1] !== undefined) return `0x${eth[1]}`;\n if (/^0x[0-9a-fA-F]{40}$/u.test(address) || /^(?:client\\|)?[0-9a-fA-F]{24}$/u.test(address)) {\n return address;\n }\n throw new GalaSDKError('INVALID_WALLET_ADDRESS', { field: 'walletAddress', value: address });\n}\n\n/** An identity Gala Wallet can act as: an account form above, any `eth|`/`client|` alias, verbatim. */\nfunction assertWalletIdentity(identity: string): void {\n assertNoEthZeroXPrefix(identity, 'selectAddress');\n if (\n !/^(?:eth\\|[0-9a-fA-F]{40}|0x[0-9a-fA-F]{40}|(?:client\\|)?[0-9a-fA-F]{24})$/u.test(identity)\n ) {\n throw new GalaSDKError('INVALID_WALLET_ADDRESS', { field: 'selectAddress', value: identity });\n }\n}\n\n/** Provider-wide queue: `setAddress` + the signature request must not interleave across signers. */\nconst walletIdentityQueue = new WeakMap<object, Promise<unknown>>();\n\n/**\n * Runs `signWith` with `identity` selected on a Gala Wallet that supports `setAddress`. Gala\n * Wallet holds ONE current account, so two signatures for different identities in flight at once\n * would sign as whichever selection came last; the pair (select, sign) is therefore serialized\n * per wallet object, across every signer and provider that signs through it\n * (`GalaWalletSigner`, `./providers`' `GalaWalletProvider`). A failed selection fails the\n * signature (nothing is requested). Without an identity, or on a wallet without `setAddress`, it\n * just runs `signWith`.\n *\n * @example\n * ```typescript\n * const signature = await withGalaWalletIdentity(window.gala, 'eth|70997970C51812dc3A010C7d01b50e0d17dc79C8', () =>\n * window.gala.request({ method: 'personal_sign', params: [hexMessage, address] }),\n * );\n * ```\n */\nexport function withGalaWalletIdentity<T>(\n wallet: GalaWalletApi,\n identity: string | undefined,\n signWith: () => Promise<T>,\n): Promise<T> {\n const { setAddress } = wallet;\n if (identity === undefined || typeof setAddress !== 'function') return signWith();\n const previous = walletIdentityQueue.get(wallet) ?? Promise.resolve();\n const run = previous\n .catch(() => undefined)\n .then(async () => {\n await setAddress.call(wallet, identity);\n return signWith();\n });\n walletIdentityQueue.set(wallet, run);\n return run;\n}\n\nfunction personalSign<T extends Record<string, unknown>>(\n provider: GalaWalletApi | BrowserWalletProvider,\n dto: T,\n walletAddress: string,\n methodName?: string,\n): Promise<T & { prefix: string; signature: string }> {\n const prefix = personalSignPrefixFor(dto);\n const payload = { ...dto, prefix };\n // A browser wallet's `personal_sign` applies the EIP-191 header ITSELF, so it must sign the\n // bare DTO; Gala Wallet's `gala_signChainDto` (personal-sign scheme) instead extracts the\n // `prefix` field from what it is handed and prepends it before hashing, so it is handed the\n // prefixed payload. Both submit `{ ...dto, prefix, signature }`.\n const params =\n methodName !== undefined\n ? [serialize(payload), walletAddress, methodName]\n : [serialize(dto), walletAddress];\n\n return provider\n .request({ method: methodName !== undefined ? 'gala_signChainDto' : 'personal_sign', params })\n .then((value) => ({ ...payload, signature: getPersonalSignature(value) }));\n}\n\n/**\n * Signs a DTO via genuine EIP-712 (`eth_signTypedData_v4`) — correctly resolves the `client|`\n * identity, unlike `personal_sign`, for the operations in `EIP712_CAPABLE_METHODS`.\n *\n * Constructs the raw JSON-RPC payload by hand (`{domain, types: {...types, EIP712Domain},\n * primaryType, message}`) rather than depending on ethers.js, matching exactly what\n * `ethers.TypedDataEncoder.getPayload`/`Wallet.signTypedData` produce internally — verified\n * byte-for-byte equivalent (same recovered address from the same signature against both\n * constructions) before this shipped, since the core SDK deliberately has no ethers dependency.\n */\nasync function signEIP712<T extends Record<string, unknown>>(\n provider: BrowserWalletProvider,\n methodName: string,\n dto: T,\n walletAddress: string,\n): Promise<T & { types: EIP712Types; domain: EIP712DomainValue; signature: string }> {\n const { completedDto, types } = buildEIP712Payload(methodName, dto);\n // The wallet's LIVE chain id, read on every signature: a user can switch networks after\n // connecting, and a cached or hardcoded id would sign a domain MetaMask itself rejects.\n const domain = eip712DomainFor(await provider.request({ method: 'eth_chainId', params: [] }));\n // The body `prefix` is not part of the EIP-712 `types`, so it is never hashed; it carries the\n // connect-style fixpoint value only to keep the submitted body byte-identical to what the Gala\n // web apps have always sent.\n const prefix = fixpointPrefixFor(completedDto);\n const message = { ...completedDto, prefix };\n const eip712Domain = [\n { name: 'name', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n ];\n const payload = {\n domain,\n types: { ...types, EIP712Domain: eip712Domain },\n primaryType: methodName,\n message,\n };\n\n const value = await provider.request({\n method: 'eth_signTypedData_v4',\n params: [walletAddress, JSON.stringify(payload)],\n });\n // Key order matches the body the Gala web apps submit: ..., prefix, signature, types, domain.\n return {\n ...(message as T & { prefix: string }),\n signature: getPersonalSignature(value),\n types,\n domain,\n };\n}\n\n/**\n * A GalaChain native signer backed by a secp256k1 private key.\n *\n * Native signing produces the bare GalaChain signature format, without a personal-sign prefix\n * or EIP-712 metadata. The private-key identity is recovered by the chain.\n */\nexport class PrivateKeySigner implements GalaChainSigner {\n private readonly privateKey: Uint8Array;\n\n /**\n * Creates a native signer from a hex or base64 secp256k1 private key.\n *\n * @example\n * ```typescript\n * const signer = new PrivateKeySigner('1'.padStart(64, '0'));\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n */\n constructor(privateKey: string) {\n this.privateKey = normalizePrivateKey(privateKey);\n }\n\n /**\n * Signs the DTO with GalaChain native signing.\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('RequestTrade', {\n * token0: 'GALA',\n * token1: 'GUSDC',\n * fee: 3000,\n * });\n * ```\n */\n public signObject<T extends Record<string, unknown>>(\n _methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n const signature = signNative(this.privateKey, dto);\n return Promise.resolve({ ...dto, signature });\n }\n}\n\n/** Supplies a private key at sign time: a hex/base64 string, possibly fetched asynchronously. */\nexport type PrivateKeyProvider = () => Promise<string> | string;\n\n/** Options for {@link createLazyPrivateKeySigner}. */\nexport interface LazyPrivateKeySignerOptions {\n /**\n * When set, every signature first checks that the fetched key belongs to this account (`0x...`\n * or the Gala `eth|<40 hex>` form, case-insensitive; `eth|0x...` is refused at creation) and\n * refuses to sign otherwise (`SIGNER_ADDRESS_MISMATCH`). Use it when the key lives in a slot another surface can switch\n * between the moment a request was approved and the moment it is signed.\n */\n expectedAddress?: string | undefined;\n}\n\n/**\n * Calls the app's key provider. Whatever it throws or rejects with is the app's own failure to\n * produce a key before anything was signed or sent, so it becomes `KEY_PROVIDER_FAILED` (the\n * original is `cause`); an SDK error is already catalogued and passes through.\n */\nasync function keyFrom(getPrivateKey: PrivateKeyProvider): Promise<unknown> {\n try {\n return await getPrivateKey();\n } catch (cause: unknown) {\n throw isGalaError(cause) ? cause : new GalaSDKError('KEY_PROVIDER_FAILED', {}, { cause });\n }\n}\n\n/**\n * Creates the native-signing equivalent of {@link PrivateKeySigner} for apps that must not hold a\n * key in a long-lived object (an extension that reads its session key at sign time).\n *\n * `getPrivateKey` is called once per `signObject` call, never cached, never shared between calls\n * (concurrent signatures each fetch their own key), and the normalized key bytes are zeroed\n * before `signObject` settles, also on failure. A rejection or exception from `getPrivateKey` (the\n * app's \"wallet is locked\", a storage read that failed) is a `KEY_PROVIDER_FAILED` error with the\n * original error as `cause`: nothing has been sent, so `classifyFailure` says `not_sent` and Retry\n * is safe, and the app needs no error class of its own to tell this apart. A provider that returns\n * no usable string (`''`, `undefined`) is `INVALID_PRIVATE_KEY` with `reason: 'no_key_provided'`,\n * classified the same way; any other key that is not a valid secp256k1 key string is an\n * `INVALID_PRIVATE_KEY` error. An SDK error the provider throws itself is passed through.\n * Signatures are byte-identical to `new PrivateKeySigner(key).signObject(...)`.\n *\n * A JavaScript string cannot be wiped; the provider owns the lifetime of the string it returns.\n *\n * @example\n * ```typescript\n * const signer = createLazyPrivateKeySigner(\n * () => SecurityHelper.getSessionSecret(SecurityHelper.SESSION_PRIVATE_KEY_KEY),\n * { expectedAddress: account.address },\n * );\n * const gswap = new GSwap({ signer });\n * ```\n */\nexport function createLazyPrivateKeySigner(\n getPrivateKey: PrivateKeyProvider,\n options: LazyPrivateKeySignerOptions = {},\n): GalaChainSigner {\n const expected = options.expectedAddress;\n const expectedLower =\n expected === undefined\n ? undefined\n : normalizeEthereumAccount(expected, true, 'expectedAddress').toLowerCase();\n\n return {\n async signObject<T extends Record<string, unknown>>(\n _methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n const provided: unknown = await keyFrom(getPrivateKey);\n if (typeof provided !== 'string' || provided === '') {\n throw new GalaSDKError('INVALID_PRIVATE_KEY', { reason: 'no_key_provided' });\n }\n const key = normalizePrivateKey(provided);\n try {\n if (expectedLower !== undefined && ethAddressOfPrivateKey(key) !== expectedLower) {\n throw new GalaSDKError('SIGNER_ADDRESS_MISMATCH', {});\n }\n return { ...dto, signature: signNative(key, dto) };\n } finally {\n key.fill(0);\n }\n },\n };\n}\n\n/**\n * A Gala Wallet signer using native GalaChain signing, with an opt-in personal-sign mode.\n *\n * The selected Ethereum account is passed to Gala Wallet. There is NO automatic fallback: a\n * wallet that rejects `native` surfaces its error to the caller, because the only alternative,\n * `personal-sign`, silently recovers a phantom signer on every released Gala Wallet.\n *\n * `scheme: 'personal-sign'` calls\n * `gala_signChainDto([serialize({ ...dto, prefix }), walletAddress, methodName])` and REQUIRES\n * a Gala Wallet build that strips the embedded `prefix` field and hashes `prefix` + the\n * prefix-less canonical body (the chain's scheme). Wallet builds that predate that fix hash the\n * string with the `prefix` field still inside it and the signature recovers to an address\n * nobody holds, so only opt in once the wallet you target has the fix.\n */\nexport class GalaWalletSigner implements GalaChainSigner {\n /** The wallet address supplied to Gala Wallet for each signing request. */\n public readonly walletAddress: string;\n\n /** The signing scheme used for every request; it never changes after construction. */\n public readonly scheme: GalaWalletScheme;\n\n /**\n * Creates a Gala Wallet signer.\n *\n * @example\n * ```typescript\n * const signer = new GalaWalletSigner('0x0123456789012345678901234567890123456789');\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n *\n * @param walletAddress - The account passed to Gala Wallet as the signer address. An Ethereum\n * account is `0x` plus 40 hex digits (Gala Wallet's `eth|...` form is normalized to it and held\n * to the same check); a GalaChain id is `client|` plus 24 hex digits, or the bare 24 hex digits\n * a web app keeps for a direct `client|` login, and is passed through unchanged.\n * @param options - Select native signing (default) or personal-sign explicitly.\n * `'personal-sign'` requires a Gala Wallet build that signs the bare serialized DTO.\n * `selectAddress` is the identity (`client|...` / `eth|...`) Gala Wallet is switched to with\n * `setAddress` before every signature, when the wallet offers it. `wallet` is the Gala Wallet\n * object to sign through (the one an EIP-6963 announcement or a wallet provider holds); without\n * it, `window.gala` is read at every signature.\n */\n constructor(\n walletAddress: string,\n options: {\n scheme?: GalaWalletScheme | undefined;\n selectAddress?: string | undefined;\n wallet?: GalaWalletApi | undefined;\n } = {},\n ) {\n this.walletAddress = normalizeGalaWalletAccount(walletAddress);\n this.scheme = options.scheme ?? 'native';\n if (options.selectAddress !== undefined) assertWalletIdentity(options.selectAddress);\n this.selectAddress = options.selectAddress;\n this.wallet = options.wallet;\n }\n\n /** The identity Gala Wallet is switched to before each signature, if one was given. */\n public readonly selectAddress: string | undefined;\n\n /** The Gala Wallet object this signer signs through; `undefined` reads `window.gala` each time. */\n private readonly wallet: GalaWalletApi | undefined;\n\n /**\n * Signs a DTO through `gala_signChainDto`.\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('AddLiquidity', {\n * token0: 'GALA',\n * token1: 'GUSDC',\n * tickLower: -60,\n * tickUpper: 60,\n * });\n * ```\n */\n public async signObject<T extends Record<string, unknown>>(\n methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n const wallet = this.wallet ?? getWalletProvider();\n\n return withGalaWalletIdentity(wallet, this.selectAddress, async () => {\n if (this.scheme === 'personal-sign') {\n return personalSign(wallet, dto, this.walletAddress, methodName);\n }\n const signature = await wallet.request({\n method: 'gala_signChainDto',\n params: [serialize(dto), this.walletAddress, methodName, 'native'],\n });\n return { ...dto, signature: getNativeSignature(signature) };\n });\n }\n}\n\n/**\n * A personal-sign signer for MetaMask and other EIP-1193 browser wallets.\n *\n * The chain recovers this signature using the EIP-191 wrap applied by the wallet to\n * `personal_sign`. This is the browser-wallet path used by the v2 frontend and resolves the\n * bare `eth|` identity.\n */\nexport class BrowserWalletSigner implements GalaChainSigner {\n /**\n * Creates a browser-wallet signer.\n *\n * Defaults to `personal_sign` — unchanged from every existing integration, since it only ever\n * resolves the bare `eth|` identity and changing that silently would be a real behavior\n * break for anyone already depending on it. Pass `{ scheme: 'eip712' }` to correctly resolve\n * a registered `client|` alias instead, for `RequestTrade`/`AddLiquidity`/`RemoveLiquidity`/\n * `CollectPositionFees` (`EIP712_CAPABLE_METHODS`) — `CreatePool` and any other method still\n * falls back to `personal_sign` even in `'eip712'` mode, since its EIP-712 signing is a\n * separate, unsolved chain-side problem.\n *\n * @example\n * ```typescript\n * const signer = new BrowserWalletSigner(window.ethereum, '0x0123456789012345678901234567890123456789');\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n * @example\n * ```typescript\n * // Correctly resolves a registered client| alias instead of the bare eth| address.\n * const signer = new BrowserWalletSigner(window.ethereum, walletAddress, { scheme: 'eip712' });\n * ```\n */\n constructor(\n private readonly provider: BrowserWalletProvider,\n walletAddress: string,\n options: { scheme?: 'personal-sign' | 'eip712' } = {},\n ) {\n this.walletAddress = normalizeEthereumAccount(walletAddress, false);\n this.scheme = options.scheme ?? 'personal-sign';\n }\n\n /** The selected `0x` Ethereum account every signature is requested for. */\n public readonly walletAddress: string;\n private readonly scheme: 'personal-sign' | 'eip712';\n\n /**\n * Signs the DTO with `eth_signTypedData_v4` (when constructed with `{ scheme: 'eip712' }` and\n * `methodName` is in `EIP712_CAPABLE_METHODS`) or the EIP-1193 `personal_sign` method\n * (otherwise — the default).\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('RequestTrade', {\n * token0: 'GALA',\n * token1: 'GUSDC',\n * fee: 3000,\n * });\n * ```\n */\n public signObject<T extends Record<string, unknown>>(\n methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n if (this.scheme === 'eip712' && EIP712_CAPABLE_METHODS.has(methodName)) {\n return signEIP712(this.provider, methodName, dto, this.walletAddress);\n }\n return personalSign(this.provider, dto, this.walletAddress);\n }\n}\n"],"mappings":"0eAmFA,SAASE,GAAmC,CAE1C,IAAMC,EAASH,WAAa,QAAQ,KACpC,GAAI,CAACG,EACH,MAAM,IAAIC,EAAa,4BAA6B,CAAC,CAAC,EAExD,OAAOD,CACT,CAEA,SAASE,EAAmB,EAAwB,CAMlD,GALI,OAAOC,GAAU,UAKjB,CAAC,6BAA6B,KAAKA,CAAK,EAC1C,MAAM,IAAIF,EAAa,oBAAqB,CAAE,OAAQ,QAAS,CAAC,EAElE,OAAOE,CACT,CAEA,SAASC,EAAqB,EAAwB,CACpD,GAAI,OAAOD,GAAU,UAAY,CAAC,6BAA6B,KAAKA,CAAK,EACvE,MAAM,IAAIF,EAAa,oBAAqB,CAAE,OAAQ,eAAgB,CAAC,EAEzE,OAAOE,CACT,CAiBA,SAAgBE,EAAyB,EAAqC,CAC5EC,EAAuBC,EAAS,SAAS,EACzC,IAAMC,EAAQ,mCAAmC,KAAKD,CAAO,EAC7D,OAAOC,IAAQ,KAAO,IAAA,GAAY,IAAA,GAAY,KAAKA,EAAM,IAC3D,CAEA,SAASC,EACP,EACA,EACA,EAAQ,gBACA,CACRH,EAAuBI,EAASC,CAAK,EACrC,IAAMC,EAAaC,EAAmBR,EAAyBK,CAAO,GAAKA,EAAWA,EACtF,GAAI,CAAC,uBAAuB,KAAKE,CAAU,EACzC,MAAM,IAAIX,EAAa,yBAA0B,CAAE,QAAO,MAAOS,CAAQ,CAAC,EAK5E,OAAOE,CACT,CASA,SAASE,EAA2B,EAAyB,CAC3DR,EAAuBI,EAAS,eAAe,EAC/C,IAAMK,EAAM,4BAA4B,KAAKL,CAAO,EACpD,GAAIK,I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F,EASac,EAAb,KAA4D,CAuB1D,YACE,EACA,EACA,EAAmD,CAAC,EACpD,CAHiB,KAAA,SAAA3B,EASHlC,EAAA,KAAA,gBAAA,IAAA,EAAA,EACCA,EAAA,KAAA,SAAA,IAAA,EAAA,EANf,KAAK,cAAgBW,EAAyBsB,EAAe,EAAK,EAClE,KAAK,OAASsB,EAAQ,QAAU,eAClC,CAoBA,WACE,EACA,EACuB,CAIvB,OAHI,KAAK,SAAW,UAAYO,EAAuB,IAAI/B,CAAU,EAC5DI,EAAW,KAAK,SAAUJ,EAAYH,EAAK,KAAK,aAAa,EAE/DH,EAAa,KAAK,SAAUG,EAAK,KAAK,aAAa,CAC5D,CACF"}
1
+ {"version":3,"file":"signers.js","names":["globalObject","_defineProperty","getWalletProvider","wallet","GalaSDKError","getNativeSignature","value","getPersonalSignature","ethereumAddressOfAccount","assertNoEthZeroXPrefix","account","match","normalizeEthereumAccount","address","field","normalized","allowGalaPrefix","normalizeGalaWalletAccount","eth","assertWalletIdentity","identity","walletIdentityQueue","withGalaWalletIdentity","setAddress","signWith","run","personalSign","prefix","personalSignPrefixFor","dto","payload","params","methodName","serialize","walletAddress","provider","signEIP712","buildEIP712Payload","domain","eip712DomainFor","fixpointPrefixFor","completedDto","message","eip712Domain","types","PrivateKeySigner","normalizePrivateKey","privateKey","signature","signNative","keyFrom","getPrivateKey","cause","isGalaError","createLazyPrivateKeySigner","expected","options","expectedLower","provided","key","ethAddressOfPrivateKey","GalaWalletSigner","BrowserWalletSigner","EIP712_CAPABLE_METHODS"],"sources":["../../../src/classes/signers.ts"],"sourcesContent":["import { GalaSDKError, isGalaError } from './gala_sdk_error.js';\nimport { assertNoEthZeroXPrefix } from '../writes/identity.js';\nimport {\n buildEIP712Payload,\n EIP712_CAPABLE_METHODS,\n eip712DomainFor,\n type EIP712DomainValue,\n type EIP712Types,\n} from '../utils/eip712.js';\nimport {\n ethAddressOfPrivateKey,\n fixpointPrefixFor,\n normalizePrivateKey,\n personalSignPrefixFor,\n serialize,\n signNative,\n} from '../utils/signing.js';\n\n// Personal-sign prefix, computed the way THE CHAIN verifies it.\n//\n// GalaChain (SDK 3.x) recovers a personal-signed DTO from\n// keccak256(<prefix field> + <canonical JSON of the DTO WITHOUT the prefix field>)\n// and a browser wallet's `personal_sign` (EIP-191) hashes\n// \"\\u0019Ethereum Signed Message:\\n\" + <byte length of message> + <message>.\n// They agree exactly when the wallet signs the bare canonical DTO and `prefix` is the EIP-191\n// header for that message's UTF-8 BYTE length. Any other message still yields a valid-looking\n// signature — it just recovers to an address nobody holds. This SDK used to embed `prefix` in\n// the signed message (the SDK 1.10 client recipe): observed on stage 2026-09-23, such a\n// MetaMask-signed CreatePool executed on chain under a phantom creator, and the swap backend's\n// write guard now rejects that shape outright.\n//\n// `@gala-chain/connect`'s prefix helper must NOT be used for wallet `personal_sign`: its\n// fixpoint counts the prefix itself and targets the SDK's raw-payload signer. The same header\n// is also what Gala Wallet's `gala_signChainDto` (personal-sign scheme) prepends before hashing,\n// so one value serves both paths.\n//\n// The header itself is computed by `personalSignPrefixFor` in ../utils/signing.ts.\n\n/** The signing schemes supported by the Gala Wallet signer. */\nexport type GalaWalletScheme = 'native' | 'personal-sign';\n\n/** The request surface used by an EIP-1193 browser wallet. */\nexport interface BrowserWalletProvider {\n request(args: { method: string; params?: unknown[] }): Promise<unknown>;\n}\n\n/** The Gala Wallet extension's API (`window.gala`, or the same object from an EIP-6963 announcement). */\nexport interface GalaWalletApi {\n request(args: { method: string; params?: unknown[] }): Promise<unknown>;\n /** Gala Wallet's \"act as this account\" switch; absent on other providers. */\n setAddress?: (address: string) => Promise<void>;\n}\n\ninterface WindowWithGala {\n gala?: GalaWalletApi;\n}\n\ninterface GlobalWithWindow {\n window?: WindowWithGala;\n}\n\n/** A DTO together with the signature that belongs in the gateway request body. */\nexport type SignedDto<T extends Record<string, unknown>> = T & { signature: string };\n\n/**\n * A signer for complete GalaChain write bodies.\n *\n * Implementations return the DTO fields together with the signature that belongs in the\n * gateway request body. Signer identity is recovered from that signature; implementations do\n * not add signer hints, typed-data metadata, or a domain.\n */\nexport interface GalaChainSigner {\n /**\n * Signs a DTO for a named GalaChain contract method.\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n */\n signObject<T extends Record<string, unknown>>(methodName: string, dto: T): Promise<SignedDto<T>>;\n}\n\nfunction getWalletProvider(): GalaWalletApi {\n const globalObject = globalThis as GlobalWithWindow;\n const wallet = globalObject.window?.gala;\n if (!wallet) {\n throw new GalaSDKError('GALA_WALLET_NOT_AVAILABLE', {});\n }\n return wallet;\n}\n\nfunction getNativeSignature(value: unknown): string {\n if (typeof value !== 'string') {\n throw new GalaSDKError('INVALID_SIGNATURE', { scheme: 'native' });\n }\n // 130 hex digits (r || s || v), bare as Gala Wallet returns it or `0x`-prefixed; passed on\n // verbatim, because the backend recovers the signer from either spelling.\n if (!/^(?:0x)?[0-9a-fA-F]{130}$/u.test(value)) {\n throw new GalaSDKError('INVALID_SIGNATURE', { scheme: 'native' });\n }\n return value;\n}\n\nfunction getPersonalSignature(value: unknown): string {\n if (typeof value !== 'string' || !/^(?:0x)?[0-9a-fA-F]{130}$/u.test(value)) {\n throw new GalaSDKError('INVALID_SIGNATURE', { scheme: 'personal-sign' });\n }\n return value;\n}\n\n/**\n * The `0x`-prefixed Ethereum address a Gala account is signed by, or `undefined` when the account\n * names no key (a `client|` alias or a bare GalaChain id is not derivable from a key). Accepts\n * `0x` plus 40 hex digits and `eth|` plus 40 hex digits; the caller's casing is kept. `eth|0x...`\n * is not an address form and is refused. For {@link LazyPrivateKeySignerOptions.expectedAddress}, which should only be set for\n * an account whose key can be checked.\n *\n * @example\n * ```ts\n * createLazyPrivateKeySigner(getKey, { expectedAddress: ethereumAddressOfAccount(account) });\n * ```\n *\n * @throws GalaSDKError `INVALID_ETH_USER_REF_PREFIX` for `eth|0x...` (refused, never read as\n * \"names no key\", which would switch a signer's address check off).\n */\nexport function ethereumAddressOfAccount(account: string): string | undefined {\n assertNoEthZeroXPrefix(account, 'account');\n const match = /^(?:eth\\||0x)([0-9a-fA-F]{40})$/u.exec(account);\n return match?.[1] === undefined ? undefined : `0x${match[1]}`;\n}\n\nfunction normalizeEthereumAccount(\n address: string,\n allowGalaPrefix: boolean,\n field = 'walletAddress',\n): string {\n assertNoEthZeroXPrefix(address, field);\n const normalized = allowGalaPrefix ? (ethereumAddressOfAccount(address) ?? address) : address;\n if (!/^0x[0-9a-fA-F]{40}$/u.test(normalized)) {\n throw new GalaSDKError('INVALID_WALLET_ADDRESS', { field, value: address });\n }\n // The caller's casing is kept on purpose: the Gala web apps and the wallet hand the wallet the\n // checksummed account, and EIP-1193 / Gala Wallet accept any case, so passing the value through\n // unchanged is the only choice that cannot differ from what they send.\n return normalized;\n}\n\n/**\n * The account handed to Gala Wallet as the signer address. An Ethereum account is held to the\n * same strict check as ever (`0x` plus 40 hex digits; `eth|` plus 40 hex digits is normalized to\n * it; `eth|0x...` is refused). A GalaChain id the wallet can also be asked to sign for is passed\n * through verbatim: `client|` plus 24 hex digits, or the bare 24 hex digits that a web app keeps\n * after a direct `client|` login. Nothing else is accepted.\n */\nfunction normalizeGalaWalletAccount(address: string): string {\n assertNoEthZeroXPrefix(address, 'walletAddress');\n const eth = /^eth\\|([0-9a-fA-F]{40})$/u.exec(address);\n if (eth?.[1] !== undefined) return `0x${eth[1]}`;\n if (/^0x[0-9a-fA-F]{40}$/u.test(address) || /^(?:client\\|)?[0-9a-fA-F]{24}$/u.test(address)) {\n return address;\n }\n throw new GalaSDKError('INVALID_WALLET_ADDRESS', { field: 'walletAddress', value: address });\n}\n\n/** An identity Gala Wallet can act as: an account form above, any `eth|`/`client|` alias, verbatim. */\nfunction assertWalletIdentity(identity: string): void {\n assertNoEthZeroXPrefix(identity, 'selectAddress');\n if (\n !/^(?:eth\\|[0-9a-fA-F]{40}|0x[0-9a-fA-F]{40}|(?:client\\|)?[0-9a-fA-F]{24})$/u.test(identity)\n ) {\n throw new GalaSDKError('INVALID_WALLET_ADDRESS', { field: 'selectAddress', value: identity });\n }\n}\n\n/** Provider-wide queue: `setAddress` + the signature request must not interleave across signers. */\nconst walletIdentityQueue = new WeakMap<object, Promise<unknown>>();\n\n/**\n * Runs `signWith` with `identity` selected on a Gala Wallet that supports `setAddress`. Gala\n * Wallet holds ONE current account, so two signatures for different identities in flight at once\n * would sign as whichever selection came last; the pair (select, sign) is therefore serialized\n * per wallet object, across every signer and provider that signs through it\n * (`GalaWalletSigner`, `./providers`' `GalaWalletProvider`). A failed selection fails the\n * signature (nothing is requested). Without an identity, or on a wallet without `setAddress`, it\n * just runs `signWith`.\n *\n * @example\n * ```typescript\n * const signature = await withGalaWalletIdentity(window.gala, 'eth|70997970C51812dc3A010C7d01b50e0d17dc79C8', () =>\n * window.gala.request({ method: 'personal_sign', params: [hexMessage, address] }),\n * );\n * ```\n */\nexport function withGalaWalletIdentity<T>(\n wallet: GalaWalletApi,\n identity: string | undefined,\n signWith: () => Promise<T>,\n): Promise<T> {\n const { setAddress } = wallet;\n if (identity === undefined || typeof setAddress !== 'function') return signWith();\n const previous = walletIdentityQueue.get(wallet) ?? Promise.resolve();\n const run = previous\n .catch(() => undefined)\n .then(async () => {\n await setAddress.call(wallet, identity);\n return signWith();\n });\n walletIdentityQueue.set(wallet, run);\n return run;\n}\n\nfunction personalSign<T extends Record<string, unknown>>(\n provider: GalaWalletApi | BrowserWalletProvider,\n dto: T,\n walletAddress: string,\n methodName?: string,\n): Promise<T & { prefix: string; signature: string }> {\n const prefix = personalSignPrefixFor(dto);\n const payload = { ...dto, prefix };\n // A browser wallet's `personal_sign` applies the EIP-191 header ITSELF, so it must sign the\n // bare DTO; Gala Wallet's `gala_signChainDto` (personal-sign scheme) instead extracts the\n // `prefix` field from what it is handed and prepends it before hashing, so it is handed the\n // prefixed payload. Both submit `{ ...dto, prefix, signature }`.\n const params =\n methodName !== undefined\n ? [serialize(payload), walletAddress, methodName]\n : [serialize(dto), walletAddress];\n\n return provider\n .request({ method: methodName !== undefined ? 'gala_signChainDto' : 'personal_sign', params })\n .then((value) => ({ ...payload, signature: getPersonalSignature(value) }));\n}\n\n/**\n * Signs a DTO via genuine EIP-712 (`eth_signTypedData_v4`) — correctly resolves the `client|`\n * identity, unlike `personal_sign`, for the operations in `EIP712_CAPABLE_METHODS`.\n *\n * Constructs the raw JSON-RPC payload by hand (`{domain, types: {...types, EIP712Domain},\n * primaryType, message}`) rather than depending on ethers.js, matching exactly what\n * `ethers.TypedDataEncoder.getPayload`/`Wallet.signTypedData` produce internally — verified\n * byte-for-byte equivalent (same recovered address from the same signature against both\n * constructions) before this shipped, since the core SDK deliberately has no ethers dependency.\n */\nasync function signEIP712<T extends Record<string, unknown>>(\n provider: BrowserWalletProvider,\n methodName: string,\n dto: T,\n walletAddress: string,\n): Promise<T & { types: EIP712Types; domain: EIP712DomainValue; signature: string }> {\n const { completedDto, types } = buildEIP712Payload(methodName, dto);\n // The wallet's LIVE chain id, read on every signature: a user can switch networks after\n // connecting, and a cached or hardcoded id would sign a domain MetaMask itself rejects.\n const domain = eip712DomainFor(await provider.request({ method: 'eth_chainId', params: [] }));\n // The body `prefix` is not part of the EIP-712 `types`, so it is never hashed; it carries the\n // connect-style fixpoint value only to keep the submitted body byte-identical to what the Gala\n // web apps have always sent.\n const prefix = fixpointPrefixFor(completedDto);\n const message = { ...completedDto, prefix };\n const eip712Domain = [\n { name: 'name', type: 'string' },\n { name: 'chainId', type: 'uint256' },\n ];\n const payload = {\n domain,\n types: { ...types, EIP712Domain: eip712Domain },\n primaryType: methodName,\n message,\n };\n\n const value = await provider.request({\n method: 'eth_signTypedData_v4',\n params: [walletAddress, JSON.stringify(payload)],\n });\n // Key order matches the body the Gala web apps submit: ..., prefix, signature, types, domain.\n return {\n ...(message as T & { prefix: string }),\n signature: getPersonalSignature(value),\n types,\n domain,\n };\n}\n\n/**\n * A GalaChain native signer backed by a secp256k1 private key.\n *\n * Native signing produces the bare GalaChain signature format, without a personal-sign prefix\n * or EIP-712 metadata. The private-key identity is recovered by the chain.\n */\nexport class PrivateKeySigner implements GalaChainSigner {\n private readonly privateKey: Uint8Array;\n\n /**\n * Creates a native signer from a hex or base64 secp256k1 private key.\n *\n * @example\n * ```typescript\n * const signer = new PrivateKeySigner('1'.padStart(64, '0'));\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n */\n constructor(privateKey: string) {\n this.privateKey = normalizePrivateKey(privateKey);\n }\n\n /**\n * Signs the DTO with GalaChain native signing.\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('RequestTrade', {\n * token0: 'GALA',\n * token1: 'GUSDC',\n * fee: 3000,\n * });\n * ```\n */\n public signObject<T extends Record<string, unknown>>(\n _methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n const signature = signNative(this.privateKey, dto);\n return Promise.resolve({ ...dto, signature });\n }\n}\n\n/** Supplies a private key at sign time: a hex/base64 string, possibly fetched asynchronously. */\nexport type PrivateKeyProvider = () => Promise<string> | string;\n\n/** Options for {@link createLazyPrivateKeySigner}. */\nexport interface LazyPrivateKeySignerOptions {\n /**\n * When set, every signature first checks that the fetched key belongs to this account (`0x...`\n * or the Gala `eth|<40 hex>` form, case-insensitive; `eth|0x...` is refused at creation) and\n * refuses to sign otherwise (`SIGNER_ADDRESS_MISMATCH`). Use it when the key lives in a slot another surface can switch\n * between the moment a request was approved and the moment it is signed.\n */\n expectedAddress?: string | undefined;\n}\n\n/**\n * Calls the app's key provider. Whatever it throws or rejects with is the app's own failure to\n * produce a key before anything was signed or sent, so it becomes `KEY_PROVIDER_FAILED` (the\n * original is `cause`); an SDK error is already catalogued and passes through.\n */\nasync function keyFrom(getPrivateKey: PrivateKeyProvider): Promise<unknown> {\n try {\n return await getPrivateKey();\n } catch (cause: unknown) {\n throw isGalaError(cause) ? cause : new GalaSDKError('KEY_PROVIDER_FAILED', {}, { cause });\n }\n}\n\n/**\n * Creates the native-signing equivalent of {@link PrivateKeySigner} for apps that must not hold a\n * key in a long-lived object (an extension that reads its session key at sign time).\n *\n * `getPrivateKey` is called once per `signObject` call, never cached, never shared between calls\n * (concurrent signatures each fetch their own key), and the normalized key bytes are zeroed\n * before `signObject` settles, also on failure. A rejection or exception from `getPrivateKey` (the\n * app's \"wallet is locked\", a storage read that failed) is a `KEY_PROVIDER_FAILED` error with the\n * original error as `cause`: nothing has been sent, so `classifyFailure` says `not_sent` and Retry\n * is safe, and the app needs no error class of its own to tell this apart. A provider that returns\n * no usable string (`''`, `undefined`) is `INVALID_PRIVATE_KEY` with `reason: 'no_key_provided'`,\n * classified the same way; any other key that is not a valid secp256k1 key string is an\n * `INVALID_PRIVATE_KEY` error. An SDK error the provider throws itself is passed through.\n * Signatures are byte-identical to `new PrivateKeySigner(key).signObject(...)`.\n *\n * A JavaScript string cannot be wiped; the provider owns the lifetime of the string it returns.\n *\n * @example\n * ```typescript\n * const signer = createLazyPrivateKeySigner(\n * () => SecurityHelper.getSessionSecret(SecurityHelper.SESSION_PRIVATE_KEY_KEY),\n * { expectedAddress: account.address },\n * );\n * const gswap = new GSwap({ signer });\n * ```\n */\nexport function createLazyPrivateKeySigner(\n getPrivateKey: PrivateKeyProvider,\n options: LazyPrivateKeySignerOptions = {},\n): GalaChainSigner {\n const expected = options.expectedAddress;\n const expectedLower =\n expected === undefined\n ? undefined\n : normalizeEthereumAccount(expected, true, 'expectedAddress').toLowerCase();\n\n return {\n async signObject<T extends Record<string, unknown>>(\n _methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n const provided: unknown = await keyFrom(getPrivateKey);\n if (typeof provided !== 'string' || provided === '') {\n throw new GalaSDKError('INVALID_PRIVATE_KEY', { reason: 'no_key_provided' });\n }\n const key = normalizePrivateKey(provided);\n try {\n if (expectedLower !== undefined && ethAddressOfPrivateKey(key) !== expectedLower) {\n throw new GalaSDKError('SIGNER_ADDRESS_MISMATCH', {});\n }\n return { ...dto, signature: signNative(key, dto) };\n } finally {\n key.fill(0);\n }\n },\n };\n}\n\n/**\n * A Gala Wallet signer using native GalaChain signing, with an opt-in personal-sign mode.\n *\n * The selected Ethereum account is passed to Gala Wallet. There is NO automatic fallback: a\n * wallet that rejects `native` surfaces its error to the caller, because the only alternative,\n * `personal-sign`, silently recovers a phantom signer on every released Gala Wallet.\n *\n * `scheme: 'personal-sign'` calls\n * `gala_signChainDto([serialize({ ...dto, prefix }), walletAddress, methodName])` and REQUIRES\n * a Gala Wallet build that strips the embedded `prefix` field and hashes `prefix` + the\n * prefix-less canonical body (the chain's scheme). Wallet builds that predate that fix hash the\n * string with the `prefix` field still inside it and the signature recovers to an address\n * nobody holds, so only opt in once the wallet you target has the fix.\n */\nexport class GalaWalletSigner implements GalaChainSigner {\n /** The wallet address supplied to Gala Wallet for each signing request. */\n public readonly walletAddress: string;\n\n /** The signing scheme used for every request; it never changes after construction. */\n public readonly scheme: GalaWalletScheme;\n\n /**\n * Creates a Gala Wallet signer.\n *\n * @example\n * ```typescript\n * const signer = new GalaWalletSigner('0x0123456789012345678901234567890123456789');\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n *\n * @param walletAddress - The account passed to Gala Wallet as the signer address. An Ethereum\n * account is `0x` plus 40 hex digits (Gala Wallet's `eth|...` form is normalized to it and held\n * to the same check); a GalaChain id is `client|` plus 24 hex digits, or the bare 24 hex digits\n * a web app keeps for a direct `client|` login, and is passed through unchanged.\n * @param options - Select native signing (default) or personal-sign explicitly.\n * `'personal-sign'` requires a Gala Wallet build that signs the bare serialized DTO.\n * `selectAddress` is the identity (`client|...` / `eth|...`) Gala Wallet is switched to with\n * `setAddress` before every signature, when the wallet offers it. `wallet` is the Gala Wallet\n * object to sign through (the one an EIP-6963 announcement or a wallet provider holds); without\n * it, `window.gala` is read at every signature.\n */\n constructor(\n walletAddress: string,\n options: {\n scheme?: GalaWalletScheme | undefined;\n selectAddress?: string | undefined;\n wallet?: GalaWalletApi | undefined;\n } = {},\n ) {\n this.walletAddress = normalizeGalaWalletAccount(walletAddress);\n this.scheme = options.scheme ?? 'native';\n if (options.selectAddress !== undefined) assertWalletIdentity(options.selectAddress);\n this.selectAddress = options.selectAddress;\n this.wallet = options.wallet;\n }\n\n /** The identity Gala Wallet is switched to before each signature, if one was given. */\n public readonly selectAddress: string | undefined;\n\n /** The Gala Wallet object this signer signs through; `undefined` reads `window.gala` each time. */\n private readonly wallet: GalaWalletApi | undefined;\n\n /**\n * Signs a DTO through `gala_signChainDto`.\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('AddLiquidity', {\n * token0: 'GALA',\n * token1: 'GUSDC',\n * tickLower: -60,\n * tickUpper: 60,\n * });\n * ```\n */\n public async signObject<T extends Record<string, unknown>>(\n methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n const wallet = this.wallet ?? getWalletProvider();\n\n return withGalaWalletIdentity(wallet, this.selectAddress, async () => {\n if (this.scheme === 'personal-sign') {\n return personalSign(wallet, dto, this.walletAddress, methodName);\n }\n const signature = await wallet.request({\n method: 'gala_signChainDto',\n params: [serialize(dto), this.walletAddress, methodName, 'native'],\n });\n return { ...dto, signature: getNativeSignature(signature) };\n });\n }\n}\n\n/**\n * A personal-sign signer for MetaMask and other EIP-1193 browser wallets.\n *\n * The chain recovers this signature using the EIP-191 wrap applied by the wallet to\n * `personal_sign`. This is the browser-wallet path used by the v2 frontend and resolves the\n * bare `eth|` identity.\n */\nexport class BrowserWalletSigner implements GalaChainSigner {\n /**\n * Creates a browser-wallet signer.\n *\n * Defaults to `personal_sign` — unchanged from every existing integration, since it only ever\n * resolves the bare `eth|` identity and changing that silently would be a real behavior\n * break for anyone already depending on it. Pass `{ scheme: 'eip712' }` to correctly resolve\n * a registered `client|` alias instead, for `RequestTrade`/`AddLiquidity`/`RemoveLiquidity`/\n * `CollectPositionFees` (`EIP712_CAPABLE_METHODS`) — `CreatePool` and any other method still\n * falls back to `personal_sign` even in `'eip712'` mode, since its EIP-712 signing is a\n * separate, unsolved chain-side problem.\n *\n * @example\n * ```typescript\n * const signer = new BrowserWalletSigner(window.ethereum, '0x0123456789012345678901234567890123456789');\n * const signed = await signer.signObject('RequestTrade', { token0: 'GALA', token1: 'GUSDC' });\n * ```\n * @example\n * ```typescript\n * // Correctly resolves a registered client| alias instead of the bare eth| address.\n * const signer = new BrowserWalletSigner(window.ethereum, walletAddress, { scheme: 'eip712' });\n * ```\n */\n constructor(\n private readonly provider: BrowserWalletProvider,\n walletAddress: string,\n options: { scheme?: 'personal-sign' | 'eip712' } = {},\n ) {\n this.walletAddress = normalizeEthereumAccount(walletAddress, false);\n this.scheme = options.scheme ?? 'personal-sign';\n }\n\n /** The selected `0x` Ethereum account every signature is requested for. */\n public readonly walletAddress: string;\n private readonly scheme: 'personal-sign' | 'eip712';\n\n /**\n * Signs the DTO with `eth_signTypedData_v4` (when constructed with `{ scheme: 'eip712' }` and\n * `methodName` is in `EIP712_CAPABLE_METHODS`) or the EIP-1193 `personal_sign` method\n * (otherwise — the default).\n *\n * @example\n * ```typescript\n * const signed = await signer.signObject('RequestTrade', {\n * token0: 'GALA',\n * token1: 'GUSDC',\n * fee: 3000,\n * });\n * ```\n */\n public signObject<T extends Record<string, unknown>>(\n methodName: string,\n dto: T,\n ): Promise<SignedDto<T>> {\n if (this.scheme === 'eip712' && EIP712_CAPABLE_METHODS.has(methodName)) {\n return signEIP712(this.provider, methodName, dto, this.walletAddress);\n }\n return personalSign(this.provider, dto, this.walletAddress);\n }\n}\n"],"mappings":"A,0eAmFA,SAASE,GAAmC,CAE1C,IAAMC,EAASH,WAAa,QAAQ,KACpC,GAAI,CAACG,EACH,MAAM,IAAIC,EAAa,4BAA6B,CAAC,CAAC,EAExD,OAAOD,CACT,CAEA,SAASE,EAAmB,EAAwB,CAMlD,GALI,OAAOC,GAAU,UAKjB,CAAC,6BAA6B,KAAKA,CAAK,EAC1C,MAAM,IAAIF,EAAa,oBAAqB,CAAE,OAAQ,QAAS,CAAC,EAElE,OAAOE,CACT,C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GalaChain deployment: `prod` (mainnet) or `stage` (testnet). */\nexport type GalaChainEnv = 'prod' | 'stage';\n\n/** The product-independent endpoints of one GalaChain deployment. */\nexport interface GalaChainEnvironmentConfig {\n /** The public GalaChain gateway (`GatewayReads` / `GatewayWrites` `gatewayBaseUrl`). */\n readonly gatewayBaseUrl: string;\n /** The DEX API platform (GalaConnect: bridge, wrap and referral reads). */\n readonly dexApiBaseUrl: string;\n}\n\n/**\n * The built-in endpoints of each deployment. A product SDK extends these with its own backends\n * (launchpad-sdk's launchpad and bundler URLs, gswap-sdk's swap backend); it never redefines them.\n */\nexport const GALA_CHAIN_ENVIRONMENTS: Readonly<Record<GalaChainEnv, GalaChainEnvironmentConfig>> =\n Object.freeze({\n prod: Object.freeze({\n gatewayBaseUrl: 'https://gateway-mainnet.galachain.com',\n dexApiBaseUrl: 'https://dex-api-platform-dex-prod-gala.gala.com',\n }),\n stage: Object.freeze({\n gatewayBaseUrl: 'https://gateway-testnet.galachain.com',\n dexApiBaseUrl: 'https://dex-api-platform-dex-stage-gala.gala.com',\n }),\n });\n"],"mappings":"AAeA,MAAaA,EACX,OAAO,OAAO,CACZ,KAAM,OAAO,OAAO,CAClB,eAAgB,wCAChB,cAAe,iDACjB,CAAC,EACD,MAAO,OAAO,OAAO,CACnB,eAAgB,wCAChB,cAAe,kDACjB,CAAC,CACH,CAAC"}
1
+ {"version":3,"file":"environments.js","names":["GALA_CHAIN_ENVIRONMENTS"],"sources":["../../../src/config/environments.ts"],"sourcesContent":["/** A GalaChain deployment: `prod` (mainnet) or `stage` (testnet). */\nexport type GalaChainEnv = 'prod' | 'stage';\n\n/** The product-independent endpoints of one GalaChain deployment. */\nexport interface GalaChainEnvironmentConfig {\n /** The public GalaChain gateway (`GatewayReads` / `GatewayWrites` `gatewayBaseUrl`). */\n readonly gatewayBaseUrl: string;\n /** The DEX API platform (GalaConnect: bridge, wrap and referral reads). */\n readonly dexApiBaseUrl: string;\n}\n\n/**\n * The built-in endpoints of each deployment. A product SDK extends these with its own backends\n * (launchpad-sdk's launchpad and bundler URLs, gswap-sdk's swap backend); it never redefines them.\n */\nexport const GALA_CHAIN_ENVIRONMENTS: Readonly<Record<GalaChainEnv, GalaChainEnvironmentConfig>> =\n Object.freeze({\n prod: Object.freeze({\n gatewayBaseUrl: 'https://gateway-mainnet.galachain.com',\n dexApiBaseUrl: 'https://dex-api-platform-dex-prod-gala.gala.com',\n }),\n stage: Object.freeze({\n gatewayBaseUrl: 'https://gateway-testnet.galachain.com',\n dexApiBaseUrl: 'https://dex-api-platform-dex-stage-gala.gala.com',\n }),\n });\n"],"mappings":"AAeA,MAAaA,EACX,OAAO,OAAO,CACZ,KAAM,OAAO,OAAO,CAClB,eAAgB,wCAChB,cAAe,iDACjB,CAAC,EACD,MAAO,OAAO,OAAO,CACnB,eAAgB,wCAChB,cAAe,kDACjB,CAAC,CACH,CAAC,E"}