@gala-chain/gala-core-sdk 1.1.0-beta.9 → 1.2.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -2
- package/dist/bridge.cjs +1 -11
- package/dist/bridge.cjs.map +1 -1
- package/dist/bridge.mjs +1 -11
- package/dist/bridge.mjs.map +1 -1
- package/dist/browser/bridge.js +1 -1
- package/dist/browser/bridge.js.map +1 -1
- package/dist/browser/classes/error_catalog.js +1 -1
- package/dist/browser/classes/error_catalog.js.map +1 -1
- package/dist/browser/classes/error_phase_table.js +1 -1
- package/dist/browser/classes/error_phase_table.js.map +1 -1
- package/dist/browser/index.js +1 -1
- package/dist/browser/reads/gateway_reads.js +1 -1
- package/dist/browser/reads/nft_collections.js +2 -0
- package/dist/browser/reads/nft_collections.js.map +1 -0
- package/dist/browser/reads/nft_fees.js +2 -0
- package/dist/browser/reads/nft_fees.js.map +1 -0
- package/dist/browser/reads/request.js +1 -1
- package/dist/browser/reads/request.js.map +1 -1
- package/dist/browser/utils/dto_operation.js +1 -1
- package/dist/browser/utils/dto_operation.js.map +1 -1
- package/dist/browser/utils/transport.js +1 -1
- package/dist/browser/version.js +1 -1
- package/dist/browser/version.js.map +1 -1
- package/dist/browser/writes/gateway_writes.js +1 -1
- package/dist/browser/writes/gateway_writes.js.map +1 -1
- package/dist/browser/writes/identity.js +1 -1
- package/dist/browser/writes/identity.js.map +1 -1
- package/dist/browser/writes/nft.js +2 -0
- package/dist/browser/writes/nft.js.map +1 -0
- package/dist/browser/writes/nft_fee.js +2 -0
- package/dist/browser/writes/nft_fee.js.map +1 -0
- package/dist/browser/writes/submit.js +1 -1
- package/dist/browser/writes/submit.js.map +1 -1
- package/dist/browser/writes/types.js.map +1 -1
- package/dist/index.cjs +761 -141
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +284 -7
- package/dist/index.d.ts +284 -7
- package/dist/index.mjs +753 -142
- package/dist/index.mjs.map +1 -1
- package/package.json +32 -30
package/dist/index.cjs
CHANGED
|
@@ -85,6 +85,20 @@ const INVALID_TOKEN_REFERENCE_REASONS = [
|
|
|
85
85
|
"bad_instance"
|
|
86
86
|
];
|
|
87
87
|
/**
|
|
88
|
+
* Why an NFT read's, write's or fee quote's input is refused (`INVALID_NFT_INPUT.params.reason`).
|
|
89
|
+
* A token for the app to map to its own text.
|
|
90
|
+
*/
|
|
91
|
+
const INVALID_NFT_INPUT_REASONS = [
|
|
92
|
+
"not_a_string",
|
|
93
|
+
"empty",
|
|
94
|
+
"bad_characters",
|
|
95
|
+
"not_a_positive_whole_number",
|
|
96
|
+
"above_mint_limit",
|
|
97
|
+
"bad_public_key",
|
|
98
|
+
"bad_authorities",
|
|
99
|
+
"bad_collection_name"
|
|
100
|
+
];
|
|
101
|
+
/**
|
|
88
102
|
* The `GatewayWrites` options that are refused when missing or of the wrong type
|
|
89
103
|
* (`INVALID_WRITES_OPTION.params.option`). `walletAddress`, `requestTimeoutMs` and
|
|
90
104
|
* `uniqueKeyPrefix` have codes of their own (`INVALID_WALLET_ADDRESS`, `INVALID_TIMEOUT`,
|
|
@@ -565,6 +579,14 @@ const GALA_ERROR_CATALOG = {
|
|
|
565
579
|
template: "The lock name must be a string (got a {valueType}).",
|
|
566
580
|
params: { valueType: "string" }
|
|
567
581
|
},
|
|
582
|
+
INVALID_NFT_INPUT: {
|
|
583
|
+
phase: "pre_send",
|
|
584
|
+
template: "Invalid NFT input {field}: {reason}.",
|
|
585
|
+
params: {
|
|
586
|
+
field: "string",
|
|
587
|
+
reason: INVALID_NFT_INPUT_REASONS
|
|
588
|
+
}
|
|
589
|
+
},
|
|
568
590
|
NO_TOKEN_NAME_RESOLVER: {
|
|
569
591
|
phase: "pre_send",
|
|
570
592
|
template: "The token name \"{tokenName}\" cannot be resolved: no tokenNameResolver is configured. Pass its tokenClassKey instead.",
|
|
@@ -916,6 +938,7 @@ const GALA_ERROR_PHASE_BY_CODE = {
|
|
|
916
938
|
INVALID_TOKEN_BATCH: "pre_send",
|
|
917
939
|
INVALID_LOCK_EXPIRES: "pre_send",
|
|
918
940
|
INVALID_LOCK_NAME: "pre_send",
|
|
941
|
+
INVALID_NFT_INPUT: "pre_send",
|
|
919
942
|
NO_TOKEN_NAME_RESOLVER: "pre_send",
|
|
920
943
|
TOKEN_NAME_RESOLUTION_FAILED: "pre_send",
|
|
921
944
|
GATEWAY_WRITE_OUTCOME_UNKNOWN: "in_flight",
|
|
@@ -999,12 +1022,12 @@ const GALA_ERROR_PHASES = [
|
|
|
999
1022
|
* recognise each other's errors, which `instanceof` cannot do.
|
|
1000
1023
|
*/
|
|
1001
1024
|
const GALA_ERROR_BRAND = Symbol.for("@gala-chain/gala-core-sdk/error");
|
|
1002
|
-
function isRecord$
|
|
1025
|
+
function isRecord$7(value) {
|
|
1003
1026
|
return typeof value === "object" && value !== null;
|
|
1004
1027
|
}
|
|
1005
1028
|
/** True when `value` carries the SDK error brand (a real `GalaSDKError`, from any copy of the SDK). */
|
|
1006
1029
|
function hasGalaErrorBrand(value) {
|
|
1007
|
-
return isRecord$
|
|
1030
|
+
return isRecord$7(value) && value[GALA_ERROR_BRAND] === true;
|
|
1008
1031
|
}
|
|
1009
1032
|
/**
|
|
1010
1033
|
* True when `value` is an SDK error (it carries the brand) or a plain-object VIEW of one: a string
|
|
@@ -1020,7 +1043,7 @@ function hasGalaErrorBrand(value) {
|
|
|
1020
1043
|
*/
|
|
1021
1044
|
function isGalaErrorLike(value) {
|
|
1022
1045
|
if (hasGalaErrorBrand(value)) return true;
|
|
1023
|
-
return isRecord$
|
|
1046
|
+
return isRecord$7(value) && typeof value["code"] === "string" && isRecord$7(value["params"]) && !Array.isArray(value["params"]);
|
|
1024
1047
|
}
|
|
1025
1048
|
|
|
1026
1049
|
//#endregion
|
|
@@ -1223,6 +1246,15 @@ const CLIENT_ALIAS = /^client\|[A-Za-z0-9_-]+$/u;
|
|
|
1223
1246
|
/** `eth|0x...`: not a user reference. An `eth|` reference is followed by the digits alone. */
|
|
1224
1247
|
const ETH_WITH_0X = /^eth\|0[xX](.*)$/su;
|
|
1225
1248
|
/**
|
|
1249
|
+
* `value` with the part before its first `|` lower-cased and everything after it exactly as written (a value with no
|
|
1250
|
+
* `|` is returned as is): `Client|X` is the account `client|X`, `ETH|<hex>` is `eth|<hex>`. The scheme is
|
|
1251
|
+
* case-insensitive, an alias id is not (launchpad-sdk's `userRef` follows the same rule).
|
|
1252
|
+
*/
|
|
1253
|
+
function lowerScheme(value) {
|
|
1254
|
+
const pipe = value.indexOf("|");
|
|
1255
|
+
return pipe < 0 ? value : `${value.slice(0, pipe).toLowerCase()}${value.slice(pipe)}`;
|
|
1256
|
+
}
|
|
1257
|
+
/**
|
|
1226
1258
|
* Refuses `eth|0x...` (any digits, any casing of the `0x`) with `INVALID_ETH_USER_REF_PREFIX`,
|
|
1227
1259
|
* naming the correct spelling. `eth|0x...` is not an address form: GalaChain's `eth|` reference is
|
|
1228
1260
|
* followed by the 40 hex digits only. A bare `0x<40 hex>` is a different, normal thing (an
|
|
@@ -1234,7 +1266,7 @@ const ETH_WITH_0X = /^eth\|0[xX](.*)$/su;
|
|
|
1234
1266
|
function assertNoEthZeroXPrefix(value, field) {
|
|
1235
1267
|
var _ETH_WITH_0X$exec;
|
|
1236
1268
|
if (typeof value !== "string") return;
|
|
1237
|
-
const rest = (_ETH_WITH_0X$exec = ETH_WITH_0X.exec(value)) === null || _ETH_WITH_0X$exec === void 0 ? void 0 : _ETH_WITH_0X$exec[1];
|
|
1269
|
+
const rest = (_ETH_WITH_0X$exec = ETH_WITH_0X.exec(lowerScheme(value))) === null || _ETH_WITH_0X$exec === void 0 ? void 0 : _ETH_WITH_0X$exec[1];
|
|
1238
1270
|
if (rest === void 0) return;
|
|
1239
1271
|
const checksummed = /^[0-9a-fA-F]{40}$/u.test(rest) ? checksumEthereumAddress(rest) : void 0;
|
|
1240
1272
|
throw new GalaSDKError("INVALID_ETH_USER_REF_PREFIX", {
|
|
@@ -1256,7 +1288,9 @@ function assertNoEthZeroXPrefix(value, field) {
|
|
|
1256
1288
|
* - `eth|0x<hex>` is NOT an address form: an `eth|` reference is followed by the digits alone.
|
|
1257
1289
|
* It is refused before anything is signed or sent (see {@link assertNoEthZeroXPrefix}). A bare
|
|
1258
1290
|
* `0x<40 hex>` is an ordinary Ethereum address and is converted to `eth|<EIP-55 digits>`.
|
|
1259
|
-
* - `client|<id>` (`A-Za-z0-9_-`): a GalaChain alias, kept exactly as written.
|
|
1291
|
+
* - `client|<id>` (`A-Za-z0-9_-`): a GalaChain alias, kept exactly as written after the scheme.
|
|
1292
|
+
* - The scheme (before the first `|`) is accepted in any case and sent lower case (`Client|X` -> `client|X`,
|
|
1293
|
+
* `ETH|<hex>` -> `eth|<hex>`); everything after the `|` keeps its case.
|
|
1260
1294
|
*
|
|
1261
1295
|
* Anything else is refused before anything is signed or sent (fail closed): an unknown spelling
|
|
1262
1296
|
* could name an account nobody holds.
|
|
@@ -1268,8 +1302,9 @@ function galaChainUserRef(value, field) {
|
|
|
1268
1302
|
assertNoEthZeroXPrefix(value, field);
|
|
1269
1303
|
if (typeof value === "string") {
|
|
1270
1304
|
var _ACCOUNT$exec;
|
|
1271
|
-
|
|
1272
|
-
|
|
1305
|
+
const spelled = lowerScheme(value);
|
|
1306
|
+
if (CLIENT_ALIAS.test(spelled)) return spelled;
|
|
1307
|
+
const digits = (_ACCOUNT$exec = ACCOUNT.exec(spelled)) === null || _ACCOUNT$exec === void 0 ? void 0 : _ACCOUNT$exec[1];
|
|
1273
1308
|
const account = digits === void 0 ? void 0 : checksumEthereumAddress(digits);
|
|
1274
1309
|
if (account !== void 0) return `eth|${account.slice(2)}`;
|
|
1275
1310
|
}
|
|
@@ -2572,8 +2607,8 @@ async function signTypedDataPayload(privateKey, payload) {
|
|
|
2572
2607
|
* `dtoOperationMap` (the `dtoOperation` / API path table of the GalaChain platform team,
|
|
2573
2608
|
* 2026-10-27). The chain refuses a signed DTO whose `dtoOperation` is not exactly the operation it
|
|
2574
2609
|
* is called through ("The dto was signed to call X operation, but the current operation is Y"), so
|
|
2575
|
-
* the URL a write is POSTed to and the `dtoOperation` it carries both come from this one table
|
|
2576
|
-
*
|
|
2610
|
+
* the URL a write is POSTed to and the `dtoOperation` it carries both come from this one table
|
|
2611
|
+
* (the platform's rows, plus the chain's own deviations in `CHAIN_METHOD_OPERATIONS`).
|
|
2577
2612
|
*
|
|
2578
2613
|
* `dtoOperation` is a SIGNED field: it is part of the DTO before the signer sees it, never added by
|
|
2579
2614
|
* a signer or after the signature.
|
|
@@ -2643,7 +2678,30 @@ const CHAIN_CONTRACT_OPERATION_PREFIXES = {
|
|
|
2643
2678
|
"vox/resources-contract": "vox_vox_VOXResourceToken"
|
|
2644
2679
|
};
|
|
2645
2680
|
/**
|
|
2646
|
-
*
|
|
2681
|
+
* Where the chain enforces an operation other than the platform table's, keyed `<contract path>:<method>`. The ONE
|
|
2682
|
+
* place such a deviation lives: every consumer (core's bridge-out signing, the wrap flow, Connect, the product SDKs)
|
|
2683
|
+
* asks `dtoOperationOf`, so nobody hard-codes the exception.
|
|
2684
|
+
*
|
|
2685
|
+
* - `RequestTokenBridgeOut`: the table maps `asset/bridge-contract` to bridge-chaincode, but a RequestTokenBridgeOut
|
|
2686
|
+
* is a TOKEN contract call. Verified on stage (2026-11-02): signed under
|
|
2687
|
+
* `asset-channel_bridge-chaincode_BridgeContract:RequestTokenBridgeOut` the chain answers "signed to call ...
|
|
2688
|
+
* BridgeContract:RequestTokenBridgeOut, but the current operation is
|
|
2689
|
+
* asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut", and it accepts the token contract's.
|
|
2690
|
+
* - `GrantAllowance`: the grants embedded in a `BridgeTokenOut` are signed as
|
|
2691
|
+
* `asset-channel_bridge-chaincode_GalaChainToken:GrantAllowance`, which the table has no row for. Observed in
|
|
2692
|
+
* GalaConnect-signed stage traffic; this SDK does not sign it and it was not re-verified against the chain.
|
|
2693
|
+
*
|
|
2694
|
+
* `asset/bridge-contract:BridgeTokenOut` is NOT here: the table's `BridgeContract:BridgeTokenOut` is what was seen
|
|
2695
|
+
* live on stage for the external-chain bridge (GalaConnect-signed). The token contracts' own `BridgeTokenOut`
|
|
2696
|
+
* (`asset/token-contract`, `music/token-contract`, the channel move) is their plain prefix.
|
|
2697
|
+
*/
|
|
2698
|
+
const CHAIN_METHOD_OPERATIONS = {
|
|
2699
|
+
"asset/bridge-contract:RequestTokenBridgeOut": "asset-channel_basic-asset_GalaChainToken:RequestTokenBridgeOut",
|
|
2700
|
+
"asset/bridge-contract:GrantAllowance": "asset-channel_bridge-chaincode_GalaChainToken:GrantAllowance"
|
|
2701
|
+
};
|
|
2702
|
+
/**
|
|
2703
|
+
* The `dtoOperation` of `method` on the contract served at `contractPath`: the chain's own
|
|
2704
|
+
* (`CHAIN_METHOD_OPERATIONS`) where it deviates from the platform table, else the table's prefix plus `:<method>`.
|
|
2647
2705
|
*
|
|
2648
2706
|
* `ChainContractPath` is only a type: a plain-JS caller, or a path built at runtime
|
|
2649
2707
|
* (`${channel}/${contract}`), can name a contract the table does not have. That is refused here, before
|
|
@@ -2653,6 +2711,8 @@ const CHAIN_CONTRACT_OPERATION_PREFIXES = {
|
|
|
2653
2711
|
* @throws GalaSDKError SIGNING_FAILED when `contractPath` is not in the table.
|
|
2654
2712
|
*/
|
|
2655
2713
|
function dtoOperationOf(contractPath, method) {
|
|
2714
|
+
const methodKey = `${contractPath}:${method}`;
|
|
2715
|
+
if (Object.prototype.hasOwnProperty.call(CHAIN_METHOD_OPERATIONS, methodKey)) return CHAIN_METHOD_OPERATIONS[methodKey];
|
|
2656
2716
|
const prefix = Object.prototype.hasOwnProperty.call(CHAIN_CONTRACT_OPERATION_PREFIXES, contractPath) ? CHAIN_CONTRACT_OPERATION_PREFIXES[contractPath] : void 0;
|
|
2657
2717
|
if (prefix === void 0) throw new GalaSDKError("SIGNING_FAILED", {
|
|
2658
2718
|
method,
|
|
@@ -2729,12 +2789,12 @@ const TEXT_KEYS = [
|
|
|
2729
2789
|
];
|
|
2730
2790
|
/** Wallet errors nest their text at most a level or two deep; the bound also stops a cyclic object. */
|
|
2731
2791
|
const MAX_TEXT_DEPTH = 3;
|
|
2732
|
-
function isRecord$
|
|
2792
|
+
function isRecord$6(value) {
|
|
2733
2793
|
return typeof value === "object" && value !== null;
|
|
2734
2794
|
}
|
|
2735
2795
|
function textsOf(value, depth = 0) {
|
|
2736
2796
|
if (typeof value === "string") return [value];
|
|
2737
|
-
if (!isRecord$
|
|
2797
|
+
if (!isRecord$6(value) || depth >= MAX_TEXT_DEPTH) return [];
|
|
2738
2798
|
return TEXT_KEYS.flatMap((key) => textsOf(value[key], depth + 1));
|
|
2739
2799
|
}
|
|
2740
2800
|
function wordsADecline(text) {
|
|
@@ -2777,7 +2837,7 @@ function isWalletUserRejection(value) {
|
|
|
2777
2837
|
if (value.code === "SIGNING_FAILED") return value.params["reason"] === "user_rejected";
|
|
2778
2838
|
return !hasGalaErrorBrand(value) && REJECTION_CODES.includes(value.code);
|
|
2779
2839
|
}
|
|
2780
|
-
if (isRecord$
|
|
2840
|
+
if (isRecord$6(value)) {
|
|
2781
2841
|
if (REJECTION_CODES.includes(value["code"]) || value["name"] === REJECTION_NAME) return true;
|
|
2782
2842
|
}
|
|
2783
2843
|
return textsOf(value).some(wordsADecline);
|
|
@@ -2869,7 +2929,7 @@ async function signPreSendFor(signer, contractPath, method, dto) {
|
|
|
2869
2929
|
* fallback. It is the version in the default `User-Agent` (`GalaChain-SDK/<version>`) of every SDK
|
|
2870
2930
|
* request, whichever product SDK sends it.
|
|
2871
2931
|
*/
|
|
2872
|
-
const GALA_CORE_SDK_VERSION = "1.
|
|
2932
|
+
const GALA_CORE_SDK_VERSION = "1.2.0-beta.2";
|
|
2873
2933
|
|
|
2874
2934
|
//#endregion
|
|
2875
2935
|
//#region src/utils/transport.ts
|
|
@@ -2930,7 +2990,7 @@ function buildRequestHeaders(wire, parts = {}) {
|
|
|
2930
2990
|
entries.set(name.toLowerCase(), [name, value]);
|
|
2931
2991
|
}
|
|
2932
2992
|
};
|
|
2933
|
-
if ((wire === null || wire === void 0 ? void 0 : wire.userAgent) !== false) put({ "User-Agent": (wire === null || wire === void 0 ? void 0 : wire.userAgent) ?? `GalaChain-SDK/${"1.
|
|
2993
|
+
if ((wire === null || wire === void 0 ? void 0 : wire.userAgent) !== false) put({ "User-Agent": (wire === null || wire === void 0 ? void 0 : wire.userAgent) ?? `GalaChain-SDK/${"1.2.0-beta.2"}` });
|
|
2934
2994
|
put(parts.defaults);
|
|
2935
2995
|
put(wire === null || wire === void 0 ? void 0 : wire.headers);
|
|
2936
2996
|
if (parts.json === true && !entries.has("content-type")) put({ "Content-Type": "application/json" });
|
|
@@ -3033,7 +3093,7 @@ function hasHeaderGetter(headers) {
|
|
|
3033
3093
|
|
|
3034
3094
|
//#endregion
|
|
3035
3095
|
//#region src/utils/axios_requestor.ts
|
|
3036
|
-
function isRecord$
|
|
3096
|
+
function isRecord$5(value) {
|
|
3037
3097
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3038
3098
|
}
|
|
3039
3099
|
/**
|
|
@@ -3041,10 +3101,10 @@ function isRecord$3(value) {
|
|
|
3041
3101
|
* for ECONNREFUSED). That is a transport failure, not an HTTP answer.
|
|
3042
3102
|
*/
|
|
3043
3103
|
function isAxiosLikeResponse(value) {
|
|
3044
|
-
return isRecord$
|
|
3104
|
+
return isRecord$5(value) && typeof value["status"] === "number";
|
|
3045
3105
|
}
|
|
3046
3106
|
function readAxiosHeader(headers, name) {
|
|
3047
|
-
if (!isRecord$
|
|
3107
|
+
if (!isRecord$5(headers)) return null;
|
|
3048
3108
|
const getter = headers["get"];
|
|
3049
3109
|
if (typeof getter === "function") {
|
|
3050
3110
|
const value = getter.call(headers, name);
|
|
@@ -3125,16 +3185,16 @@ function httpRequestorFromAxios(instance, options) {
|
|
|
3125
3185
|
*/
|
|
3126
3186
|
function isTransportRejection(error, rejectOnHttpError) {
|
|
3127
3187
|
if (!rejectOnHttpError) return true;
|
|
3128
|
-
return isRecord$
|
|
3188
|
+
return isRecord$5(error) && error["isAxiosError"] === true && error["response"] === void 0;
|
|
3129
3189
|
}
|
|
3130
3190
|
|
|
3131
3191
|
//#endregion
|
|
3132
3192
|
//#region src/utils/ethers_provider.ts
|
|
3133
|
-
function isRecord$
|
|
3193
|
+
function isRecord$4(value) {
|
|
3134
3194
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3135
3195
|
}
|
|
3136
3196
|
function isTypedDataTypes(value) {
|
|
3137
|
-
return isRecord$
|
|
3197
|
+
return isRecord$4(value) && Object.values(value).every((fields) => Array.isArray(fields) && fields.every((field) => isRecord$4(field) && typeof field["name"] === "string" && typeof field["type"] === "string"));
|
|
3138
3198
|
}
|
|
3139
3199
|
function malformed(method) {
|
|
3140
3200
|
return new GalaSDKError("MALFORMED_WALLET_REQUEST", { method });
|
|
@@ -3148,9 +3208,9 @@ function readTypedDataRequest(params) {
|
|
|
3148
3208
|
} catch {
|
|
3149
3209
|
throw malformed("eth_signTypedData_v4");
|
|
3150
3210
|
}
|
|
3151
|
-
if (!isRecord$
|
|
3211
|
+
if (!isRecord$4(payload)) throw malformed("eth_signTypedData_v4");
|
|
3152
3212
|
const { domain, types, message } = payload;
|
|
3153
|
-
if (!isRecord$
|
|
3213
|
+
if (!isRecord$4(domain) || !isTypedDataTypes(types) || !isRecord$4(message)) throw malformed("eth_signTypedData_v4");
|
|
3154
3214
|
return {
|
|
3155
3215
|
domain,
|
|
3156
3216
|
types: stripEip712DomainType(types),
|
|
@@ -3279,7 +3339,7 @@ const FAILURE_OUTCOMES = [
|
|
|
3279
3339
|
|
|
3280
3340
|
//#endregion
|
|
3281
3341
|
//#region src/utils/failure_view.ts
|
|
3282
|
-
function isRecord$
|
|
3342
|
+
function isRecord$3(value) {
|
|
3283
3343
|
return typeof value === "object" && value !== null;
|
|
3284
3344
|
}
|
|
3285
3345
|
/**
|
|
@@ -3297,12 +3357,12 @@ function isRecord$1(value) {
|
|
|
3297
3357
|
* ```
|
|
3298
3358
|
*/
|
|
3299
3359
|
function toFailureView(value) {
|
|
3300
|
-
if (!isRecord$
|
|
3360
|
+
if (!isRecord$3(value)) return void 0;
|
|
3301
3361
|
const { code, params, status, phase, uniqueKey, write, outcome, retryable, shadow, notFound } = value;
|
|
3302
3362
|
if (typeof code !== "string" || code === "") return void 0;
|
|
3303
3363
|
return {
|
|
3304
3364
|
code,
|
|
3305
|
-
params: isRecord$
|
|
3365
|
+
params: isRecord$3(params) && !Array.isArray(params) ? params : void 0,
|
|
3306
3366
|
status: typeof status === "number" && Number.isFinite(status) ? status : void 0,
|
|
3307
3367
|
phase: GALA_ERROR_PHASES.find((known) => known === phase),
|
|
3308
3368
|
uniqueKey: typeof uniqueKey === "string" && uniqueKey !== "" ? uniqueKey : void 0,
|
|
@@ -3763,10 +3823,315 @@ function unlockTokenDto(owner, tokens, uniqueKey, name) {
|
|
|
3763
3823
|
};
|
|
3764
3824
|
}
|
|
3765
3825
|
|
|
3826
|
+
//#endregion
|
|
3827
|
+
//#region src/writes/nft.ts
|
|
3828
|
+
/**
|
|
3829
|
+
* The NFT methods of GalaChain's token contract that `GatewayWrites` signs and submits, as a closed
|
|
3830
|
+
* set: claim a collection name (`GrantNftCollectionAuthorization`), create the NFT collection's
|
|
3831
|
+
* token class (`CreateNftCollection`), mint NFTs, granting the minter its own mint allowance in
|
|
3832
|
+
* the same transaction (`MintTokenWithAllowance`) or against an allowance it already holds
|
|
3833
|
+
* (`MintToken`).
|
|
3834
|
+
*/
|
|
3835
|
+
const NFT_WRITE_METHODS = [
|
|
3836
|
+
"GrantNftCollectionAuthorization",
|
|
3837
|
+
"CreateNftCollection",
|
|
3838
|
+
"MintTokenWithAllowance",
|
|
3839
|
+
"MintToken"
|
|
3840
|
+
];
|
|
3841
|
+
/** The most NFTs one mint may create (the chain's `MintTokenDto.MAX_NFT_MINT_SIZE`). */
|
|
3842
|
+
const NFT_MINT_LIMIT = 1e3;
|
|
3843
|
+
/** The `additionalKey` an NFT token class carries when its creator names none (GalaChain's `none`). */
|
|
3844
|
+
const NFT_DEFAULT_ADDITIONAL_KEY = "none";
|
|
3845
|
+
function refuse(field, reason) {
|
|
3846
|
+
return new GalaSDKError("INVALID_NFT_INPUT", {
|
|
3847
|
+
field,
|
|
3848
|
+
reason
|
|
3849
|
+
});
|
|
3850
|
+
}
|
|
3851
|
+
/** True when `value` holds an ASCII or C1 control character (the NUL of chain composite keys among them). */
|
|
3852
|
+
function hasControlCharacter(value) {
|
|
3853
|
+
for (let index = 0; index < value.length; index += 1) {
|
|
3854
|
+
const code = value.charCodeAt(index);
|
|
3855
|
+
if (code <= 31 || code >= 127 && code <= 159) return true;
|
|
3856
|
+
}
|
|
3857
|
+
return false;
|
|
3858
|
+
}
|
|
3859
|
+
/**
|
|
3860
|
+
* One part of a token class key (collection, category, type, additionalKey): a non-empty string
|
|
3861
|
+
* with no control character (the chain's composite keys are NUL-separated), no `|` (the key's own
|
|
3862
|
+
* separator) and no surrounding whitespace. Returned exactly as written, never trimmed.
|
|
3863
|
+
*
|
|
3864
|
+
* @throws GalaSDKError `INVALID_NFT_INPUT`.
|
|
3865
|
+
*/
|
|
3866
|
+
function nftClassPart(value, field) {
|
|
3867
|
+
if (typeof value !== "string") throw refuse(field, "not_a_string");
|
|
3868
|
+
if (value.trim() === "") throw refuse(field, "empty");
|
|
3869
|
+
if (value.trim() !== value || value.includes("|") || hasControlCharacter(value)) throw refuse(field, "bad_characters");
|
|
3870
|
+
return value;
|
|
3871
|
+
}
|
|
3872
|
+
/** A non-empty free-text field (name, description, image, ...), exactly as written. */
|
|
3873
|
+
function nftText(value, field) {
|
|
3874
|
+
if (typeof value !== "string") throw refuse(field, "not_a_string");
|
|
3875
|
+
if (value.trim() === "") throw refuse(field, "empty");
|
|
3876
|
+
return value;
|
|
3877
|
+
}
|
|
3878
|
+
/** A string that may be empty (the symbol). */
|
|
3879
|
+
function nftString(value, field) {
|
|
3880
|
+
if (typeof value !== "string") throw refuse(field, "not_a_string");
|
|
3881
|
+
return value;
|
|
3882
|
+
}
|
|
3883
|
+
const WHOLE_NUMBER = /^[1-9][0-9]{0,37}$/u;
|
|
3884
|
+
/**
|
|
3885
|
+
* A positive whole number written as a decimal string (no sign, fraction, exponent, separators or
|
|
3886
|
+
* leading zero), returned as written. A JS number is refused: the chain receives strings.
|
|
3887
|
+
*/
|
|
3888
|
+
function nftWholeNumber(value, field) {
|
|
3889
|
+
if (typeof value !== "string" || !WHOLE_NUMBER.test(value)) throw refuse(field, "not_a_positive_whole_number");
|
|
3890
|
+
return value;
|
|
3891
|
+
}
|
|
3892
|
+
/** The quantity of a mint: a positive whole number of at most {@link NFT_MINT_LIMIT}. */
|
|
3893
|
+
function nftMintQuantity(value, field) {
|
|
3894
|
+
const quantity = nftWholeNumber(value, field);
|
|
3895
|
+
if (new bignumber_js.default(quantity).isGreaterThan(1e3)) throw refuse(field, "above_mint_limit");
|
|
3896
|
+
return quantity;
|
|
3897
|
+
}
|
|
3898
|
+
/** The token class a write names, every part checked; `additionalKey` defaults to `none`. */
|
|
3899
|
+
function nftTokenClass(input) {
|
|
3900
|
+
return {
|
|
3901
|
+
collection: nftClassPart(input.collection, "collection"),
|
|
3902
|
+
category: nftClassPart(input.category, "category"),
|
|
3903
|
+
type: nftClassPart(input.type, "type"),
|
|
3904
|
+
additionalKey: nftClassPart(input.additionalKey ?? "none", "additionalKey")
|
|
3905
|
+
};
|
|
3906
|
+
}
|
|
3907
|
+
/** The authorities of a create: one or more user references, each in its one gateway spelling. */
|
|
3908
|
+
function nftAuthorities(value) {
|
|
3909
|
+
if (!Array.isArray(value) || value.length === 0) throw refuse("authorities", "bad_authorities");
|
|
3910
|
+
return value.map((authority, index) => galaChainUserRef(authority, `authorities[${index}]`));
|
|
3911
|
+
}
|
|
3912
|
+
const PUBLIC_KEY = /^(?:0x)?(?:(?:02|03)[0-9a-fA-F]{64}|04[0-9a-fA-F]{128})$/u;
|
|
3913
|
+
/**
|
|
3914
|
+
* The public key a DryRun simulates the caller as: a secp256k1 key in hex, compressed (33 bytes) or
|
|
3915
|
+
* uncompressed (65 bytes), with or without `0x`. The chain refuses a DryRun that names no caller.
|
|
3916
|
+
*/
|
|
3917
|
+
function nftCallerPublicKey(value) {
|
|
3918
|
+
if (typeof value !== "string" || !PUBLIC_KEY.test(value)) throw refuse("callerPublicKey", "bad_public_key");
|
|
3919
|
+
return value;
|
|
3920
|
+
}
|
|
3921
|
+
/** The unsigned `GrantNftCollectionAuthorization` DTO. */
|
|
3922
|
+
function claimNftCollectionDto(collection, authorizedUser, uniqueKey) {
|
|
3923
|
+
return {
|
|
3924
|
+
collection,
|
|
3925
|
+
authorizedUser,
|
|
3926
|
+
uniqueKey
|
|
3927
|
+
};
|
|
3928
|
+
}
|
|
3929
|
+
/** The unsigned `CreateNftCollection` DTO: the fields the caller gave, none the caller left out. */
|
|
3930
|
+
function createNftCollectionDto(tokenClass, fields, uniqueKey) {
|
|
3931
|
+
return {
|
|
3932
|
+
...tokenClass,
|
|
3933
|
+
name: fields.name,
|
|
3934
|
+
symbol: fields.symbol,
|
|
3935
|
+
description: fields.description,
|
|
3936
|
+
image: fields.image,
|
|
3937
|
+
maxSupply: fields.maxSupply,
|
|
3938
|
+
...fields.maxCapacity === void 0 ? {} : { maxCapacity: fields.maxCapacity },
|
|
3939
|
+
...fields.metadataAddress === void 0 ? {} : { metadataAddress: fields.metadataAddress },
|
|
3940
|
+
...fields.contractAddress === void 0 ? {} : { contractAddress: fields.contractAddress },
|
|
3941
|
+
...fields.rarity === void 0 ? {} : { rarity: fields.rarity },
|
|
3942
|
+
...fields.authorities === void 0 ? {} : { authorities: [...fields.authorities] },
|
|
3943
|
+
uniqueKey
|
|
3944
|
+
};
|
|
3945
|
+
}
|
|
3946
|
+
/**
|
|
3947
|
+
* The unsigned mint DTO. `MintTokenWithAllowance` names instance `"0"` (the allowance it grants
|
|
3948
|
+
* itself covers the class's mint, not one NFT); `MintToken` carries no instance.
|
|
3949
|
+
*/
|
|
3950
|
+
function mintNftDto(method, tokenClass, owner, quantity, uniqueKey) {
|
|
3951
|
+
return {
|
|
3952
|
+
tokenClass,
|
|
3953
|
+
owner,
|
|
3954
|
+
...method === "MintTokenWithAllowance" ? { tokenInstance: "0" } : {},
|
|
3955
|
+
quantity,
|
|
3956
|
+
uniqueKey
|
|
3957
|
+
};
|
|
3958
|
+
}
|
|
3959
|
+
function isRecord$2(value) {
|
|
3960
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
3961
|
+
}
|
|
3962
|
+
/** The error for a write GalaChain accepted whose answer does not say what the write did. */
|
|
3963
|
+
function unreadable(method, uniqueKey, body) {
|
|
3964
|
+
return new GalaSDKError("GATEWAY_RESPONSE_INVALID", { method }, {
|
|
3965
|
+
body,
|
|
3966
|
+
uniqueKey
|
|
3967
|
+
});
|
|
3968
|
+
}
|
|
3969
|
+
function sameClass(value, tokenClass) {
|
|
3970
|
+
return value["collection"] === tokenClass.collection && value["category"] === tokenClass.category && value["type"] === tokenClass.type && value["additionalKey"] === tokenClass.additionalKey;
|
|
3971
|
+
}
|
|
3972
|
+
/**
|
|
3973
|
+
* The collection and authorized users a claim answered. Fails closed: an answer for another
|
|
3974
|
+
* collection, or one that authorizes nobody, is not the claim that was sent.
|
|
3975
|
+
*/
|
|
3976
|
+
function claimedCollection(receipt, collection) {
|
|
3977
|
+
const data = receipt.data;
|
|
3978
|
+
const users = isRecord$2(data) ? data["authorizedUsers"] : void 0;
|
|
3979
|
+
if (!isRecord$2(data) || data["collection"] !== collection || !Array.isArray(users) || users.length === 0 || !users.every((user) => typeof user === "string")) throw unreadable(receipt.method, receipt.uniqueKey, receipt.body);
|
|
3980
|
+
return {
|
|
3981
|
+
...receipt,
|
|
3982
|
+
collection,
|
|
3983
|
+
authorizedUsers: users
|
|
3984
|
+
};
|
|
3985
|
+
}
|
|
3986
|
+
/** The token class a create answered; an answer naming another class is not the create that was sent. */
|
|
3987
|
+
function createdTokenClass(receipt, tokenClass) {
|
|
3988
|
+
const data = receipt.data;
|
|
3989
|
+
if (!isRecord$2(data) || !sameClass(data, tokenClass)) throw unreadable(receipt.method, receipt.uniqueKey, receipt.body);
|
|
3990
|
+
return {
|
|
3991
|
+
...receipt,
|
|
3992
|
+
tokenClass: { ...tokenClass }
|
|
3993
|
+
};
|
|
3994
|
+
}
|
|
3995
|
+
const INSTANCE_ID = /^[0-9]+$/u;
|
|
3996
|
+
/**
|
|
3997
|
+
* The NFT instances a mint answered, never synthesized: as many as were asked for, each of the
|
|
3998
|
+
* class that was named, each with a whole-number instance, none twice.
|
|
3999
|
+
*/
|
|
4000
|
+
function mintedInstances(receipt, tokenClass, quantity) {
|
|
4001
|
+
const data = receipt.data;
|
|
4002
|
+
const instances = [];
|
|
4003
|
+
if (Array.isArray(data)) for (const item of data) {
|
|
4004
|
+
const instance = isRecord$2(item) ? item["instance"] : void 0;
|
|
4005
|
+
if (!isRecord$2(item) || !sameClass(item, tokenClass) || typeof instance !== "string") break;
|
|
4006
|
+
if (!INSTANCE_ID.test(instance)) break;
|
|
4007
|
+
instances.push({
|
|
4008
|
+
...tokenClass,
|
|
4009
|
+
instance
|
|
4010
|
+
});
|
|
4011
|
+
}
|
|
4012
|
+
if (!Array.isArray(data) || instances.length !== data.length || instances.length !== Number(quantity) || new Set(instances.map((key) => key.instance)).size !== instances.length) throw unreadable(receipt.method, receipt.uniqueKey, receipt.body);
|
|
4013
|
+
return {
|
|
4014
|
+
...receipt,
|
|
4015
|
+
tokenInstances: instances
|
|
4016
|
+
};
|
|
4017
|
+
}
|
|
4018
|
+
|
|
4019
|
+
//#endregion
|
|
4020
|
+
//#region src/reads/request.ts
|
|
4021
|
+
/** The chaincode contract each read method belongs to (part of its URL). */
|
|
4022
|
+
const CONTRACT_OF = {
|
|
4023
|
+
FetchBalances: "token-contract",
|
|
4024
|
+
FetchTokenClasses: "token-contract",
|
|
4025
|
+
FetchTokenClassesWithSupply: "token-contract",
|
|
4026
|
+
FetchTokenClassesWithPagination: "token-contract",
|
|
4027
|
+
FetchNftCollectionAuthorizationsWithPagination: "token-contract",
|
|
4028
|
+
GetPublicKey: "public-key-contract"
|
|
4029
|
+
};
|
|
4030
|
+
/**
|
|
4031
|
+
* Methods whose successful answer carries no `Status`: the connect-api GalaChain proxies answer
|
|
4032
|
+
* `GetPublicKey` with `{ Data: { publicKey } }` only (recorded 2026-10-14, prod and stage,
|
|
4033
|
+
* `tests/fixtures/public-key-recorded.json`). A `Status` they do send is still checked.
|
|
4034
|
+
*/
|
|
4035
|
+
const ANSWERED_WITHOUT_STATUS = /* @__PURE__ */ new Set(["GetPublicKey"]);
|
|
4036
|
+
/**
|
|
4037
|
+
* The channel of a collection: `$MUSIC` (and `MUSIC`, any case) lives on the gateway's `music`
|
|
4038
|
+
* channel, every other collection (`$GMUSIC` included) on `asset`.
|
|
4039
|
+
*/
|
|
4040
|
+
function channelOf(collection) {
|
|
4041
|
+
return collection !== void 0 && /^\$?music$/iu.test(collection) ? "music" : "asset";
|
|
4042
|
+
}
|
|
4043
|
+
function isRecord$1(value) {
|
|
4044
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4045
|
+
}
|
|
4046
|
+
function stringField$2(record, key) {
|
|
4047
|
+
const value = record === null || record === void 0 ? void 0 : record[key];
|
|
4048
|
+
return typeof value === "string" ? value : "";
|
|
4049
|
+
}
|
|
4050
|
+
/**
|
|
4051
|
+
* The chain's error object of a refused answer: GalaChain's gateway nests it as
|
|
4052
|
+
* `{ error: { Status: 0, ErrorKey, Message, ErrorPayload }, message }`; an older answer carries
|
|
4053
|
+
* `Status` / `ErrorKey` / `Message` at the top.
|
|
4054
|
+
*/
|
|
4055
|
+
function chainErrorOf(body) {
|
|
4056
|
+
if (!isRecord$1(body)) return void 0;
|
|
4057
|
+
const nested = body["error"];
|
|
4058
|
+
return isRecord$1(nested) ? nested : body;
|
|
4059
|
+
}
|
|
4060
|
+
/**
|
|
4061
|
+
* POSTs one read and returns the chain's `Data`. Reads change nothing, so every failure is a READ's
|
|
4062
|
+
* (`error.write === false`) and a retry is always safe:
|
|
4063
|
+
*
|
|
4064
|
+
* - no answer: `REQUEST_TIMEOUT` / `TRANSPORT_ERROR`, both `write: false` (an app requestor's
|
|
4065
|
+
* own rejection passes through unchanged: it is the app's error); a body that broke off is
|
|
4066
|
+
* `TRANSPORT_ERROR`;
|
|
4067
|
+
* - a numeric top-level `Status` other than 1, in any HTTP status: `GATEWAY_READ_REJECTED`;
|
|
4068
|
+
* - any other non-2xx: `GATEWAY_HTTP_ERROR` (`params.status`; the chain's refusal is `error.body`);
|
|
4069
|
+
* - a 2xx that is not `{ Status: 1, Data }` (for `GetPublicKey`, whose answer carries no
|
|
4070
|
+
* `Status`, not `{ Data }`): `GATEWAY_READ_RESPONSE_INVALID`.
|
|
4071
|
+
*/
|
|
4072
|
+
async function readGateway(transport, method, body, channel = "asset") {
|
|
4073
|
+
const url = `${transport.gatewayBaseUrl}/api/${channel}/${CONTRACT_OF[method]}/${method}`;
|
|
4074
|
+
const response = await requestWithTimeout(transport.requestor, url, {
|
|
4075
|
+
method: "POST",
|
|
4076
|
+
headers: buildRequestHeaders(transport.wire, { json: true }),
|
|
4077
|
+
body: JSON.stringify(body)
|
|
4078
|
+
}, transport.timeoutMs, { write: false });
|
|
4079
|
+
let answer;
|
|
4080
|
+
try {
|
|
4081
|
+
answer = await readResponseBody(response);
|
|
4082
|
+
} catch (cause) {
|
|
4083
|
+
throw new GalaSDKError("TRANSPORT_ERROR", { url }, {
|
|
4084
|
+
url,
|
|
4085
|
+
cause,
|
|
4086
|
+
write: false
|
|
4087
|
+
});
|
|
4088
|
+
}
|
|
4089
|
+
return dataOf(method, url, response, answer);
|
|
4090
|
+
}
|
|
4091
|
+
/**
|
|
4092
|
+
* The chain's `Data` of a read-like answer, or the error for one that is not (see
|
|
4093
|
+
* {@link readGateway} for the codes). Also the reading of a signed DryRun answer, which changes
|
|
4094
|
+
* nothing either, so it names its own `method` (a string, not a read method).
|
|
4095
|
+
*/
|
|
4096
|
+
function dataOf(method, url, response, answer) {
|
|
4097
|
+
const context = {
|
|
4098
|
+
status: response.status,
|
|
4099
|
+
body: answer,
|
|
4100
|
+
url,
|
|
4101
|
+
write: false
|
|
4102
|
+
};
|
|
4103
|
+
const envelope = isRecord$1(answer) ? answer : void 0;
|
|
4104
|
+
const chainStatus = envelope === null || envelope === void 0 ? void 0 : envelope["Status"];
|
|
4105
|
+
if (typeof chainStatus === "number" && chainStatus !== 1) throw new GalaSDKError("GATEWAY_READ_REJECTED", {
|
|
4106
|
+
method,
|
|
4107
|
+
chainStatus,
|
|
4108
|
+
errorKey: stringField$2(envelope, "ErrorKey"),
|
|
4109
|
+
serverMessage: stringField$2(envelope, "Message")
|
|
4110
|
+
}, context);
|
|
4111
|
+
if (!response.ok) {
|
|
4112
|
+
const chainError = chainErrorOf(answer);
|
|
4113
|
+
throw new GalaSDKError("GATEWAY_HTTP_ERROR", {
|
|
4114
|
+
method,
|
|
4115
|
+
status: response.status,
|
|
4116
|
+
serverMessage: stringField$2(chainError, "Message") || stringField$2(envelope, "message")
|
|
4117
|
+
}, context);
|
|
4118
|
+
}
|
|
4119
|
+
const statusAccepted = chainStatus === 1 || chainStatus === void 0 && ANSWERED_WITHOUT_STATUS.has(method);
|
|
4120
|
+
if (envelope === void 0 || !statusAccepted || !("Data" in envelope)) throw new GalaSDKError("GATEWAY_READ_RESPONSE_INVALID", { method }, context);
|
|
4121
|
+
return envelope["Data"];
|
|
4122
|
+
}
|
|
4123
|
+
/** The error for a 2xx whose `Data` is not what `method` answers. */
|
|
4124
|
+
function invalidAnswer(method, data) {
|
|
4125
|
+
return new GalaSDKError("GATEWAY_READ_RESPONSE_INVALID", { method }, {
|
|
4126
|
+
body: data,
|
|
4127
|
+
write: false
|
|
4128
|
+
});
|
|
4129
|
+
}
|
|
4130
|
+
|
|
3766
4131
|
//#endregion
|
|
3767
4132
|
//#region src/writes/submit.ts
|
|
3768
4133
|
/** The contract every write of this module is sent to (its URL path and its `dtoOperation`). */
|
|
3769
|
-
const TOKEN_CONTRACT = "asset/token-contract";
|
|
4134
|
+
const TOKEN_CONTRACT$1 = "asset/token-contract";
|
|
3770
4135
|
/**
|
|
3771
4136
|
* The fields a signer may add next to the DTO: the signature and, for the wallet schemes, the
|
|
3772
4137
|
* personal-sign `prefix` and the EIP-712 `types` / `domain`. Nothing else: a signer that inserts a
|
|
@@ -3796,9 +4161,9 @@ function carriesExactlyTheDto(builtDto, signed) {
|
|
|
3796
4161
|
* `SIGNING_FAILED` (pre-send: nothing was transmitted, a retry is safe).
|
|
3797
4162
|
*/
|
|
3798
4163
|
async function signedPayload(signer, method, dto) {
|
|
3799
|
-
const operated = withDtoOperation(TOKEN_CONTRACT, method, dto);
|
|
4164
|
+
const operated = withDtoOperation(TOKEN_CONTRACT$1, method, dto);
|
|
3800
4165
|
const builtDto = serialize(operated);
|
|
3801
|
-
const signed = await signPreSendFor(signer, TOKEN_CONTRACT, method, operated);
|
|
4166
|
+
const signed = await signPreSendFor(signer, TOKEN_CONTRACT$1, method, operated);
|
|
3802
4167
|
let payload;
|
|
3803
4168
|
try {
|
|
3804
4169
|
payload = carriesExactlyTheDto(builtDto, signed) ? JSON.stringify(signed) : void 0;
|
|
@@ -3880,11 +4245,13 @@ function receiptOf(method, uniqueKey, url, response, body) {
|
|
|
3880
4245
|
};
|
|
3881
4246
|
const envelope = typeof body === "object" && body !== null && !Array.isArray(body) ? body : void 0;
|
|
3882
4247
|
const chainStatus = envelope === null || envelope === void 0 ? void 0 : envelope["Status"];
|
|
3883
|
-
|
|
4248
|
+
const refusal = chainErrorOf(body);
|
|
4249
|
+
const refusalStatus = refusal === null || refusal === void 0 ? void 0 : refusal["Status"];
|
|
4250
|
+
if (typeof refusalStatus === "number" && refusalStatus !== 1) throw new GalaSDKError("GATEWAY_WRITE_REJECTED", {
|
|
3884
4251
|
method,
|
|
3885
|
-
chainStatus,
|
|
3886
|
-
errorKey: stringField$1(
|
|
3887
|
-
serverMessage: stringField$1(
|
|
4252
|
+
chainStatus: refusalStatus,
|
|
4253
|
+
errorKey: stringField$1(refusal, "ErrorKey"),
|
|
4254
|
+
serverMessage: stringField$1(refusal, "Message")
|
|
3888
4255
|
}, context);
|
|
3889
4256
|
if (!response.ok) throw new GalaSDKError("GATEWAY_HTTP_ERROR", {
|
|
3890
4257
|
method,
|
|
@@ -3909,11 +4276,123 @@ function receiptOf(method, uniqueKey, url, response, body) {
|
|
|
3909
4276
|
*/
|
|
3910
4277
|
async function submitWrite(transport, method, dto, uniqueKey) {
|
|
3911
4278
|
const payload = await signedPayload(transport.signer, method, dto);
|
|
3912
|
-
const url = `${transport.gatewayBaseUrl}/api/${TOKEN_CONTRACT}/${method}`;
|
|
4279
|
+
const url = `${transport.gatewayBaseUrl}/api/${TOKEN_CONTRACT$1}/${method}`;
|
|
3913
4280
|
const { response, body } = await post(transport, method, url, payload, uniqueKey);
|
|
3914
4281
|
return receiptOf(method, uniqueKey, url, response, body);
|
|
3915
4282
|
}
|
|
3916
4283
|
|
|
4284
|
+
//#endregion
|
|
4285
|
+
//#region src/writes/nft_fee.ts
|
|
4286
|
+
/** The contract every NFT write, and the DryRun that prices it, is sent to. */
|
|
4287
|
+
const TOKEN_CONTRACT = "asset/token-contract";
|
|
4288
|
+
/** The key prefix of the chain's fee receipts: the channel's (`GCFR`) and the paying user's (`GCUR`). */
|
|
4289
|
+
const CHANNEL_RECEIPT = "\0GCFR\0";
|
|
4290
|
+
const USER_RECEIPT = "\0GCUR\0";
|
|
4291
|
+
function isRecord(value) {
|
|
4292
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4293
|
+
}
|
|
4294
|
+
function stringField(record, key) {
|
|
4295
|
+
const value = record[key];
|
|
4296
|
+
return typeof value === "string" ? value : "";
|
|
4297
|
+
}
|
|
4298
|
+
/**
|
|
4299
|
+
* Reads a simulated write's fee from its DryRun `Data`. The simulated write must have SUCCEEDED
|
|
4300
|
+
* (`response.Status` 1): a write the chain would refuse still writes its fee receipt in the
|
|
4301
|
+
* simulation, and quoting that as the price of a write that will not happen would be a lie, so a
|
|
4302
|
+
* refusal (`PAYMENT_REQUIRED`, `INSUFFICIENT_MINT_ALLOWANCE`, ...) is `GATEWAY_READ_REJECTED`.
|
|
4303
|
+
*
|
|
4304
|
+
* The fee is what the paying user's receipts (`GCUR`) add up to; the channel receipt (`GCFR`) the
|
|
4305
|
+
* chain writes beside each is the same payment seen from the channel, so it is counted only when
|
|
4306
|
+
* no user receipt exists. No receipt at all is a fee of `"0"`: the write is free.
|
|
4307
|
+
*
|
|
4308
|
+
* @throws GalaSDKError `GATEWAY_READ_REJECTED` (the simulated write failed), `GATEWAY_READ_RESPONSE_INVALID`
|
|
4309
|
+
* (an answer that is not a DryRun result, or a receipt with no readable quantity).
|
|
4310
|
+
*/
|
|
4311
|
+
function feeQuoteOf(method, data, context) {
|
|
4312
|
+
const invalid = () => new GalaSDKError("GATEWAY_READ_RESPONSE_INVALID", { method: "DryRun" }, {
|
|
4313
|
+
...context,
|
|
4314
|
+
body: data
|
|
4315
|
+
});
|
|
4316
|
+
if (!isRecord(data) || !isRecord(data["response"]) || !isRecord(data["writes"])) throw invalid();
|
|
4317
|
+
const response = data["response"];
|
|
4318
|
+
if (response["Status"] !== 1) throw new GalaSDKError("GATEWAY_READ_REJECTED", {
|
|
4319
|
+
method: "DryRun",
|
|
4320
|
+
chainStatus: typeof response["Status"] === "number" ? response["Status"] : 0,
|
|
4321
|
+
errorKey: stringField(response, "ErrorKey"),
|
|
4322
|
+
serverMessage: stringField(response, "Message")
|
|
4323
|
+
}, {
|
|
4324
|
+
...context,
|
|
4325
|
+
body: response
|
|
4326
|
+
});
|
|
4327
|
+
const user = [];
|
|
4328
|
+
const channel = [];
|
|
4329
|
+
for (const [key, value] of Object.entries(data["writes"])) {
|
|
4330
|
+
const target = key.startsWith(USER_RECEIPT) ? user : key.startsWith(CHANNEL_RECEIPT) ? channel : void 0;
|
|
4331
|
+
if (target === void 0) continue;
|
|
4332
|
+
let receipt;
|
|
4333
|
+
try {
|
|
4334
|
+
receipt = typeof value === "string" ? JSON.parse(value) : void 0;
|
|
4335
|
+
} catch {
|
|
4336
|
+
throw invalid();
|
|
4337
|
+
}
|
|
4338
|
+
const quantity = isRecord(receipt) ? receipt["quantity"] : void 0;
|
|
4339
|
+
const feeCode = isRecord(receipt) ? receipt["feeCode"] : void 0;
|
|
4340
|
+
if (typeof quantity !== "string" || typeof feeCode !== "string") throw invalid();
|
|
4341
|
+
const amount = new bignumber_js.default(quantity);
|
|
4342
|
+
if (!amount.isFinite() || amount.isNegative()) throw invalid();
|
|
4343
|
+
target.push({
|
|
4344
|
+
feeCode,
|
|
4345
|
+
quantity
|
|
4346
|
+
});
|
|
4347
|
+
}
|
|
4348
|
+
const receipts = user.length > 0 ? user : channel;
|
|
4349
|
+
return {
|
|
4350
|
+
method,
|
|
4351
|
+
fee: receipts.reduce((sum, receipt) => sum.plus(receipt.quantity), new bignumber_js.default(0)).toFixed(),
|
|
4352
|
+
feeToken: "GALA",
|
|
4353
|
+
receipts
|
|
4354
|
+
};
|
|
4355
|
+
}
|
|
4356
|
+
/**
|
|
4357
|
+
* Prices `dto` as `method` with the gateway's DryRun: a signed wrapper
|
|
4358
|
+
* `{ callerPublicKey, method, dto, uniqueKey }` (the inner DTO travels unsigned, as an object, with
|
|
4359
|
+
* no `dtoOperation`: a DryRun runs it inside the wrapper, which is what is signed for `DryRun`)
|
|
4360
|
+
* and nothing is written to the chain. A DryRun changes nothing, so every failure of it is a
|
|
4361
|
+
* READ's (`write: false`) and a retry is safe.
|
|
4362
|
+
*
|
|
4363
|
+
* @throws GalaSDKError the signer's pre-send `SIGNING_FAILED`; `REQUEST_TIMEOUT` / `TRANSPORT_ERROR`
|
|
4364
|
+
* (`write: false`); `GATEWAY_HTTP_ERROR`; `GATEWAY_READ_REJECTED`; `GATEWAY_READ_RESPONSE_INVALID`.
|
|
4365
|
+
*/
|
|
4366
|
+
async function quoteNftFee(transport, uniqueKeyPrefix, callerPublicKey, method, dto) {
|
|
4367
|
+
const payload = await signedPayload(transport.signer, "DryRun", {
|
|
4368
|
+
callerPublicKey,
|
|
4369
|
+
method,
|
|
4370
|
+
dto,
|
|
4371
|
+
uniqueKey: createUniqueKey(uniqueKeyPrefix)
|
|
4372
|
+
});
|
|
4373
|
+
const url = `${transport.gatewayBaseUrl}/api/${TOKEN_CONTRACT}/DryRun`;
|
|
4374
|
+
const response = await requestWithTimeout(transport.requestor, url, {
|
|
4375
|
+
method: "POST",
|
|
4376
|
+
headers: buildRequestHeaders(transport.wire, { json: true }),
|
|
4377
|
+
body: payload
|
|
4378
|
+
}, transport.timeoutMs, { write: false });
|
|
4379
|
+
let answer;
|
|
4380
|
+
try {
|
|
4381
|
+
answer = await readResponseBody(response);
|
|
4382
|
+
} catch (cause) {
|
|
4383
|
+
throw new GalaSDKError("TRANSPORT_ERROR", { url }, {
|
|
4384
|
+
url,
|
|
4385
|
+
cause,
|
|
4386
|
+
write: false
|
|
4387
|
+
});
|
|
4388
|
+
}
|
|
4389
|
+
return feeQuoteOf(method, dataOf("DryRun", url, response, answer), {
|
|
4390
|
+
status: response.status,
|
|
4391
|
+
url,
|
|
4392
|
+
write: false
|
|
4393
|
+
});
|
|
4394
|
+
}
|
|
4395
|
+
|
|
3917
4396
|
//#endregion
|
|
3918
4397
|
//#region src/writes/token_ref.ts
|
|
3919
4398
|
/** A plain decimal: digits, optionally a fraction. No sign, exponent, hex, spaces or separators. */
|
|
@@ -4211,6 +4690,131 @@ var GatewayWrites = class {
|
|
|
4211
4690
|
const tokens = await this.resolveAll(checked);
|
|
4212
4691
|
return this.submit("UnlockToken", unlockTokenDto(this.walletAddress, tokens, uniqueKey, name), uniqueKey);
|
|
4213
4692
|
}
|
|
4693
|
+
/**
|
|
4694
|
+
* Claim an NFT collection name: authorize `authorizedUser` (default the writer) to create token
|
|
4695
|
+
* classes under it. The chain charges its claim fee (see {@link estimateNftFee}) and refuses a
|
|
4696
|
+
* name that is taken, whatever its casing.
|
|
4697
|
+
*
|
|
4698
|
+
* @throws GalaSDKError pre-send: `INVALID_NFT_INPUT`, `INVALID_WALLET_ADDRESS`,
|
|
4699
|
+
* `INVALID_UNIQUE_KEY`, `SIGNING_FAILED`; in flight: `GATEWAY_WRITE_OUTCOME_UNKNOWN` (check
|
|
4700
|
+
* `error.uniqueKey`; never resend under a fresh key); post-send: `GATEWAY_WRITE_REJECTED`,
|
|
4701
|
+
* `GATEWAY_HTTP_ERROR`, `GATEWAY_RESPONSE_INVALID` (also an answer for another collection).
|
|
4702
|
+
*/
|
|
4703
|
+
async claimNftCollection(input) {
|
|
4704
|
+
const prepared = this.prepareClaim(input);
|
|
4705
|
+
const receipt = await submitWrite(this.transport, "GrantNftCollectionAuthorization", prepared.dto, prepared.uniqueKey);
|
|
4706
|
+
return claimedCollection(receipt, prepared.collection);
|
|
4707
|
+
}
|
|
4708
|
+
/**
|
|
4709
|
+
* Create the token class of an NFT collection the writer is authorized for (`CreateNftCollection`).
|
|
4710
|
+
*
|
|
4711
|
+
* @throws GalaSDKError as {@link claimNftCollection}.
|
|
4712
|
+
*/
|
|
4713
|
+
async createNftCollection(input) {
|
|
4714
|
+
const prepared = this.prepareCreate(input);
|
|
4715
|
+
const receipt = await submitWrite(this.transport, "CreateNftCollection", prepared.dto, prepared.uniqueKey);
|
|
4716
|
+
return createdTokenClass(receipt, prepared.tokenClass);
|
|
4717
|
+
}
|
|
4718
|
+
/**
|
|
4719
|
+
* Mint 1 to 1000 NFTs of a token class the writer is a token authority of, to `owner` (default
|
|
4720
|
+
* the writer). The receipt lists the instances the chain created, as the chain answered them.
|
|
4721
|
+
*
|
|
4722
|
+
* @throws GalaSDKError as {@link claimNftCollection}.
|
|
4723
|
+
*/
|
|
4724
|
+
async mintNft(input) {
|
|
4725
|
+
const prepared = this.prepareMint(input);
|
|
4726
|
+
const receipt = await submitWrite(this.transport, prepared.method, prepared.dto, prepared.uniqueKey);
|
|
4727
|
+
return mintedInstances(receipt, prepared.tokenClass, prepared.quantity);
|
|
4728
|
+
}
|
|
4729
|
+
/**
|
|
4730
|
+
* What GalaChain's DryRun says an NFT write would cost, for the same input the write takes,
|
|
4731
|
+
* checked the same way, and with nothing written to the chain. The fee is the network's own
|
|
4732
|
+
* figure for this environment (it differs between stage and mainnet), never a constant.
|
|
4733
|
+
*
|
|
4734
|
+
* `callerPublicKey` is the writer's secp256k1 public key (hex): the chain's DryRun needs a caller
|
|
4735
|
+
* and a signer is not asked for its key. A write the chain would refuse (no authorization, no
|
|
4736
|
+
* balance, no mint allowance) is `GATEWAY_READ_REJECTED`, never a fee.
|
|
4737
|
+
*
|
|
4738
|
+
* @throws GalaSDKError the input checks of the write; `INVALID_NFT_INPUT` for a bad key;
|
|
4739
|
+
* `SIGNING_FAILED`; `REQUEST_TIMEOUT` / `TRANSPORT_ERROR` (`write: false`); `GATEWAY_HTTP_ERROR`;
|
|
4740
|
+
* `GATEWAY_READ_REJECTED`; `GATEWAY_READ_RESPONSE_INVALID`.
|
|
4741
|
+
*/
|
|
4742
|
+
async estimateNftFee(request, options) {
|
|
4743
|
+
const callerPublicKey = nftCallerPublicKey(options.callerPublicKey);
|
|
4744
|
+
const prepared = this.prepareFeeRequest(request);
|
|
4745
|
+
return await quoteNftFee(this.transport, this.uniqueKeyPrefix, callerPublicKey, prepared.method, prepared.dto);
|
|
4746
|
+
}
|
|
4747
|
+
prepareFeeRequest(request) {
|
|
4748
|
+
switch (request.write) {
|
|
4749
|
+
case "claimNftCollection": {
|
|
4750
|
+
const { dto } = this.prepareClaim(request);
|
|
4751
|
+
return {
|
|
4752
|
+
method: "GrantNftCollectionAuthorization",
|
|
4753
|
+
dto
|
|
4754
|
+
};
|
|
4755
|
+
}
|
|
4756
|
+
case "createNftCollection": {
|
|
4757
|
+
const { dto } = this.prepareCreate(request);
|
|
4758
|
+
return {
|
|
4759
|
+
method: "CreateNftCollection",
|
|
4760
|
+
dto
|
|
4761
|
+
};
|
|
4762
|
+
}
|
|
4763
|
+
case "mintNft": {
|
|
4764
|
+
const { method, dto } = this.prepareMint(request);
|
|
4765
|
+
return {
|
|
4766
|
+
method,
|
|
4767
|
+
dto
|
|
4768
|
+
};
|
|
4769
|
+
}
|
|
4770
|
+
}
|
|
4771
|
+
}
|
|
4772
|
+
/** Everything a claim needs, every input checked before the key is spent. */
|
|
4773
|
+
prepareClaim(input) {
|
|
4774
|
+
const collection = nftClassPart(input.collection, "collection");
|
|
4775
|
+
const authorizedUser = input.authorizedUser === void 0 ? this.walletAddress : galaChainUserRef(input.authorizedUser, "authorizedUser");
|
|
4776
|
+
const uniqueKey = this.uniqueKeyOf(input.uniqueKey);
|
|
4777
|
+
return {
|
|
4778
|
+
collection,
|
|
4779
|
+
uniqueKey,
|
|
4780
|
+
dto: claimNftCollectionDto(collection, authorizedUser, uniqueKey)
|
|
4781
|
+
};
|
|
4782
|
+
}
|
|
4783
|
+
prepareCreate(input) {
|
|
4784
|
+
const tokenClass = nftTokenClass(input);
|
|
4785
|
+
const fields = {
|
|
4786
|
+
name: nftText(input.name, "name"),
|
|
4787
|
+
symbol: nftString(input.symbol, "symbol"),
|
|
4788
|
+
description: nftText(input.description, "description"),
|
|
4789
|
+
image: nftText(input.image, "image"),
|
|
4790
|
+
maxSupply: nftWholeNumber(input.maxSupply, "maxSupply"),
|
|
4791
|
+
maxCapacity: input.maxCapacity === void 0 ? void 0 : nftWholeNumber(input.maxCapacity, "maxCapacity"),
|
|
4792
|
+
metadataAddress: input.metadataAddress === void 0 ? void 0 : nftText(input.metadataAddress, "metadataAddress"),
|
|
4793
|
+
contractAddress: input.contractAddress === void 0 ? void 0 : nftText(input.contractAddress, "contractAddress"),
|
|
4794
|
+
rarity: input.rarity === void 0 ? void 0 : nftText(input.rarity, "rarity"),
|
|
4795
|
+
authorities: input.authorities === void 0 ? void 0 : nftAuthorities(input.authorities)
|
|
4796
|
+
};
|
|
4797
|
+
const uniqueKey = this.uniqueKeyOf(input.uniqueKey);
|
|
4798
|
+
return {
|
|
4799
|
+
tokenClass,
|
|
4800
|
+
uniqueKey,
|
|
4801
|
+
dto: createNftCollectionDto(tokenClass, fields, uniqueKey)
|
|
4802
|
+
};
|
|
4803
|
+
}
|
|
4804
|
+
prepareMint(input) {
|
|
4805
|
+
const tokenClass = nftTokenClass(input);
|
|
4806
|
+
const quantity = nftMintQuantity(input.quantity, "quantity");
|
|
4807
|
+
const owner = input.owner === void 0 ? this.walletAddress : galaChainUserRef(input.owner, "owner");
|
|
4808
|
+
const method = input.existingAllowance === true ? "MintToken" : "MintTokenWithAllowance";
|
|
4809
|
+
const uniqueKey = this.uniqueKeyOf(input.uniqueKey);
|
|
4810
|
+
return {
|
|
4811
|
+
method,
|
|
4812
|
+
tokenClass,
|
|
4813
|
+
quantity,
|
|
4814
|
+
uniqueKey,
|
|
4815
|
+
dto: mintNftDto(method, tokenClass, owner, quantity, uniqueKey)
|
|
4816
|
+
};
|
|
4817
|
+
}
|
|
4214
4818
|
/** The caller's key, checked, or a fresh one. */
|
|
4215
4819
|
uniqueKeyOf(given) {
|
|
4216
4820
|
if (given === void 0) return createUniqueKey(this.uniqueKeyPrefix);
|
|
@@ -4421,113 +5025,6 @@ function parsePage(value, parse) {
|
|
|
4421
5025
|
};
|
|
4422
5026
|
}
|
|
4423
5027
|
|
|
4424
|
-
//#endregion
|
|
4425
|
-
//#region src/reads/request.ts
|
|
4426
|
-
/** The chaincode contract each read method belongs to (part of its URL). */
|
|
4427
|
-
const CONTRACT_OF = {
|
|
4428
|
-
FetchBalances: "token-contract",
|
|
4429
|
-
FetchTokenClasses: "token-contract",
|
|
4430
|
-
FetchTokenClassesWithSupply: "token-contract",
|
|
4431
|
-
FetchTokenClassesWithPagination: "token-contract",
|
|
4432
|
-
FetchNftCollectionAuthorizationsWithPagination: "token-contract",
|
|
4433
|
-
GetPublicKey: "public-key-contract"
|
|
4434
|
-
};
|
|
4435
|
-
/**
|
|
4436
|
-
* Methods whose successful answer carries no `Status`: the connect-api GalaChain proxies answer
|
|
4437
|
-
* `GetPublicKey` with `{ Data: { publicKey } }` only (recorded 2026-10-14, prod and stage,
|
|
4438
|
-
* `tests/fixtures/public-key-recorded.json`). A `Status` they do send is still checked.
|
|
4439
|
-
*/
|
|
4440
|
-
const ANSWERED_WITHOUT_STATUS = /* @__PURE__ */ new Set(["GetPublicKey"]);
|
|
4441
|
-
/**
|
|
4442
|
-
* The channel of a collection: `$MUSIC` (and `MUSIC`, any case) lives on the gateway's `music`
|
|
4443
|
-
* channel, every other collection (`$GMUSIC` included) on `asset`.
|
|
4444
|
-
*/
|
|
4445
|
-
function channelOf(collection) {
|
|
4446
|
-
return collection !== void 0 && /^\$?music$/iu.test(collection) ? "music" : "asset";
|
|
4447
|
-
}
|
|
4448
|
-
function isRecord(value) {
|
|
4449
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4450
|
-
}
|
|
4451
|
-
function stringField(record, key) {
|
|
4452
|
-
const value = record === null || record === void 0 ? void 0 : record[key];
|
|
4453
|
-
return typeof value === "string" ? value : "";
|
|
4454
|
-
}
|
|
4455
|
-
/**
|
|
4456
|
-
* The chain's error object of a refused answer: GalaChain's gateway nests it as
|
|
4457
|
-
* `{ error: { Status: 0, ErrorKey, Message, ErrorPayload }, message }`; an older answer carries
|
|
4458
|
-
* `Status` / `ErrorKey` / `Message` at the top.
|
|
4459
|
-
*/
|
|
4460
|
-
function chainErrorOf(body) {
|
|
4461
|
-
if (!isRecord(body)) return void 0;
|
|
4462
|
-
const nested = body["error"];
|
|
4463
|
-
return isRecord(nested) ? nested : body;
|
|
4464
|
-
}
|
|
4465
|
-
/**
|
|
4466
|
-
* POSTs one read and returns the chain's `Data`. Reads change nothing, so every failure is a READ's
|
|
4467
|
-
* (`error.write === false`) and a retry is always safe:
|
|
4468
|
-
*
|
|
4469
|
-
* - no answer: `REQUEST_TIMEOUT` / `TRANSPORT_ERROR`, both `write: false` (an app requestor's
|
|
4470
|
-
* own rejection passes through unchanged: it is the app's error); a body that broke off is
|
|
4471
|
-
* `TRANSPORT_ERROR`;
|
|
4472
|
-
* - a numeric top-level `Status` other than 1, in any HTTP status: `GATEWAY_READ_REJECTED`;
|
|
4473
|
-
* - any other non-2xx: `GATEWAY_HTTP_ERROR` (`params.status`; the chain's refusal is `error.body`);
|
|
4474
|
-
* - a 2xx that is not `{ Status: 1, Data }` (for `GetPublicKey`, whose answer carries no
|
|
4475
|
-
* `Status`, not `{ Data }`): `GATEWAY_READ_RESPONSE_INVALID`.
|
|
4476
|
-
*/
|
|
4477
|
-
async function readGateway(transport, method, body, channel = "asset") {
|
|
4478
|
-
const url = `${transport.gatewayBaseUrl}/api/${channel}/${CONTRACT_OF[method]}/${method}`;
|
|
4479
|
-
const response = await requestWithTimeout(transport.requestor, url, {
|
|
4480
|
-
method: "POST",
|
|
4481
|
-
headers: buildRequestHeaders(transport.wire, { json: true }),
|
|
4482
|
-
body: JSON.stringify(body)
|
|
4483
|
-
}, transport.timeoutMs, { write: false });
|
|
4484
|
-
let answer;
|
|
4485
|
-
try {
|
|
4486
|
-
answer = await readResponseBody(response);
|
|
4487
|
-
} catch (cause) {
|
|
4488
|
-
throw new GalaSDKError("TRANSPORT_ERROR", { url }, {
|
|
4489
|
-
url,
|
|
4490
|
-
cause,
|
|
4491
|
-
write: false
|
|
4492
|
-
});
|
|
4493
|
-
}
|
|
4494
|
-
return dataOf(method, url, response, answer);
|
|
4495
|
-
}
|
|
4496
|
-
function dataOf(method, url, response, answer) {
|
|
4497
|
-
const context = {
|
|
4498
|
-
status: response.status,
|
|
4499
|
-
body: answer,
|
|
4500
|
-
url,
|
|
4501
|
-
write: false
|
|
4502
|
-
};
|
|
4503
|
-
const envelope = isRecord(answer) ? answer : void 0;
|
|
4504
|
-
const chainStatus = envelope === null || envelope === void 0 ? void 0 : envelope["Status"];
|
|
4505
|
-
if (typeof chainStatus === "number" && chainStatus !== 1) throw new GalaSDKError("GATEWAY_READ_REJECTED", {
|
|
4506
|
-
method,
|
|
4507
|
-
chainStatus,
|
|
4508
|
-
errorKey: stringField(envelope, "ErrorKey"),
|
|
4509
|
-
serverMessage: stringField(envelope, "Message")
|
|
4510
|
-
}, context);
|
|
4511
|
-
if (!response.ok) {
|
|
4512
|
-
const chainError = chainErrorOf(answer);
|
|
4513
|
-
throw new GalaSDKError("GATEWAY_HTTP_ERROR", {
|
|
4514
|
-
method,
|
|
4515
|
-
status: response.status,
|
|
4516
|
-
serverMessage: stringField(chainError, "Message") || stringField(envelope, "message")
|
|
4517
|
-
}, context);
|
|
4518
|
-
}
|
|
4519
|
-
const statusAccepted = chainStatus === 1 || chainStatus === void 0 && ANSWERED_WITHOUT_STATUS.has(method);
|
|
4520
|
-
if (envelope === void 0 || !statusAccepted || !("Data" in envelope)) throw new GalaSDKError("GATEWAY_READ_RESPONSE_INVALID", { method }, context);
|
|
4521
|
-
return envelope["Data"];
|
|
4522
|
-
}
|
|
4523
|
-
/** The error for a 2xx whose `Data` is not what `method` answers. */
|
|
4524
|
-
function invalidAnswer(method, data) {
|
|
4525
|
-
return new GalaSDKError("GATEWAY_READ_RESPONSE_INVALID", { method }, {
|
|
4526
|
-
body: data,
|
|
4527
|
-
write: false
|
|
4528
|
-
});
|
|
4529
|
-
}
|
|
4530
|
-
|
|
4531
5028
|
//#endregion
|
|
4532
5029
|
//#region src/reads/types.ts
|
|
4533
5030
|
/**
|
|
@@ -4906,6 +5403,120 @@ function notFoundOf(error) {
|
|
|
4906
5403
|
});
|
|
4907
5404
|
}
|
|
4908
5405
|
|
|
5406
|
+
//#endregion
|
|
5407
|
+
//#region src/reads/nft_collections.ts
|
|
5408
|
+
/** A read's collection name: 3 to 50 letters and digits. @throws GalaSDKError `INVALID_NFT_INPUT`. */
|
|
5409
|
+
function collectionName(name, field) {
|
|
5410
|
+
if (typeof name !== "string") throw new GalaSDKError("INVALID_NFT_INPUT", {
|
|
5411
|
+
field,
|
|
5412
|
+
reason: "not_a_string"
|
|
5413
|
+
});
|
|
5414
|
+
if (name === "") throw new GalaSDKError("INVALID_NFT_INPUT", {
|
|
5415
|
+
field,
|
|
5416
|
+
reason: "empty"
|
|
5417
|
+
});
|
|
5418
|
+
if (!/^[a-zA-Z0-9]{3,50}$/u.test(name)) throw new GalaSDKError("INVALID_NFT_INPUT", {
|
|
5419
|
+
field,
|
|
5420
|
+
reason: "bad_collection_name"
|
|
5421
|
+
});
|
|
5422
|
+
return name;
|
|
5423
|
+
}
|
|
5424
|
+
function validAddress(value) {
|
|
5425
|
+
try {
|
|
5426
|
+
galaChainUserRef(value, "address");
|
|
5427
|
+
return true;
|
|
5428
|
+
} catch {
|
|
5429
|
+
return false;
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
function canonicalAddress(value) {
|
|
5433
|
+
return (validAddress(value) ? galaChainUserRef(value, "address") : value).toLowerCase();
|
|
5434
|
+
}
|
|
5435
|
+
/** NFT collection reads in Launchpad result shapes, using a shared gateway reader. */
|
|
5436
|
+
var NftCollectionReads = class {
|
|
5437
|
+
reads;
|
|
5438
|
+
constructor(reads) {
|
|
5439
|
+
this.reads = reads;
|
|
5440
|
+
}
|
|
5441
|
+
async fetchNftCollections(walletAddress) {
|
|
5442
|
+
const authorizedUser = galaChainUserRef(walletAddress, "walletAddress");
|
|
5443
|
+
return (await this.reads.fetchAllNftCollectionAuthorizations({ pageSize: 1e3 })).filter((row) => row.authorizedUsers.some((user) => canonicalAddress(user) === canonicalAddress(authorizedUser))).map((row) => ({
|
|
5444
|
+
authorizedUser,
|
|
5445
|
+
collection: row.collection
|
|
5446
|
+
}));
|
|
5447
|
+
}
|
|
5448
|
+
async isNftCollectionAvailable(name) {
|
|
5449
|
+
const collection = collectionName(name, "collection");
|
|
5450
|
+
return !(await this.reads.fetchAllNftCollectionAuthorizations({ pageSize: 1e3 })).some((row) => row.collection === collection);
|
|
5451
|
+
}
|
|
5452
|
+
async fetchNftTokenClasses(params) {
|
|
5453
|
+
collectionName(params.collection, "collection");
|
|
5454
|
+
return (await this.reads.fetchAllTokenClasses({
|
|
5455
|
+
collection: params.collection,
|
|
5456
|
+
category: params.category,
|
|
5457
|
+
type: params.type
|
|
5458
|
+
}, { pageSize: 1e3 })).map((row) => ({
|
|
5459
|
+
collection: row.collection,
|
|
5460
|
+
type: row.type,
|
|
5461
|
+
category: row.category,
|
|
5462
|
+
additionalKey: row.additionalKey,
|
|
5463
|
+
totalSupply: row.totalSupply,
|
|
5464
|
+
maxSupply: row.maxSupply,
|
|
5465
|
+
isNonFungible: row.isNonFungible,
|
|
5466
|
+
name: row.name,
|
|
5467
|
+
description: row.description,
|
|
5468
|
+
image: row.image,
|
|
5469
|
+
symbol: row.symbol,
|
|
5470
|
+
...row.rarity === void 0 ? {} : { rarity: row.rarity }
|
|
5471
|
+
}));
|
|
5472
|
+
}
|
|
5473
|
+
async fetchNftBalances(ownerAddress, collectionFilter) {
|
|
5474
|
+
const owner = galaChainUserRef(ownerAddress, "ownerAddress");
|
|
5475
|
+
return (await this.reads.fetchNftBalances({
|
|
5476
|
+
owner,
|
|
5477
|
+
collection: collectionFilter
|
|
5478
|
+
})).map((row) => ({
|
|
5479
|
+
owner: row.owner,
|
|
5480
|
+
collection: row.collection,
|
|
5481
|
+
category: row.category,
|
|
5482
|
+
type: row.type,
|
|
5483
|
+
additionalKey: row.additionalKey,
|
|
5484
|
+
instanceIds: [...row.instanceIds],
|
|
5485
|
+
totalOwned: row.instanceIds.length
|
|
5486
|
+
}));
|
|
5487
|
+
}
|
|
5488
|
+
};
|
|
5489
|
+
|
|
5490
|
+
//#endregion
|
|
5491
|
+
//#region src/reads/nft_fees.ts
|
|
5492
|
+
function getNftCollectionClaimFee() {
|
|
5493
|
+
return "10000";
|
|
5494
|
+
}
|
|
5495
|
+
function getNftTokenClassCreateFee() {
|
|
5496
|
+
return "1000";
|
|
5497
|
+
}
|
|
5498
|
+
/** Calculate the fixed fees for the requested collection and token-class operations. */
|
|
5499
|
+
function estimateNftOperationFees(params) {
|
|
5500
|
+
let totalFee = "0";
|
|
5501
|
+
const breakdown = {};
|
|
5502
|
+
if (params.claimCollection) {
|
|
5503
|
+
const fee = getNftCollectionClaimFee();
|
|
5504
|
+
breakdown.collectionClaim = fee;
|
|
5505
|
+
totalFee = String(BigInt(totalFee) + BigInt(fee));
|
|
5506
|
+
}
|
|
5507
|
+
if ((params.createTokenClasses ?? 0) > 0) {
|
|
5508
|
+
const count = params.createTokenClasses;
|
|
5509
|
+
const fee = getNftTokenClassCreateFee();
|
|
5510
|
+
breakdown.tokenClassCreate = fee;
|
|
5511
|
+
breakdown.tokenClassCount = count;
|
|
5512
|
+
totalFee = String(BigInt(totalFee) + BigInt(fee) * BigInt(count));
|
|
5513
|
+
}
|
|
5514
|
+
return {
|
|
5515
|
+
totalFee,
|
|
5516
|
+
breakdown
|
|
5517
|
+
};
|
|
5518
|
+
}
|
|
5519
|
+
|
|
4909
5520
|
//#endregion
|
|
4910
5521
|
//#region src/config/environments.ts
|
|
4911
5522
|
/**
|
|
@@ -4933,6 +5544,7 @@ exports.BRIDGE_NETWORKS = BRIDGE_NETWORKS;
|
|
|
4933
5544
|
exports.BRIDGE_OUT_STEPS = BRIDGE_OUT_STEPS;
|
|
4934
5545
|
exports.BrowserWalletSigner = BrowserWalletSigner;
|
|
4935
5546
|
exports.CHAIN_CONTRACT_OPERATION_PREFIXES = CHAIN_CONTRACT_OPERATION_PREFIXES;
|
|
5547
|
+
exports.CHAIN_METHOD_OPERATIONS = CHAIN_METHOD_OPERATIONS;
|
|
4936
5548
|
exports.DEFAULT_UNIQUE_KEY_PREFIX = DEFAULT_UNIQUE_KEY_PREFIX;
|
|
4937
5549
|
exports.EIP712_CAPABLE_METHODS = EIP712_CAPABLE_METHODS;
|
|
4938
5550
|
exports.FAILURE_OUTCOMES = FAILURE_OUTCOMES;
|
|
@@ -4953,8 +5565,13 @@ exports.GalaSDKError = GalaSDKError;
|
|
|
4953
5565
|
exports.GalaWalletSigner = GalaWalletSigner;
|
|
4954
5566
|
exports.GatewayReads = GatewayReads;
|
|
4955
5567
|
exports.GatewayWrites = GatewayWrites;
|
|
5568
|
+
exports.INVALID_NFT_INPUT_REASONS = INVALID_NFT_INPUT_REASONS;
|
|
4956
5569
|
exports.INVALID_PRIVATE_KEY_REASONS = INVALID_PRIVATE_KEY_REASONS;
|
|
4957
5570
|
exports.INVALID_TOKEN_REFERENCE_REASONS = INVALID_TOKEN_REFERENCE_REASONS;
|
|
5571
|
+
exports.NFT_DEFAULT_ADDITIONAL_KEY = NFT_DEFAULT_ADDITIONAL_KEY;
|
|
5572
|
+
exports.NFT_MINT_LIMIT = NFT_MINT_LIMIT;
|
|
5573
|
+
exports.NFT_WRITE_METHODS = NFT_WRITE_METHODS;
|
|
5574
|
+
exports.NftCollectionReads = NftCollectionReads;
|
|
4958
5575
|
exports.PAGE_REQUEST_FIELDS = PAGE_REQUEST_FIELDS;
|
|
4959
5576
|
exports.PrivateKeySigner = PrivateKeySigner;
|
|
4960
5577
|
exports.SIGNING_FAILURE_REASONS = SIGNING_FAILURE_REASONS;
|
|
@@ -4979,6 +5596,7 @@ exports.createWallet = createWallet;
|
|
|
4979
5596
|
exports.dtoOperationOf = dtoOperationOf;
|
|
4980
5597
|
exports.eip1193ProviderFromEthers = eip1193ProviderFromEthers;
|
|
4981
5598
|
exports.eip712DomainFor = eip712DomainFor;
|
|
5599
|
+
exports.estimateNftOperationFees = estimateNftOperationFees;
|
|
4982
5600
|
exports.ethAddressOfPrivateKey = ethAddressOfPrivateKey;
|
|
4983
5601
|
exports.ethereumAddressOfAccount = ethereumAddressOfAccount;
|
|
4984
5602
|
exports.fetchRequestor = fetchRequestor;
|
|
@@ -4987,6 +5605,8 @@ exports.galaChainUserRef = galaChainUserRef;
|
|
|
4987
5605
|
exports.galaErrorTemplates = galaErrorTemplates;
|
|
4988
5606
|
exports.generateEIP712Types = generateEIP712Types;
|
|
4989
5607
|
exports.getEthereumAddressFromPrivateKey = getEthereumAddressFromPrivateKey;
|
|
5608
|
+
exports.getNftCollectionClaimFee = getNftCollectionClaimFee;
|
|
5609
|
+
exports.getNftTokenClassCreateFee = getNftTokenClassCreateFee;
|
|
4990
5610
|
exports.getPayloadToSign = getPayloadToSign;
|
|
4991
5611
|
exports.getPublicKeyFromPrivateKey = getPublicKeyFromPrivateKey;
|
|
4992
5612
|
exports.hasGalaErrorBrand = hasGalaErrorBrand;
|