@ab-org/predicate-market-sdk 2.0.0 → 2.1.1-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.
- package/README.md +42 -7
- package/dist/account-F5Z2SMJE.js +213 -0
- package/dist/api-DyQAYQ0i.d.ts +156 -0
- package/dist/auth.d.ts +8 -0
- package/dist/auth.js +1 -0
- package/dist/autoReconnect-IFPVI2XU.js +33 -0
- package/dist/chunk-6YQEHB6P.js +14 -0
- package/dist/chunk-F2UPP3YC.js +88 -0
- package/dist/chunk-IUBVUCWJ.js +419 -0
- package/dist/chunk-JFRRJXOJ.js +149 -0
- package/dist/chunk-LOJTP47I.js +6 -0
- package/dist/chunk-SHLNBZBY.js +72 -0
- package/dist/chunk-SZYGIQT3.js +3192 -0
- package/dist/chunk-TPMI3XWV.js +114 -0
- package/dist/chunk-UAXKA6QC.js +17 -0
- package/dist/chunk-WHTI52FI.js +10 -0
- package/dist/chunk-XB2DFS2W.js +50 -0
- package/dist/chunk-YX56ZGDB.js +274 -0
- package/dist/core.d.ts +63 -0
- package/dist/core.js +6 -0
- package/dist/dist-Q2PDXT2F.js +81 -0
- package/dist/index.d.ts +12 -706
- package/dist/index.js +12 -43009
- package/dist/merchant.d.ts +206 -0
- package/dist/merchant.js +4 -0
- package/dist/react.d.ts +197 -0
- package/dist/react.js +7 -0
- package/dist/signInTypes-DESvmgWG.d.ts +41 -0
- package/dist/types-BFidNjd9.d.ts +64 -0
- package/package.json +23 -11
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { setMerchantBaseUrl, getMerchantBaseUrl } from './chunk-SHLNBZBY.js';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
|
|
4
|
+
var merchantApiConfig = {};
|
|
5
|
+
var apiClient;
|
|
6
|
+
function resolveMerchantBaseUrl() {
|
|
7
|
+
return merchantApiConfig.baseUrl ?? getMerchantBaseUrl();
|
|
8
|
+
}
|
|
9
|
+
function createClient(baseUrl) {
|
|
10
|
+
if (!baseUrl) {
|
|
11
|
+
throw new Error("MERCHANT_BASE_URL is not set");
|
|
12
|
+
}
|
|
13
|
+
return axios.create({
|
|
14
|
+
baseURL: baseUrl,
|
|
15
|
+
timeout: 3e4,
|
|
16
|
+
headers: { "Content-Type": "application/json" }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function getOrCreateMerchantApiClient() {
|
|
20
|
+
if (merchantApiConfig.client) return merchantApiConfig.client;
|
|
21
|
+
if (!apiClient) {
|
|
22
|
+
apiClient = createClient(resolveMerchantBaseUrl());
|
|
23
|
+
}
|
|
24
|
+
return apiClient;
|
|
25
|
+
}
|
|
26
|
+
function unwrap(res) {
|
|
27
|
+
if (res.code !== 0 || res.data === null) {
|
|
28
|
+
throw new Error(res.msg || "API error");
|
|
29
|
+
}
|
|
30
|
+
return res.data;
|
|
31
|
+
}
|
|
32
|
+
function configureMerchantApi(config = {}) {
|
|
33
|
+
if ("baseUrl" in config) {
|
|
34
|
+
setMerchantBaseUrl(config.baseUrl);
|
|
35
|
+
}
|
|
36
|
+
if (config.client) {
|
|
37
|
+
merchantApiConfig = {
|
|
38
|
+
...merchantApiConfig,
|
|
39
|
+
...config,
|
|
40
|
+
client: config.client
|
|
41
|
+
};
|
|
42
|
+
apiClient = config.client;
|
|
43
|
+
return config.client;
|
|
44
|
+
}
|
|
45
|
+
merchantApiConfig = {
|
|
46
|
+
...merchantApiConfig,
|
|
47
|
+
...config,
|
|
48
|
+
client: void 0
|
|
49
|
+
};
|
|
50
|
+
apiClient = void 0;
|
|
51
|
+
return getOrCreateMerchantApiClient();
|
|
52
|
+
}
|
|
53
|
+
function getMerchantApiClient() {
|
|
54
|
+
return getOrCreateMerchantApiClient();
|
|
55
|
+
}
|
|
56
|
+
async function getChains() {
|
|
57
|
+
try {
|
|
58
|
+
const { data } = await getOrCreateMerchantApiClient().get("/chains");
|
|
59
|
+
return unwrap(data);
|
|
60
|
+
} catch {
|
|
61
|
+
throw new Error("Failed to get chains");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
async function registerPlatform(body) {
|
|
65
|
+
try {
|
|
66
|
+
const { data } = await getOrCreateMerchantApiClient().post(
|
|
67
|
+
"/api/v1/platform",
|
|
68
|
+
body
|
|
69
|
+
);
|
|
70
|
+
return unwrap(data);
|
|
71
|
+
} catch {
|
|
72
|
+
throw new Error("Failed to register platform");
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function quote(body) {
|
|
76
|
+
const { data } = await getOrCreateMerchantApiClient().post(
|
|
77
|
+
"/api/v1/quote",
|
|
78
|
+
body
|
|
79
|
+
);
|
|
80
|
+
return unwrap(data);
|
|
81
|
+
}
|
|
82
|
+
async function getDepositOrder(orderId) {
|
|
83
|
+
try {
|
|
84
|
+
const { data } = await getOrCreateMerchantApiClient().get(
|
|
85
|
+
`/api/v1/orders/deposit/${encodeURIComponent(orderId)}`
|
|
86
|
+
);
|
|
87
|
+
return unwrap(data);
|
|
88
|
+
} catch {
|
|
89
|
+
throw new Error("Failed to get deposit order");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async function getWithdrawOrder(orderId) {
|
|
93
|
+
try {
|
|
94
|
+
const { data } = await getOrCreateMerchantApiClient().get(
|
|
95
|
+
`/api/v1/orders/withdraw/${encodeURIComponent(orderId)}`
|
|
96
|
+
);
|
|
97
|
+
return unwrap(data);
|
|
98
|
+
} catch {
|
|
99
|
+
throw new Error("Failed to get withdraw order");
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function createOrder(body) {
|
|
103
|
+
try {
|
|
104
|
+
const { data } = await getOrCreateMerchantApiClient().post(
|
|
105
|
+
"/order",
|
|
106
|
+
body
|
|
107
|
+
);
|
|
108
|
+
return unwrap(data);
|
|
109
|
+
} catch {
|
|
110
|
+
throw new Error("Failed to create order");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export { configureMerchantApi, createOrder, getChains, getDepositOrder, getMerchantApiClient, getWithdrawOrder, quote, registerPlatform };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// ../sign_in_sdk/src/popupOAuthBridge.ts
|
|
2
|
+
var MESSAGE_TYPE = "twitter-oauth-callback";
|
|
3
|
+
function notifyTwitterCallback() {
|
|
4
|
+
const params = new URLSearchParams(window.location.search);
|
|
5
|
+
const code = params.get("code");
|
|
6
|
+
const state = params.get("state");
|
|
7
|
+
const error = params.get("error");
|
|
8
|
+
if (window.opener) {
|
|
9
|
+
window.opener.postMessage(
|
|
10
|
+
{ type: MESSAGE_TYPE, code, state, error },
|
|
11
|
+
window.location.origin
|
|
12
|
+
);
|
|
13
|
+
window.close();
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { notifyTwitterCallback };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// src/utils/explorer.ts
|
|
2
|
+
var explorerTemplates = {
|
|
3
|
+
"0": "",
|
|
4
|
+
"1": "https://etherscan.io/tx/{txId}",
|
|
5
|
+
"3": "https://dogechain.info/tx/{txId}",
|
|
6
|
+
"10": "https://optimistic.etherscan.io/tx/{txId}",
|
|
7
|
+
"56": "https://bscscan.com/tx/{txId}",
|
|
8
|
+
"110": "",
|
|
9
|
+
"126": "https://explorer.movementnetwork.xyz/txn/{txId}?network=mainnet",
|
|
10
|
+
"137": "https://polygonscan.com/tx/{txId}",
|
|
11
|
+
"204": "https://opbnb.bscscan.com/tx/{txId}",
|
|
12
|
+
"223": "https://explorer.bsquared.network/tx/{txId}",
|
|
13
|
+
"227": "https://promscan.io/tx/{txId}",
|
|
14
|
+
"324": "https://mainnet.era.zksync.io/tx/{txId}",
|
|
15
|
+
"400": "",
|
|
16
|
+
"420": "https://scan.merlinchain.io/tx/{txId}",
|
|
17
|
+
"480": "https://worldchain-mainnet.explorer.alchemy.com/tx/{txId}",
|
|
18
|
+
"501": "https://solscan.io/tx/{txId}",
|
|
19
|
+
"784": "",
|
|
20
|
+
"1329": "https://seitrace.com/tx/{txId}",
|
|
21
|
+
"1514": "https://mainnet.storyscan.xyz/tx/{txId}",
|
|
22
|
+
"1625": "https://explorer.gravity.xyz/tx/{txId}",
|
|
23
|
+
"2649": "https://mainnet-explorer.ailayer.xyz/tx/{txId}",
|
|
24
|
+
"3030": "https://dashboard.tenderly.co/explorer/vnet/bd8df763-9888-4be3-9a78-26f1d5ab8d3d/tx/{txId}",
|
|
25
|
+
"3131": "https://dashboard.tenderly.co/explorer/vnet/6593bc72-f548-497d-bff9-5be061436a48/tx/{txId}",
|
|
26
|
+
"5545": "https://scan.duckchain.io/tx/{txId}",
|
|
27
|
+
"8333": "https://mainnet-rpc.b3.fun/http/tx/{txId}",
|
|
28
|
+
"8453": "https://base.blockscout.com/tx/{txId}",
|
|
29
|
+
"19484": "https://tronscan.org/#/transaction/{txId}",
|
|
30
|
+
"21000": "https://maizenet-explorer.usecorn.com/tx/{txId}",
|
|
31
|
+
"42161": "https://arbiscan.io/tx/{txId}",
|
|
32
|
+
"43114": "https://snowtrace.io/tx/{txId}",
|
|
33
|
+
"47763": "https://neotube.io/transaction/{txId}",
|
|
34
|
+
"59144": "https://lineascan.build/tx/{txId}",
|
|
35
|
+
"60808": "https://rpc.gobob.xyz/tx/{txId}",
|
|
36
|
+
"80094": "https://berascan.com/tx/{txId}",
|
|
37
|
+
"81457": "https://blastscan.io/tx/{txId}",
|
|
38
|
+
"200901": "https://rpc.bitlayer.org/tx/{txId}",
|
|
39
|
+
"221122420": "https://blockscout.devnet.doge.xyz/tx/{txId}",
|
|
40
|
+
"534352": "https://scrollscan.com/tx/{txId}"
|
|
41
|
+
};
|
|
42
|
+
function getExplorerUrl(chainId, data) {
|
|
43
|
+
const template = explorerTemplates[chainId] ?? "";
|
|
44
|
+
if (template === "") {
|
|
45
|
+
throw new Error(`chainId ${chainId} tpl not found`);
|
|
46
|
+
}
|
|
47
|
+
return template.replace("{txId}", data.txId);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export { getExplorerUrl };
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// ../wallet-utils/dist/index.js
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __export = (target, all) => {
|
|
4
|
+
for (var name in all)
|
|
5
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
6
|
+
};
|
|
7
|
+
var cache_exports = {};
|
|
8
|
+
__export(cache_exports, {
|
|
9
|
+
clear: () => clear,
|
|
10
|
+
get: () => get,
|
|
11
|
+
remove: () => remove,
|
|
12
|
+
set: () => set,
|
|
13
|
+
setKeyNS: () => setKeyNS
|
|
14
|
+
});
|
|
15
|
+
var keyNS = "tomo-";
|
|
16
|
+
function get(key) {
|
|
17
|
+
if (typeof window === "undefined") {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
const tempKey = keyNS + key;
|
|
21
|
+
if (!isKeyExist(tempKey)) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
let val = null;
|
|
25
|
+
try {
|
|
26
|
+
const data = window.localStorage.getItem(tempKey) || window.sessionStorage.getItem(tempKey);
|
|
27
|
+
val = JSON.parse(data);
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.error(err);
|
|
30
|
+
}
|
|
31
|
+
if (val !== null && Object.prototype.hasOwnProperty.call(val, "type") && Object.prototype.hasOwnProperty.call(val, "data")) {
|
|
32
|
+
return val["data"];
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
function set(key, val, isTemp) {
|
|
37
|
+
if (typeof window === "undefined") {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
let store;
|
|
41
|
+
if (isTemp) {
|
|
42
|
+
store = window.sessionStorage;
|
|
43
|
+
} else {
|
|
44
|
+
store = window.localStorage;
|
|
45
|
+
}
|
|
46
|
+
const data = JSON.stringify({
|
|
47
|
+
data: val,
|
|
48
|
+
time: (/* @__PURE__ */ new Date()).getTime(),
|
|
49
|
+
//for manage by time limit
|
|
50
|
+
type: typeof val
|
|
51
|
+
});
|
|
52
|
+
try {
|
|
53
|
+
store.setItem(keyNS + key, data);
|
|
54
|
+
return true;
|
|
55
|
+
} catch (err) {
|
|
56
|
+
if (err?.name?.toUpperCase().indexOf("QUOTA") >= 0) {
|
|
57
|
+
window.localStorage.clear();
|
|
58
|
+
store.setItem(keyNS + key, data);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
function remove(key) {
|
|
64
|
+
if (typeof window === "undefined") {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const tempKey = keyNS + key;
|
|
68
|
+
window.localStorage.removeItem(tempKey);
|
|
69
|
+
window.sessionStorage.removeItem(tempKey);
|
|
70
|
+
}
|
|
71
|
+
function clear() {
|
|
72
|
+
if (typeof window === "undefined") {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
window?.localStorage?.clear();
|
|
76
|
+
window?.sessionStorage?.clear();
|
|
77
|
+
}
|
|
78
|
+
function isKeyExist(key) {
|
|
79
|
+
if (typeof window === "undefined") {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return Object.prototype.hasOwnProperty.call(window.localStorage, key) || Object.prototype.hasOwnProperty.call(window.sessionStorage, key);
|
|
83
|
+
}
|
|
84
|
+
function setKeyNS(NS) {
|
|
85
|
+
const isString = typeof NS === "string";
|
|
86
|
+
if (isString && NS !== "") {
|
|
87
|
+
keyNS = NS;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
function pick(...candidates) {
|
|
91
|
+
for (const c of candidates) {
|
|
92
|
+
if (c != null && c !== "") return c;
|
|
93
|
+
}
|
|
94
|
+
return void 0;
|
|
95
|
+
}
|
|
96
|
+
function nextPublicProcessEnvKey(logicalKey) {
|
|
97
|
+
return `NEXT_PUBLIC_${logicalKey}`;
|
|
98
|
+
}
|
|
99
|
+
function readProcessEnvStatic(key) {
|
|
100
|
+
if (typeof process === "undefined" || !process.env) return void 0;
|
|
101
|
+
switch (key) {
|
|
102
|
+
case "STAGE":
|
|
103
|
+
return pick(
|
|
104
|
+
process.env.NEXT_PUBLIC_STAGE,
|
|
105
|
+
process.env.STAGE
|
|
106
|
+
);
|
|
107
|
+
case "FUNDING_CHAIN_ID":
|
|
108
|
+
return pick(
|
|
109
|
+
process.env.NEXT_PUBLIC_FUNDING_CHAIN_ID,
|
|
110
|
+
process.env.FUNDING_CHAIN_ID
|
|
111
|
+
);
|
|
112
|
+
/** Next.js 仅内联「静态」`process.env.NEXT_PUBLIC_*`;动态键名在客户端会为 undefined,必须逐键写出。 */
|
|
113
|
+
case "GOOGLE_CLIENT_ID":
|
|
114
|
+
return pick(
|
|
115
|
+
process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID,
|
|
116
|
+
process.env.GOOGLE_CLIENT_ID
|
|
117
|
+
);
|
|
118
|
+
case "X_CLIENT_ID":
|
|
119
|
+
return pick(
|
|
120
|
+
process.env.NEXT_PUBLIC_X_CLIENT_ID,
|
|
121
|
+
process.env.X_CLIENT_ID
|
|
122
|
+
);
|
|
123
|
+
case "MERCHANT_BASE_URL":
|
|
124
|
+
return pick(
|
|
125
|
+
process.env.NEXT_PUBLIC_MERCHANT_BASE_URL,
|
|
126
|
+
process.env.MERCHANT_BASE_URL
|
|
127
|
+
);
|
|
128
|
+
case "RELAY_ORIGIN":
|
|
129
|
+
return pick(
|
|
130
|
+
process.env.NEXT_PUBLIC_RELAY_ORIGIN,
|
|
131
|
+
process.env.RELAY_ORIGIN
|
|
132
|
+
);
|
|
133
|
+
case "CUBE_SIGNER_ENV":
|
|
134
|
+
return pick(
|
|
135
|
+
process.env.NEXT_PUBLIC_CUBE_SIGNER_ENV,
|
|
136
|
+
process.env.CUBE_SIGNER_ENV
|
|
137
|
+
);
|
|
138
|
+
case "CUBE_SIGNER_ORG_ID":
|
|
139
|
+
return pick(
|
|
140
|
+
process.env.NEXT_PUBLIC_CUBE_SIGNER_ORG_ID,
|
|
141
|
+
process.env.CUBE_SIGNER_ORG_ID
|
|
142
|
+
);
|
|
143
|
+
case "CUBE_REG":
|
|
144
|
+
return pick(
|
|
145
|
+
process.env.NEXT_PUBLIC_CUBE_REG,
|
|
146
|
+
process.env.CUBE_REG
|
|
147
|
+
);
|
|
148
|
+
case "FUNDING_TOKEN_SYMBOL":
|
|
149
|
+
return pick(
|
|
150
|
+
process.env.NEXT_PUBLIC_FUNDING_TOKEN_SYMBOL,
|
|
151
|
+
process.env.FUNDING_TOKEN_SYMBOL
|
|
152
|
+
);
|
|
153
|
+
case "FUNDING_TOKEN_ADDRESS":
|
|
154
|
+
return pick(
|
|
155
|
+
process.env.NEXT_PUBLIC_FUNDING_TOKEN_ADDRESS,
|
|
156
|
+
process.env.FUNDING_TOKEN_ADDRESS
|
|
157
|
+
);
|
|
158
|
+
default:
|
|
159
|
+
return pick(
|
|
160
|
+
process.env[`NEXT_PUBLIC_${key}`],
|
|
161
|
+
process.env[key]
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
function getEnv(key) {
|
|
166
|
+
const staticVal = readProcessEnvStatic(key);
|
|
167
|
+
if (staticVal != null && staticVal !== "") return staticVal;
|
|
168
|
+
const g = globalThis;
|
|
169
|
+
const env = g.process?.env;
|
|
170
|
+
if (env) {
|
|
171
|
+
const pub = nextPublicProcessEnvKey(key);
|
|
172
|
+
const v = env[key] ?? env[pub];
|
|
173
|
+
if (v != null && v !== "") return v;
|
|
174
|
+
}
|
|
175
|
+
try {
|
|
176
|
+
const m = import.meta.env;
|
|
177
|
+
if (m) {
|
|
178
|
+
const pub = nextPublicProcessEnvKey(key);
|
|
179
|
+
const v = m[key] ?? m[pub];
|
|
180
|
+
if (v != null && v !== "") return v;
|
|
181
|
+
}
|
|
182
|
+
} catch {
|
|
183
|
+
}
|
|
184
|
+
return "";
|
|
185
|
+
}
|
|
186
|
+
var TENDERLY_BSC_3131 = {
|
|
187
|
+
chainId: "3131",
|
|
188
|
+
name: "BSC_TENDERLY",
|
|
189
|
+
chainName: "BSC_TENDERLY",
|
|
190
|
+
nativeCurrencyName: "BSC",
|
|
191
|
+
nativeCurrencySymbol: "BSC",
|
|
192
|
+
nativeCurrencyDecimals: 18,
|
|
193
|
+
rpcUrls: [
|
|
194
|
+
"https://virtual.binance.eu.rpc.tenderly.co/e643ea28-32eb-4fb9-8116-90be24f7defa"
|
|
195
|
+
],
|
|
196
|
+
blockExplorerUrl: "https://dashboard.tenderly.co/explorer/vnet/6593bc72-f548-497d-bff9-5be061436a48",
|
|
197
|
+
platformType: "EVM",
|
|
198
|
+
icon: "https://static.tomo.inc/token/bsc_new.svg",
|
|
199
|
+
// Tenderly 默认资金侧合约地址(测试环境镜像):
|
|
200
|
+
defaultFundingTokenAddress: "0x55d398326f99059fF775485246999027B3197955"
|
|
201
|
+
};
|
|
202
|
+
var BSC_MAINNET_56 = {
|
|
203
|
+
chainId: "56",
|
|
204
|
+
name: "BSC",
|
|
205
|
+
chainName: "BNB Smart Chain",
|
|
206
|
+
nativeCurrencyName: "BNB",
|
|
207
|
+
nativeCurrencySymbol: "BNB",
|
|
208
|
+
nativeCurrencyDecimals: 18,
|
|
209
|
+
rpcUrls: ["https://bsc-dataseed.binance.org", "https://bsc-dataseed1.defibit.io"],
|
|
210
|
+
blockExplorerUrl: "https://bscscan.com",
|
|
211
|
+
platformType: "EVM",
|
|
212
|
+
icon: "https://static.tomo.inc/token/bsc_new.svg",
|
|
213
|
+
// 主网默认资金侧合约地址(USDT);如需覆盖请使用 FUNDING_TOKEN_ADDRESS 环境变量
|
|
214
|
+
defaultFundingTokenAddress: "0x55d398326f99059fF775485246999027B3197955"
|
|
215
|
+
};
|
|
216
|
+
var CHAIN_REGISTRY = {
|
|
217
|
+
[TENDERLY_BSC_3131.chainId]: TENDERLY_BSC_3131,
|
|
218
|
+
[BSC_MAINNET_56.chainId]: BSC_MAINNET_56
|
|
219
|
+
};
|
|
220
|
+
var DEFAULT_FUNDING_CHAIN_ID = getEnv("FUNDING_CHAIN_ID") || "3131";
|
|
221
|
+
function normalizeFundingChainId(chainId) {
|
|
222
|
+
if (chainId === void 0 || chainId === null) return DEFAULT_FUNDING_CHAIN_ID;
|
|
223
|
+
const s = String(chainId).trim();
|
|
224
|
+
return s === "" ? DEFAULT_FUNDING_CHAIN_ID : s;
|
|
225
|
+
}
|
|
226
|
+
function getChainInfo(chainId) {
|
|
227
|
+
const id = normalizeFundingChainId(chainId);
|
|
228
|
+
const info = CHAIN_REGISTRY[id];
|
|
229
|
+
if (!info) {
|
|
230
|
+
throw new Error(
|
|
231
|
+
`Unsupported funding chainId "${id}". Supported: ${Object.keys(CHAIN_REGISTRY).sort().join(", ")}`
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
return info;
|
|
235
|
+
}
|
|
236
|
+
function pickEnvFundingTokenAddress() {
|
|
237
|
+
const tryPairs = [
|
|
238
|
+
["NEXT_PUBLIC_FUNDING_TOKEN_ADDRESS", "FUNDING_TOKEN_ADDRESS"]
|
|
239
|
+
];
|
|
240
|
+
if (typeof process !== "undefined" && process.env) {
|
|
241
|
+
for (const [pub, priv] of tryPairs) {
|
|
242
|
+
const a = process.env[pub];
|
|
243
|
+
const b = process.env[priv];
|
|
244
|
+
if (a != null && a !== "") return a;
|
|
245
|
+
if (b != null && b !== "") return b;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const m = import.meta.env;
|
|
250
|
+
if (m) {
|
|
251
|
+
for (const [pub, priv] of tryPairs) {
|
|
252
|
+
const a = m[pub];
|
|
253
|
+
const b = m[priv];
|
|
254
|
+
if (a != null && a !== "") return a;
|
|
255
|
+
if (b != null && b !== "") return b;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} catch {
|
|
259
|
+
}
|
|
260
|
+
return void 0;
|
|
261
|
+
}
|
|
262
|
+
function getFundingTokenAddress(chainId) {
|
|
263
|
+
const v = pickEnvFundingTokenAddress();
|
|
264
|
+
if (v && /^0x[0-9a-fA-F]{40}$/.test(v)) return v;
|
|
265
|
+
return getChainInfo(chainId).defaultFundingTokenAddress;
|
|
266
|
+
}
|
|
267
|
+
getFundingTokenAddress(DEFAULT_FUNDING_CHAIN_ID);
|
|
268
|
+
({
|
|
269
|
+
google: getEnv("GOOGLE_CLIENT_ID"),
|
|
270
|
+
x: getEnv("X_CLIENT_ID")
|
|
271
|
+
});
|
|
272
|
+
new TextEncoder();
|
|
273
|
+
|
|
274
|
+
export { cache_exports, getChainInfo, getEnv };
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export { C as ChainInfo, a as CustodyAdapter, D as DepositAddressResult, M as MarketDataProvider, b as ModalController, Q as QuoteRequest, c as QuoteResult, T as TokenInfo } from './types-BFidNjd9.js';
|
|
2
|
+
import { CubeSignerConfig } from '@ab-org/sdk-core/social/auth';
|
|
3
|
+
import { S as SignInUiConfig } from './signInTypes-DESvmgWG.js';
|
|
4
|
+
import { WalletSession } from '@ab-org/sdk-core';
|
|
5
|
+
import 'react';
|
|
6
|
+
|
|
7
|
+
interface SDKConfig$1 {
|
|
8
|
+
googleClientId?: string;
|
|
9
|
+
twitterClientId?: string;
|
|
10
|
+
twitterRedirectUri?: string;
|
|
11
|
+
cubeSigner?: CubeSignerConfig;
|
|
12
|
+
signIn?: SignInUiConfig;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Public shape matches `@ab-org/sign-in-sdk` (single source of truth for runtime config). */
|
|
16
|
+
type SDKConfig = SDKConfig$1;
|
|
17
|
+
/**
|
|
18
|
+
* Fixed auth config: bundled defaults (see bundledConfig.ts) with optional
|
|
19
|
+
* overrides from environment (`NEXT_PUBLIC_*` / server). Used as defaults in {@link initSDK}.
|
|
20
|
+
*/
|
|
21
|
+
declare function getFixedAuthConfig(): Partial<SDKConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* Predicate SDK init: merges env/bundled defaults into `@ab-org/sign-in-sdk` config.
|
|
24
|
+
* Optional `registerUser` is merged into `cubeSigner.oidcLoginHooks` when `cubeSigner` is set.
|
|
25
|
+
*/
|
|
26
|
+
interface PredicateSDKConfig extends Partial<SDKConfig> {
|
|
27
|
+
merchantBaseUrl?: string;
|
|
28
|
+
registerUser?: (oidcToken: string) => Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
declare function initSDK(config?: PredicateSDKConfig): void;
|
|
31
|
+
declare function getSDKConfig(): Readonly<SDKConfig>;
|
|
32
|
+
|
|
33
|
+
declare function getEnv(key: string): string;
|
|
34
|
+
|
|
35
|
+
declare function getExplorerUrl(chainId: string, data: {
|
|
36
|
+
txId: string;
|
|
37
|
+
}): string;
|
|
38
|
+
|
|
39
|
+
type EvmChainInfo = {
|
|
40
|
+
chainId: string;
|
|
41
|
+
name: string;
|
|
42
|
+
chainName: string;
|
|
43
|
+
nativeCurrencyName: string;
|
|
44
|
+
nativeCurrencySymbol: string;
|
|
45
|
+
nativeCurrencyDecimals: number;
|
|
46
|
+
rpcUrls: readonly string[];
|
|
47
|
+
blockExplorerUrl: string;
|
|
48
|
+
platformType: "EVM";
|
|
49
|
+
icon: string;
|
|
50
|
+
defaultFundingTokenAddress: string;
|
|
51
|
+
};
|
|
52
|
+
declare const DEFAULT_FUNDING_CHAIN_ID: string;
|
|
53
|
+
declare function getChainInfo(chainId?: string | number | null): EvmChainInfo;
|
|
54
|
+
declare function getFundingTokenAddress(chainId?: string | number | null): string;
|
|
55
|
+
declare const DEFAULT_FUNDING_TOKEN_ADDRESS: string;
|
|
56
|
+
declare const ClientIds: {
|
|
57
|
+
google: string;
|
|
58
|
+
x: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
declare function tryAutoReconnect(): Promise<WalletSession | null>;
|
|
62
|
+
|
|
63
|
+
export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, type EvmChainInfo, type PredicateSDKConfig, type SDKConfig, SignInUiConfig, getChainInfo, getEnv, getExplorerUrl, getFixedAuthConfig, getFundingTokenAddress, getSDKConfig, initSDK, tryAutoReconnect };
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { tryAutoReconnect } from './chunk-LOJTP47I.js';
|
|
2
|
+
export { ClientIds, DEFAULT_FUNDING_CHAIN_ID, DEFAULT_FUNDING_TOKEN_ADDRESS, getChainInfo, getFundingTokenAddress } from './chunk-F2UPP3YC.js';
|
|
3
|
+
export { getExplorerUrl } from './chunk-XB2DFS2W.js';
|
|
4
|
+
export { getFixedAuthConfig, getSDKConfig, initSDK } from './chunk-JFRRJXOJ.js';
|
|
5
|
+
export { getEnv } from './chunk-SHLNBZBY.js';
|
|
6
|
+
import './chunk-WHTI52FI.js';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { getEnv } from './chunk-YX56ZGDB.js';
|
|
2
|
+
|
|
3
|
+
// ../oidc-auth/dist/index.js
|
|
4
|
+
var _ = { googleAuth: "ab-google-authorized", xAuth: "ab-twitter-authorized", telegramAuth: "ab-telegram-authorized" };
|
|
5
|
+
var x = 60;
|
|
6
|
+
var S = { prod: "prod", dev: "gamma" };
|
|
7
|
+
var w = { prod: { SignerApiRoot: "https://prod.signer.cubist.dev" }, gamma: { SignerApiRoot: "https://gamma.signer.cubist.dev" } };
|
|
8
|
+
var C = L("CUBE_SIGNER_ORG_ID");
|
|
9
|
+
var v = getEnv("RELAY_ORIGIN");
|
|
10
|
+
function L(e) {
|
|
11
|
+
return getEnv(e) || "";
|
|
12
|
+
}
|
|
13
|
+
var f = ({ url: e, name: g, width: r, height: t }) => {
|
|
14
|
+
let i = (window.innerHeight - (t || 400)) / 2 + window.screenY, a = (window.innerWidth - (r || 400)) / 2 + window.screenX;
|
|
15
|
+
try {
|
|
16
|
+
let s = window.open(e, g, `dialog=yes,top=${i}px,left=${a},width=${r !== void 0 ? r : 400}px,height=${t !== void 0 ? t : 600}px`);
|
|
17
|
+
return s || null;
|
|
18
|
+
} catch (s) {
|
|
19
|
+
return console.error("Failed to open window:", s), null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var R = (e) => /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(e);
|
|
23
|
+
function $(e) {
|
|
24
|
+
if (e in w) return w[e].SignerApiRoot;
|
|
25
|
+
if (/^https?:\/\//.test(e)) return e.replace(/\/$/, "");
|
|
26
|
+
throw new Error(`Unsupported CubeSigner env: ${e}`);
|
|
27
|
+
}
|
|
28
|
+
var O = async (e, g, r) => {
|
|
29
|
+
let t = await fetch(`${$(g)}/v0/org/${encodeURIComponent(r)}/oidc/email-otp`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ email: e }) });
|
|
30
|
+
if (!t.ok) {
|
|
31
|
+
let a = await t.text().catch(() => "");
|
|
32
|
+
throw new Error(a ? `Email login failed (${t.status}): ${a}` : `Email login failed (${t.status})`);
|
|
33
|
+
}
|
|
34
|
+
let i = await t.json();
|
|
35
|
+
if (!i.partial_token) throw new Error("Email login response missing partial_token");
|
|
36
|
+
return i.partial_token;
|
|
37
|
+
};
|
|
38
|
+
var Y = ({ stage: e, xClientId: g, googleClientId: r }) => {
|
|
39
|
+
let t = v;
|
|
40
|
+
if (window.location.hostname === "localhost" && (t = window.location.origin), !t) throw new Error("Invalid stage");
|
|
41
|
+
let i = `${t}/relay/x`, a = `${t}/relay/google`, s = S[e], E = C;
|
|
42
|
+
if (!E) throw new Error("Invalid cube stage");
|
|
43
|
+
let y = (o, l = 12e4) => new Promise((c, n) => {
|
|
44
|
+
if (!o) {
|
|
45
|
+
n(new Error("Failed to open popup"));
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
let m = setTimeout(() => {
|
|
49
|
+
o.close(), n(new Error("Login timeout"));
|
|
50
|
+
}, l), d = async (p) => {
|
|
51
|
+
if (p.origin !== t || p.data.action !== "login") return;
|
|
52
|
+
let { data: I } = p.data;
|
|
53
|
+
try {
|
|
54
|
+
let { oidcToken: u = "", error: h } = I || {};
|
|
55
|
+
if (h) {
|
|
56
|
+
clearTimeout(m), window.removeEventListener("message", d), o.close(), n(new Error(String(h)));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
u && (clearTimeout(m), window.removeEventListener("message", d), o.close(), c(u));
|
|
60
|
+
} catch (u) {
|
|
61
|
+
clearTimeout(m), window.removeEventListener("message", d), o.close(), n(u);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
window.addEventListener("message", d);
|
|
65
|
+
let T = setInterval(() => {
|
|
66
|
+
o.closed && (clearTimeout(m), clearInterval(T), window.removeEventListener("message", d), n(new Error("Login cancelled by user")));
|
|
67
|
+
}, 400);
|
|
68
|
+
});
|
|
69
|
+
return { loginByGoogle: async () => {
|
|
70
|
+
let l = { target: window.location.origin, stage: e, eventId: Date.now().toString(), action: "login", clientId: r }, c = `${a}?${new URLSearchParams(l).toString()}`, n = f({ url: c, name: "Google login" });
|
|
71
|
+
return await y(n);
|
|
72
|
+
}, loginByX: async () => {
|
|
73
|
+
let l = { target: window.location.origin, stage: e, eventId: Date.now().toString(), action: "login", clientId: g }, c = `${i}?${new URLSearchParams(l).toString()}`, n = f({ url: c, name: "X login" });
|
|
74
|
+
return await y(n);
|
|
75
|
+
}, loginByEmail: async (o) => {
|
|
76
|
+
if (!R(o)) throw new Error("Invalid email");
|
|
77
|
+
return { partialOidcToken: await O(o, s, E), lifeTime: x };
|
|
78
|
+
} };
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { w as CubeEnvs, C as CubeOrgId, S as CubeStages, x as EmailCodeLifeTime, Y as OidcAuth, _ as RelayMessageTypes, v as RelayOrigin, O as emailLogin, L as getPredicateCubeRegisterPath };
|