@1money/protocol-ts-sdk 1.0.14
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/.claude/settings.local.json +14 -0
- package/CLAUDE.md +77 -0
- package/README.md +600 -0
- package/es/api/accounts/index.d.ts +20 -0
- package/es/api/accounts/types.d.ts +9 -0
- package/es/api/chain/index.d.ts +12 -0
- package/es/api/chain/types.d.ts +3 -0
- package/es/api/checkpoints/index.d.ts +26 -0
- package/es/api/checkpoints/types.d.ts +33 -0
- package/es/api/constants.d.ts +9 -0
- package/es/api/index.d.ts +31 -0
- package/es/api/index.js +593 -0
- package/es/api/state/index.d.ts +12 -0
- package/es/api/state/types.d.ts +7 -0
- package/es/api/tokens/index.d.ts +62 -0
- package/es/api/tokens/types.d.ts +130 -0
- package/es/api/transactions/index.d.ts +35 -0
- package/es/api/transactions/types.d.ts +25 -0
- package/es/api/types.d.ts +18 -0
- package/es/client/core.d.ts +109 -0
- package/es/client/index.d.ts +21 -0
- package/es/client/index.js +373 -0
- package/es/index.d.ts +20 -0
- package/es/index.js +1490 -0
- package/es/utils/address.d.ts +15 -0
- package/es/utils/index.d.ts +6 -0
- package/es/utils/index.js +841 -0
- package/es/utils/interface.d.ts +7 -0
- package/es/utils/safePromise.d.ts +4 -0
- package/es/utils/sign.d.ts +15 -0
- package/es/utils/txHash.d.ts +2 -0
- package/es/utils/typeof.d.ts +2 -0
- package/lib/api/accounts/index.d.ts +20 -0
- package/lib/api/accounts/types.d.ts +9 -0
- package/lib/api/chain/index.d.ts +12 -0
- package/lib/api/chain/types.d.ts +3 -0
- package/lib/api/checkpoints/index.d.ts +26 -0
- package/lib/api/checkpoints/types.d.ts +33 -0
- package/lib/api/constants.d.ts +9 -0
- package/lib/api/index.d.ts +31 -0
- package/lib/api/index.js +692 -0
- package/lib/api/state/index.d.ts +12 -0
- package/lib/api/state/types.d.ts +7 -0
- package/lib/api/tokens/index.d.ts +62 -0
- package/lib/api/tokens/types.d.ts +130 -0
- package/lib/api/transactions/index.d.ts +35 -0
- package/lib/api/transactions/types.d.ts +25 -0
- package/lib/api/types.d.ts +18 -0
- package/lib/client/core.d.ts +109 -0
- package/lib/client/index.d.ts +21 -0
- package/lib/client/index.js +434 -0
- package/lib/index.d.ts +20 -0
- package/lib/index.js +1591 -0
- package/lib/utils/address.d.ts +15 -0
- package/lib/utils/index.d.ts +6 -0
- package/lib/utils/index.js +937 -0
- package/lib/utils/interface.d.ts +7 -0
- package/lib/utils/safePromise.d.ts +4 -0
- package/lib/utils/sign.d.ts +15 -0
- package/lib/utils/txHash.d.ts +2 -0
- package/lib/utils/typeof.d.ts +2 -0
- package/package.json +111 -0
- package/public/favicon.ico +0 -0
- package/public/logo.png +0 -0
- package/umd/1money-protocol-ts-sdk.min.js +2 -0
package/es/api/index.js
ADDED
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
import axios$1 from'axios';import'viem';import'@ethereumjs/rlp';function _typeof(ele) {
|
|
2
|
+
if (typeof ele !== 'object')
|
|
3
|
+
return (typeof ele).toLowerCase();
|
|
4
|
+
const typeStr = Object.prototype.toString.call(ele);
|
|
5
|
+
return typeStr.slice(8, typeStr.length - 1).toLowerCase();
|
|
6
|
+
}class ResponsePromise {
|
|
7
|
+
_success;
|
|
8
|
+
_failure;
|
|
9
|
+
_error;
|
|
10
|
+
_login;
|
|
11
|
+
_timeout;
|
|
12
|
+
_rest;
|
|
13
|
+
_resolve;
|
|
14
|
+
_reject;
|
|
15
|
+
promiseWrapper;
|
|
16
|
+
_restScope;
|
|
17
|
+
constructor() {
|
|
18
|
+
this.promiseWrapper = new Promise((resolve, reject) => {
|
|
19
|
+
this._resolve = resolve;
|
|
20
|
+
this._reject = reject;
|
|
21
|
+
});
|
|
22
|
+
this._restScope = ['success', 'failure', 'error', 'login', 'timeout'];
|
|
23
|
+
for (let i = 0; i < this._restScope.length; i++) {
|
|
24
|
+
const method = this._restScope[i];
|
|
25
|
+
if (!method)
|
|
26
|
+
continue;
|
|
27
|
+
this.promiseWrapper[method] = _callback => {
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
if (typeof _callback === 'function')
|
|
30
|
+
this[`_${method}`] = _callback;
|
|
31
|
+
const wrapper = this.promiseWrapper;
|
|
32
|
+
delete wrapper[method];
|
|
33
|
+
const methods = this._restScope.slice();
|
|
34
|
+
methods.splice(methods.indexOf(method), 1);
|
|
35
|
+
if (methods.every(_m => !!_m && !wrapper[_m]))
|
|
36
|
+
delete wrapper.rest;
|
|
37
|
+
return wrapper;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
this.promiseWrapper.rest = (onRest, scope) => {
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
if (typeof onRest === 'function')
|
|
43
|
+
this._rest = onRest;
|
|
44
|
+
const wrapper = this.promiseWrapper;
|
|
45
|
+
delete wrapper.rest;
|
|
46
|
+
this._restScope = scope || this._restScope;
|
|
47
|
+
// @ts-ignore
|
|
48
|
+
if (this._restScope.length === 0) {
|
|
49
|
+
console.warn('[1Money client]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
let deletedCounter = 0;
|
|
53
|
+
this._restScope.forEach(method => {
|
|
54
|
+
if (!method)
|
|
55
|
+
return;
|
|
56
|
+
if (wrapper[method]) {
|
|
57
|
+
delete wrapper[method];
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
deletedCounter++;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (deletedCounter === this._restScope.length) {
|
|
64
|
+
console.warn(`[1Money client]: The "${this._restScope.join(', ')}" had been called and the "rest" will never be triggered!`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return wrapper;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
class Request {
|
|
72
|
+
_config;
|
|
73
|
+
axios;
|
|
74
|
+
constructor(config) {
|
|
75
|
+
this._config = config || {};
|
|
76
|
+
this.axios = axios$1;
|
|
77
|
+
this.parseError = this.parseError.bind(this);
|
|
78
|
+
this.setting = this.setting.bind(this);
|
|
79
|
+
this.request = this.request.bind(this);
|
|
80
|
+
}
|
|
81
|
+
parseError(err) {
|
|
82
|
+
if (typeof err === 'string')
|
|
83
|
+
err = new Error(err);
|
|
84
|
+
// Ensure we have a valid error object
|
|
85
|
+
if (!err || (_typeof(err) !== 'object' && _typeof(err) !== 'error')) {
|
|
86
|
+
err = new Error('Unknown error occurred');
|
|
87
|
+
}
|
|
88
|
+
const name = err?.name ?? 'Error';
|
|
89
|
+
const message = err?.message ?? err?.toString?.() ?? 'Unknown error';
|
|
90
|
+
const stack = err?.stack ?? '';
|
|
91
|
+
const status = err?.response?.status ?? 500;
|
|
92
|
+
const data = err?.response?.data ?? undefined;
|
|
93
|
+
// Validate status code
|
|
94
|
+
if (typeof status !== 'number' || status < 100 || status > 599) {
|
|
95
|
+
return {
|
|
96
|
+
name: 'InvalidStatusError',
|
|
97
|
+
message: 'Invalid HTTP status code',
|
|
98
|
+
stack,
|
|
99
|
+
status: 500,
|
|
100
|
+
data
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
name,
|
|
105
|
+
message,
|
|
106
|
+
stack,
|
|
107
|
+
status,
|
|
108
|
+
data
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
setting(config) {
|
|
112
|
+
if (!config)
|
|
113
|
+
return console.warn('[1Money client]: setting method required correct parameters!');
|
|
114
|
+
this._config = { ...this._config, ...config };
|
|
115
|
+
}
|
|
116
|
+
request(options) {
|
|
117
|
+
// Set default security headers
|
|
118
|
+
options.withCredentials = typeof options.withCredentials === 'boolean' ? options.withCredentials : true;
|
|
119
|
+
options.headers = options.headers || {};
|
|
120
|
+
options.headers['Accept'] = options.headers['Accept'] || '*/*';
|
|
121
|
+
options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
|
|
122
|
+
options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
|
|
123
|
+
const { onSuccess: initOnSuccess, onFailure: initOnFailure, onLogin: initOnLogin, onError: initOnError, onTimeout: initOnTimeout, isSuccess: initIsSuccess, isLogin: initIsLogin, timeout: initTimeout, } = this._config;
|
|
124
|
+
const { onSuccess, onFailure, onLogin, onError, onTimeout, isSuccess, isLogin, timeout, } = options;
|
|
125
|
+
const rules = {
|
|
126
|
+
success: isSuccess ?? initIsSuccess,
|
|
127
|
+
login: isLogin ?? initIsLogin,
|
|
128
|
+
};
|
|
129
|
+
const ResPromise = new ResponsePromise();
|
|
130
|
+
Promise.resolve().then(() => {
|
|
131
|
+
const callbacks = {
|
|
132
|
+
success: ResPromise._success ??
|
|
133
|
+
(~ResPromise._restScope.indexOf('success') ? ResPromise._rest : undefined) ??
|
|
134
|
+
onSuccess ??
|
|
135
|
+
initOnSuccess ??
|
|
136
|
+
((r, h) => r),
|
|
137
|
+
failure: ResPromise._failure ??
|
|
138
|
+
(~ResPromise._restScope.indexOf('failure') ? ResPromise._rest : undefined) ??
|
|
139
|
+
onFailure ??
|
|
140
|
+
initOnFailure ??
|
|
141
|
+
((v, h) => v),
|
|
142
|
+
error: ResPromise._error ??
|
|
143
|
+
(~ResPromise._restScope.indexOf('error') ? ResPromise._rest : undefined) ??
|
|
144
|
+
onError ??
|
|
145
|
+
initOnError ??
|
|
146
|
+
((v, h) => v),
|
|
147
|
+
login: ResPromise._login ??
|
|
148
|
+
(~ResPromise._restScope.indexOf('login') ? ResPromise._rest : undefined) ??
|
|
149
|
+
onLogin ??
|
|
150
|
+
initOnLogin ??
|
|
151
|
+
((v, h) => v),
|
|
152
|
+
timeout: ResPromise._timeout ??
|
|
153
|
+
(~ResPromise._restScope.indexOf('timeout') ? ResPromise._rest : undefined) ??
|
|
154
|
+
onTimeout ??
|
|
155
|
+
initOnTimeout ??
|
|
156
|
+
((v, h) => v),
|
|
157
|
+
};
|
|
158
|
+
const existedHandler = {
|
|
159
|
+
success: !!(ResPromise._success ||
|
|
160
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('success')) ||
|
|
161
|
+
onSuccess ||
|
|
162
|
+
initOnSuccess),
|
|
163
|
+
failure: !!(ResPromise._failure ||
|
|
164
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('failure')) ||
|
|
165
|
+
onFailure ||
|
|
166
|
+
initOnFailure),
|
|
167
|
+
login: !!(ResPromise._login ||
|
|
168
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('login')) ||
|
|
169
|
+
onLogin ||
|
|
170
|
+
initOnLogin),
|
|
171
|
+
error: !!(ResPromise._error ||
|
|
172
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('error')) ||
|
|
173
|
+
onError ||
|
|
174
|
+
initOnError),
|
|
175
|
+
timeout: !!(ResPromise._timeout ||
|
|
176
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('timeout')) ||
|
|
177
|
+
onTimeout ||
|
|
178
|
+
initOnTimeout),
|
|
179
|
+
};
|
|
180
|
+
const existedChainHandler = {
|
|
181
|
+
success: !!(ResPromise._success ||
|
|
182
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('success'))),
|
|
183
|
+
failure: !!(ResPromise._failure ||
|
|
184
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('failure'))),
|
|
185
|
+
login: !!(ResPromise._login ||
|
|
186
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('login'))),
|
|
187
|
+
error: !!(ResPromise._error ||
|
|
188
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('error'))),
|
|
189
|
+
timeout: !!(ResPromise._timeout ||
|
|
190
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('timeout'))),
|
|
191
|
+
};
|
|
192
|
+
const errorHandler = async (e, headers) => {
|
|
193
|
+
try {
|
|
194
|
+
let err = this.parseError(e);
|
|
195
|
+
const result = await Promise.resolve(callbacks.error(err, headers));
|
|
196
|
+
if (existedChainHandler.error)
|
|
197
|
+
err = result;
|
|
198
|
+
existedHandler.error ? ResPromise._resolve(err) : ResPromise._reject(err);
|
|
199
|
+
}
|
|
200
|
+
catch (_e) {
|
|
201
|
+
ResPromise._reject(this.parseError(_e));
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
let timer = null;
|
|
205
|
+
let isTimeout = false;
|
|
206
|
+
const _timeout = timeout ?? initTimeout;
|
|
207
|
+
// Cleanup function for timeout
|
|
208
|
+
const cleanup = () => {
|
|
209
|
+
if (timer !== null) {
|
|
210
|
+
clearTimeout(timer);
|
|
211
|
+
timer = null;
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
if (_timeout) {
|
|
215
|
+
timer = setTimeout(async () => {
|
|
216
|
+
try {
|
|
217
|
+
isTimeout = true;
|
|
218
|
+
cleanup();
|
|
219
|
+
let err = this.parseError('timeout');
|
|
220
|
+
// @ts-ignore
|
|
221
|
+
const res = await Promise.resolve(callbacks.timeout(err, options.headers ?? {}));
|
|
222
|
+
if (existedChainHandler.timeout)
|
|
223
|
+
err = res;
|
|
224
|
+
existedHandler.timeout ? ResPromise._resolve(err) : ResPromise._reject(err);
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
errorHandler(e, options.headers ?? {});
|
|
228
|
+
}
|
|
229
|
+
}, _timeout);
|
|
230
|
+
}
|
|
231
|
+
this.axios(options).then(async (response) => {
|
|
232
|
+
if (isTimeout)
|
|
233
|
+
return;
|
|
234
|
+
cleanup();
|
|
235
|
+
const { status, data, headers } = response;
|
|
236
|
+
try {
|
|
237
|
+
const doSuccess = rules.success?.(data, status, headers);
|
|
238
|
+
const doLogin = rules.login?.(data, status, headers);
|
|
239
|
+
let res = data;
|
|
240
|
+
if (doLogin) {
|
|
241
|
+
const result = await Promise.resolve(callbacks.login(data, headers));
|
|
242
|
+
if (existedChainHandler.login)
|
|
243
|
+
res = result;
|
|
244
|
+
}
|
|
245
|
+
else if (doSuccess) {
|
|
246
|
+
const result = await Promise.resolve(callbacks.success(data, headers));
|
|
247
|
+
if (existedChainHandler.success)
|
|
248
|
+
res = result;
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
const result = await Promise.resolve(callbacks.failure(data, headers));
|
|
252
|
+
if (existedChainHandler.failure)
|
|
253
|
+
res = result;
|
|
254
|
+
}
|
|
255
|
+
ResPromise._resolve(res);
|
|
256
|
+
}
|
|
257
|
+
catch (e) {
|
|
258
|
+
errorHandler(e, headers);
|
|
259
|
+
}
|
|
260
|
+
}).catch(async (err) => {
|
|
261
|
+
if (isTimeout)
|
|
262
|
+
return;
|
|
263
|
+
cleanup();
|
|
264
|
+
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})};`);
|
|
265
|
+
const status = err.response?.status ?? 500;
|
|
266
|
+
const data = err.response?.data ?? {};
|
|
267
|
+
const headers = err.response?.headers ?? {};
|
|
268
|
+
try {
|
|
269
|
+
let res = data;
|
|
270
|
+
const doLogin = rules.login?.(data, status, headers);
|
|
271
|
+
if (doLogin) {
|
|
272
|
+
res = await Promise.resolve(callbacks.login(res, headers));
|
|
273
|
+
ResPromise._resolve(res);
|
|
274
|
+
}
|
|
275
|
+
else {
|
|
276
|
+
errorHandler(err, headers);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
catch (e) {
|
|
280
|
+
errorHandler(e, headers);
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
return ResPromise.promiseWrapper;
|
|
285
|
+
}
|
|
286
|
+
}const { request, setting, axios } = new Request({
|
|
287
|
+
isSuccess: (res, status) => status === 200 && res.code == 0,
|
|
288
|
+
isLogin: (res, status) => status === 401 || res.code == 401,
|
|
289
|
+
timeout: 10000
|
|
290
|
+
});
|
|
291
|
+
function get(url, options) {
|
|
292
|
+
return request({
|
|
293
|
+
...options,
|
|
294
|
+
method: 'get',
|
|
295
|
+
url
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function post(url, data, options) {
|
|
299
|
+
return request({
|
|
300
|
+
...options,
|
|
301
|
+
method: 'post',
|
|
302
|
+
url,
|
|
303
|
+
data,
|
|
304
|
+
headers: {
|
|
305
|
+
'Content-Type': 'application/json',
|
|
306
|
+
...options?.headers,
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
}
|
|
310
|
+
function setInitConfig(config) {
|
|
311
|
+
const { baseURL, ...rest } = config;
|
|
312
|
+
axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
313
|
+
setting(rest);
|
|
314
|
+
}// Base URLs for the API
|
|
315
|
+
const TESTNET_API_URL = 'https://api.testnet.1money.network';
|
|
316
|
+
const MAINNET_API_URL = 'https://api.1money.network';
|
|
317
|
+
const LOCAL_API_URL = 'http://localhost:18555';
|
|
318
|
+
// API version
|
|
319
|
+
const API_VERSION = 'v1';const API_PREFIX$5 = `/${API_VERSION}/accounts`;
|
|
320
|
+
/**
|
|
321
|
+
* Accounts API methods
|
|
322
|
+
*/
|
|
323
|
+
const accountsApi = {
|
|
324
|
+
/**
|
|
325
|
+
* Get account nonce
|
|
326
|
+
* @param address Address of the account to lookup nonce for
|
|
327
|
+
* @returns Promise with account info response
|
|
328
|
+
*/
|
|
329
|
+
getNonce: (address) => {
|
|
330
|
+
return get(`${API_PREFIX$5}/nonce?address=${address}`, { withCredentials: false });
|
|
331
|
+
},
|
|
332
|
+
/**
|
|
333
|
+
* Get associated token account
|
|
334
|
+
* @param address Address of the account to lookup associated token account for
|
|
335
|
+
* @param token Token address to lookup associated token account for
|
|
336
|
+
* @returns Promise with associated token account response
|
|
337
|
+
*/
|
|
338
|
+
getTokenAccount: (address, token) => {
|
|
339
|
+
return get(`${API_PREFIX$5}/token_account?address=${address}&token=${token}`, { withCredentials: false });
|
|
340
|
+
}
|
|
341
|
+
};const API_PREFIX$4 = `/${API_VERSION}/checkpoints`;
|
|
342
|
+
/**
|
|
343
|
+
* Checkpoint API methods
|
|
344
|
+
*/
|
|
345
|
+
const checkpointsApi = {
|
|
346
|
+
/**
|
|
347
|
+
* Get the current checkpoint number
|
|
348
|
+
* @returns Promise with checkpoint number response
|
|
349
|
+
*/
|
|
350
|
+
getNumber: () => {
|
|
351
|
+
return get(`${API_PREFIX$4}/number`, { withCredentials: false });
|
|
352
|
+
},
|
|
353
|
+
/**
|
|
354
|
+
* Get checkpoint by hash
|
|
355
|
+
* @param hash Hash of the checkpoint to lookup
|
|
356
|
+
* @param full Whether to include full transaction details
|
|
357
|
+
* @returns Promise with checkpoint response
|
|
358
|
+
*/
|
|
359
|
+
getByHash: (hash, full = false) => {
|
|
360
|
+
return get(`${API_PREFIX$4}/by_hash?hash=${hash}&full=${full}`, { withCredentials: false });
|
|
361
|
+
},
|
|
362
|
+
/**
|
|
363
|
+
* Get checkpoint by number
|
|
364
|
+
* @param number Number of the checkpoint to lookup
|
|
365
|
+
* @param full Whether to include full transaction details
|
|
366
|
+
* @returns Promise with checkpoint response
|
|
367
|
+
*/
|
|
368
|
+
getByNumber: (number, full = false) => {
|
|
369
|
+
return get(`${API_PREFIX$4}/by_number?number=${number}&full=${full}`, { withCredentials: false });
|
|
370
|
+
}
|
|
371
|
+
};const API_PREFIX$3 = `/${API_VERSION}/tokens`;
|
|
372
|
+
/**
|
|
373
|
+
* Tokens API methods
|
|
374
|
+
*/
|
|
375
|
+
const tokensApi = {
|
|
376
|
+
/**
|
|
377
|
+
* Get token metadata
|
|
378
|
+
* @param token Token address to lookup metadata for
|
|
379
|
+
* @returns Promise with token metadata response
|
|
380
|
+
*/
|
|
381
|
+
getTokenMetadata: (token) => {
|
|
382
|
+
return get(`${API_PREFIX$3}/token_metadata?token=${token}`, { withCredentials: false });
|
|
383
|
+
},
|
|
384
|
+
/**
|
|
385
|
+
* Manage token blacklist
|
|
386
|
+
* @param payload Token blacklist request payload
|
|
387
|
+
* @returns Promise with transaction hash response
|
|
388
|
+
*/
|
|
389
|
+
manageBlacklist: (payload) => {
|
|
390
|
+
return post(`${API_PREFIX$3}/manage_blacklist`, payload, { withCredentials: false });
|
|
391
|
+
},
|
|
392
|
+
/**
|
|
393
|
+
* Manage token whitelist
|
|
394
|
+
* @param payload Token whitelist request payload
|
|
395
|
+
* @returns Promise with transaction hash response
|
|
396
|
+
*/
|
|
397
|
+
manageWhitelist: (payload) => {
|
|
398
|
+
return post(`${API_PREFIX$3}/manage_whitelist`, payload, { withCredentials: false });
|
|
399
|
+
},
|
|
400
|
+
/**
|
|
401
|
+
* Burn tokens
|
|
402
|
+
* @param payload Token burn request payload
|
|
403
|
+
* @returns Promise with transaction hash response
|
|
404
|
+
*/
|
|
405
|
+
burnToken: (payload) => {
|
|
406
|
+
return post(`${API_PREFIX$3}/burn`, payload, { withCredentials: false });
|
|
407
|
+
},
|
|
408
|
+
/**
|
|
409
|
+
* Grant or revoke token authority
|
|
410
|
+
* @param payload Token authority request payload
|
|
411
|
+
* @returns Promise with transaction hash response
|
|
412
|
+
*/
|
|
413
|
+
grantAuthority: (payload) => {
|
|
414
|
+
return post(`${API_PREFIX$3}/grant_authority`, payload, { withCredentials: false });
|
|
415
|
+
},
|
|
416
|
+
/**
|
|
417
|
+
* Issue new token
|
|
418
|
+
* @param payload Token issue request payload
|
|
419
|
+
* @returns Promise with transaction hash and token address response
|
|
420
|
+
*/
|
|
421
|
+
issueToken: (payload) => {
|
|
422
|
+
return post(`${API_PREFIX$3}/issue`, payload, { withCredentials: false });
|
|
423
|
+
},
|
|
424
|
+
/**
|
|
425
|
+
* Mint tokens
|
|
426
|
+
* @param payload Token mint request payload
|
|
427
|
+
* @returns Promise with transaction hash response
|
|
428
|
+
*/
|
|
429
|
+
mintToken: (payload) => {
|
|
430
|
+
return post(`${API_PREFIX$3}/mint`, payload, { withCredentials: false });
|
|
431
|
+
},
|
|
432
|
+
/**
|
|
433
|
+
* Pause or unpause token
|
|
434
|
+
* @param payload Token pause request payload
|
|
435
|
+
* @returns Promise with transaction hash response
|
|
436
|
+
*/
|
|
437
|
+
pauseToken: (payload) => {
|
|
438
|
+
return post(`${API_PREFIX$3}/pause`, payload, { withCredentials: false });
|
|
439
|
+
},
|
|
440
|
+
/**
|
|
441
|
+
* Update token metadata
|
|
442
|
+
* @param payload Token metadata request payload
|
|
443
|
+
* @returns Promise with transaction hash response
|
|
444
|
+
*/
|
|
445
|
+
updateMetadata: (payload) => {
|
|
446
|
+
return post(`${API_PREFIX$3}/update_metadata`, payload, { withCredentials: false });
|
|
447
|
+
}
|
|
448
|
+
};const API_PREFIX$2 = `/${API_VERSION}/transactions`;
|
|
449
|
+
/**
|
|
450
|
+
* Transactions API methods
|
|
451
|
+
*/
|
|
452
|
+
const transactionsApi = {
|
|
453
|
+
/**
|
|
454
|
+
* Get transaction by hash
|
|
455
|
+
* @param hash Hash of the transaction to lookup
|
|
456
|
+
* @returns Promise with transaction response
|
|
457
|
+
*/
|
|
458
|
+
getByHash: (hash) => {
|
|
459
|
+
return get(`${API_PREFIX$2}/by_hash?hash=${hash}`, { withCredentials: false });
|
|
460
|
+
},
|
|
461
|
+
/**
|
|
462
|
+
* Get transaction receipt by hash
|
|
463
|
+
* @param hash Hash of the transaction to lookup receipt for
|
|
464
|
+
* @returns Promise with transaction receipt response
|
|
465
|
+
*/
|
|
466
|
+
getReceiptByHash: (hash) => {
|
|
467
|
+
return get(`${API_PREFIX$2}/receipt/by_hash?hash=${hash}`, { withCredentials: false });
|
|
468
|
+
},
|
|
469
|
+
/**
|
|
470
|
+
* Estimate transaction fee
|
|
471
|
+
* @param from Address of the transaction author
|
|
472
|
+
* @param value Value of the transaction
|
|
473
|
+
* @param token Optional token address
|
|
474
|
+
* @returns Promise with fee estimate response
|
|
475
|
+
*/
|
|
476
|
+
estimateFee: (from, value, token) => {
|
|
477
|
+
let url = `${API_PREFIX$2}/estimate_fee?from=${from}&value=${value}`;
|
|
478
|
+
if (token) {
|
|
479
|
+
url += `&token=${token}`;
|
|
480
|
+
}
|
|
481
|
+
return get(url, { withCredentials: false });
|
|
482
|
+
},
|
|
483
|
+
/**
|
|
484
|
+
* Submit payment transaction
|
|
485
|
+
* @param payload Payment transaction payload
|
|
486
|
+
* @returns Promise with transaction hash response
|
|
487
|
+
*/
|
|
488
|
+
payment: (payload) => {
|
|
489
|
+
return post(`${API_PREFIX$2}/payment`, payload, { withCredentials: false });
|
|
490
|
+
}
|
|
491
|
+
};const API_PREFIX$1 = `/${API_VERSION}/chains`;
|
|
492
|
+
/**
|
|
493
|
+
* Checkpoint API methods
|
|
494
|
+
*/
|
|
495
|
+
const chainApi = {
|
|
496
|
+
/**
|
|
497
|
+
* Get the current chain id
|
|
498
|
+
* @returns Promise with chain id response
|
|
499
|
+
*/
|
|
500
|
+
getChainId: () => {
|
|
501
|
+
return get(`${API_PREFIX$1}/chain_id`, { withCredentials: false });
|
|
502
|
+
},
|
|
503
|
+
};const API_PREFIX = `/${API_VERSION}/states`;
|
|
504
|
+
/**
|
|
505
|
+
* State API methods
|
|
506
|
+
*/
|
|
507
|
+
const stateApi = {
|
|
508
|
+
/**
|
|
509
|
+
* Get latest epoch checkpoint
|
|
510
|
+
* @returns Promise with latest epoch checkpoint response
|
|
511
|
+
*/
|
|
512
|
+
getLatestEpochCheckpoint: () => {
|
|
513
|
+
return get(`${API_PREFIX}/latest_epoch_checkpoint`, { withCredentials: false });
|
|
514
|
+
}
|
|
515
|
+
};// Authority types
|
|
516
|
+
var AuthorityType;
|
|
517
|
+
(function (AuthorityType) {
|
|
518
|
+
AuthorityType["MasterMint"] = "MasterMint";
|
|
519
|
+
AuthorityType["MintBurnTokens"] = "MintBurnTokens";
|
|
520
|
+
AuthorityType["Pause"] = "Pause";
|
|
521
|
+
AuthorityType["ManageList"] = "ManageList";
|
|
522
|
+
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
523
|
+
})(AuthorityType || (AuthorityType = {}));
|
|
524
|
+
var AuthorityAction;
|
|
525
|
+
(function (AuthorityAction) {
|
|
526
|
+
AuthorityAction["Grant"] = "Grant";
|
|
527
|
+
AuthorityAction["Revoke"] = "Revoke";
|
|
528
|
+
})(AuthorityAction || (AuthorityAction = {}));
|
|
529
|
+
var ManageListAction;
|
|
530
|
+
(function (ManageListAction) {
|
|
531
|
+
ManageListAction["Add"] = "Add";
|
|
532
|
+
ManageListAction["Remove"] = "Remove";
|
|
533
|
+
})(ManageListAction || (ManageListAction = {}));
|
|
534
|
+
var PauseAction;
|
|
535
|
+
(function (PauseAction) {
|
|
536
|
+
PauseAction["Pause"] = "Pause";
|
|
537
|
+
PauseAction["Unpause"] = "Unpause";
|
|
538
|
+
})(PauseAction || (PauseAction = {}));/**
|
|
539
|
+
* API client for 1money network
|
|
540
|
+
* @param options Configuration options
|
|
541
|
+
* @param options.network Network to use (testnet, mainnet, local)
|
|
542
|
+
* @param options.timeout Request timeout in milliseconds
|
|
543
|
+
* @param options.chainId Custom chain ID (overrides the default for the selected network)
|
|
544
|
+
*/
|
|
545
|
+
function api(options) {
|
|
546
|
+
const network = options?.network || 'mainnet';
|
|
547
|
+
let baseURL = MAINNET_API_URL;
|
|
548
|
+
// Set the base URL based on the network
|
|
549
|
+
switch (network) {
|
|
550
|
+
case 'mainnet':
|
|
551
|
+
baseURL = MAINNET_API_URL;
|
|
552
|
+
break;
|
|
553
|
+
case 'testnet':
|
|
554
|
+
baseURL = TESTNET_API_URL;
|
|
555
|
+
break;
|
|
556
|
+
case 'local':
|
|
557
|
+
baseURL = LOCAL_API_URL;
|
|
558
|
+
break;
|
|
559
|
+
}
|
|
560
|
+
// Initialize API configuration
|
|
561
|
+
setInitConfig({
|
|
562
|
+
baseURL,
|
|
563
|
+
// Treat status code 200 as success
|
|
564
|
+
isSuccess: (_res, status) => status === 200,
|
|
565
|
+
timeout: options?.timeout || 10000
|
|
566
|
+
});
|
|
567
|
+
return {
|
|
568
|
+
/**
|
|
569
|
+
* Accounts API methods
|
|
570
|
+
*/
|
|
571
|
+
accounts: accountsApi,
|
|
572
|
+
/**
|
|
573
|
+
* Checkpoint API methods
|
|
574
|
+
*/
|
|
575
|
+
checkpoints: checkpointsApi,
|
|
576
|
+
/**
|
|
577
|
+
* Tokens API methods
|
|
578
|
+
*/
|
|
579
|
+
tokens: tokensApi,
|
|
580
|
+
/**
|
|
581
|
+
* Transactions API methods
|
|
582
|
+
*/
|
|
583
|
+
transactions: transactionsApi,
|
|
584
|
+
/**
|
|
585
|
+
* Chain API methods
|
|
586
|
+
*/
|
|
587
|
+
chain: chainApi,
|
|
588
|
+
/**
|
|
589
|
+
* State API methods
|
|
590
|
+
*/
|
|
591
|
+
state: stateApi,
|
|
592
|
+
};
|
|
593
|
+
}export{AuthorityAction,AuthorityType,ManageListAction,PauseAction,api,api as default};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { EpochCheckpointResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* State API methods
|
|
4
|
+
*/
|
|
5
|
+
export declare const stateApi: {
|
|
6
|
+
/**
|
|
7
|
+
* Get latest epoch checkpoint
|
|
8
|
+
* @returns Promise with latest epoch checkpoint response
|
|
9
|
+
*/
|
|
10
|
+
getLatestEpochCheckpoint: () => import("../../client/index.js").PromiseWrapper<"custom", EpochCheckpointResponse, EpochCheckpointResponse, EpochCheckpointResponse, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | EpochCheckpointResponse, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<EpochCheckpointResponse>;
|
|
11
|
+
};
|
|
12
|
+
export default stateApi;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { Hash, HashWithToken } from '../../api/types';
|
|
2
|
+
import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Tokens API methods
|
|
5
|
+
*/
|
|
6
|
+
export declare const tokensApi: {
|
|
7
|
+
/**
|
|
8
|
+
* Get token metadata
|
|
9
|
+
* @param token Token address to lookup metadata for
|
|
10
|
+
* @returns Promise with token metadata response
|
|
11
|
+
*/
|
|
12
|
+
getTokenMetadata: (token: string) => import("../../client/index.js").PromiseWrapper<"custom", MintInfo, MintInfo, MintInfo, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | MintInfo, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<MintInfo>;
|
|
13
|
+
/**
|
|
14
|
+
* Manage token blacklist
|
|
15
|
+
* @param payload Token blacklist request payload
|
|
16
|
+
* @returns Promise with transaction hash response
|
|
17
|
+
*/
|
|
18
|
+
manageBlacklist: (payload: TokenManageListPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
19
|
+
/**
|
|
20
|
+
* Manage token whitelist
|
|
21
|
+
* @param payload Token whitelist request payload
|
|
22
|
+
* @returns Promise with transaction hash response
|
|
23
|
+
*/
|
|
24
|
+
manageWhitelist: (payload: TokenManageListPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
25
|
+
/**
|
|
26
|
+
* Burn tokens
|
|
27
|
+
* @param payload Token burn request payload
|
|
28
|
+
* @returns Promise with transaction hash response
|
|
29
|
+
*/
|
|
30
|
+
burnToken: (payload: TokenBurnPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
31
|
+
/**
|
|
32
|
+
* Grant or revoke token authority
|
|
33
|
+
* @param payload Token authority request payload
|
|
34
|
+
* @returns Promise with transaction hash response
|
|
35
|
+
*/
|
|
36
|
+
grantAuthority: (payload: TokenAuthorityPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
37
|
+
/**
|
|
38
|
+
* Issue new token
|
|
39
|
+
* @param payload Token issue request payload
|
|
40
|
+
* @returns Promise with transaction hash and token address response
|
|
41
|
+
*/
|
|
42
|
+
issueToken: (payload: TokenIssuePayload) => import("../../client/index.js").PromiseWrapper<"custom", HashWithToken, HashWithToken, HashWithToken, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | HashWithToken, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<HashWithToken>;
|
|
43
|
+
/**
|
|
44
|
+
* Mint tokens
|
|
45
|
+
* @param payload Token mint request payload
|
|
46
|
+
* @returns Promise with transaction hash response
|
|
47
|
+
*/
|
|
48
|
+
mintToken: (payload: TokenMintPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
49
|
+
/**
|
|
50
|
+
* Pause or unpause token
|
|
51
|
+
* @param payload Token pause request payload
|
|
52
|
+
* @returns Promise with transaction hash response
|
|
53
|
+
*/
|
|
54
|
+
pauseToken: (payload: TokenPausePayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
55
|
+
/**
|
|
56
|
+
* Update token metadata
|
|
57
|
+
* @param payload Token metadata request payload
|
|
58
|
+
* @returns Promise with transaction hash response
|
|
59
|
+
*/
|
|
60
|
+
updateMetadata: (payload: TokenMetadataPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
61
|
+
};
|
|
62
|
+
export default tokensApi;
|