@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/lib/api/index.js
ADDED
|
@@ -0,0 +1,692 @@
|
|
|
1
|
+
'use strict';Object.defineProperty(exports,'__esModule',{value:true});var axios$1=require('axios');require('viem'),require('@ethereumjs/rlp');/******************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var __assign = function() {
|
|
19
|
+
__assign = Object.assign || function __assign(t) {
|
|
20
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
21
|
+
s = arguments[i];
|
|
22
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
23
|
+
}
|
|
24
|
+
return t;
|
|
25
|
+
};
|
|
26
|
+
return __assign.apply(this, arguments);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
function __rest(s, e) {
|
|
30
|
+
var t = {};
|
|
31
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
32
|
+
t[p] = s[p];
|
|
33
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
34
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
35
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
36
|
+
t[p[i]] = s[p[i]];
|
|
37
|
+
}
|
|
38
|
+
return t;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function __awaiter(thisArg, _arguments, P, generator) {
|
|
42
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
43
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
44
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
45
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
46
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
47
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function __generator(thisArg, body) {
|
|
52
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
53
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
54
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
55
|
+
function step(op) {
|
|
56
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
57
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
58
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
59
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
60
|
+
switch (op[0]) {
|
|
61
|
+
case 0: case 1: t = op; break;
|
|
62
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
63
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
64
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
65
|
+
default:
|
|
66
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
67
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
68
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
69
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
70
|
+
if (t[2]) _.ops.pop();
|
|
71
|
+
_.trys.pop(); continue;
|
|
72
|
+
}
|
|
73
|
+
op = body.call(thisArg, _);
|
|
74
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
75
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
80
|
+
var e = new Error(message);
|
|
81
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
82
|
+
};function _typeof(ele) {
|
|
83
|
+
if (typeof ele !== 'object')
|
|
84
|
+
return (typeof ele).toLowerCase();
|
|
85
|
+
var typeStr = Object.prototype.toString.call(ele);
|
|
86
|
+
return typeStr.slice(8, typeStr.length - 1).toLowerCase();
|
|
87
|
+
}var ResponsePromise = /** @class */ (function () {
|
|
88
|
+
function ResponsePromise() {
|
|
89
|
+
var _this = this;
|
|
90
|
+
this.promiseWrapper = new Promise(function (resolve, reject) {
|
|
91
|
+
_this._resolve = resolve;
|
|
92
|
+
_this._reject = reject;
|
|
93
|
+
});
|
|
94
|
+
this._restScope = ['success', 'failure', 'error', 'login', 'timeout'];
|
|
95
|
+
var _loop_1 = function (i) {
|
|
96
|
+
var method = this_1._restScope[i];
|
|
97
|
+
if (!method)
|
|
98
|
+
return "continue";
|
|
99
|
+
this_1.promiseWrapper[method] = function (_callback) {
|
|
100
|
+
// @ts-ignore
|
|
101
|
+
if (typeof _callback === 'function')
|
|
102
|
+
_this["_".concat(method)] = _callback;
|
|
103
|
+
var wrapper = _this.promiseWrapper;
|
|
104
|
+
delete wrapper[method];
|
|
105
|
+
var methods = _this._restScope.slice();
|
|
106
|
+
methods.splice(methods.indexOf(method), 1);
|
|
107
|
+
if (methods.every(function (_m) { return !!_m && !wrapper[_m]; }))
|
|
108
|
+
delete wrapper.rest;
|
|
109
|
+
return wrapper;
|
|
110
|
+
};
|
|
111
|
+
};
|
|
112
|
+
var this_1 = this;
|
|
113
|
+
for (var i = 0; i < this._restScope.length; i++) {
|
|
114
|
+
_loop_1(i);
|
|
115
|
+
}
|
|
116
|
+
this.promiseWrapper.rest = function (onRest, scope) {
|
|
117
|
+
// @ts-ignore
|
|
118
|
+
if (typeof onRest === 'function')
|
|
119
|
+
_this._rest = onRest;
|
|
120
|
+
var wrapper = _this.promiseWrapper;
|
|
121
|
+
delete wrapper.rest;
|
|
122
|
+
_this._restScope = scope || _this._restScope;
|
|
123
|
+
// @ts-ignore
|
|
124
|
+
if (_this._restScope.length === 0) {
|
|
125
|
+
console.warn('[1Money client]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
var deletedCounter_1 = 0;
|
|
129
|
+
_this._restScope.forEach(function (method) {
|
|
130
|
+
if (!method)
|
|
131
|
+
return;
|
|
132
|
+
if (wrapper[method]) {
|
|
133
|
+
delete wrapper[method];
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
deletedCounter_1++;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
if (deletedCounter_1 === _this._restScope.length) {
|
|
140
|
+
console.warn("[1Money client]: The \"".concat(_this._restScope.join(', '), "\" had been called and the \"rest\" will never be triggered!"));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return wrapper;
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return ResponsePromise;
|
|
147
|
+
}());
|
|
148
|
+
var Request = /** @class */ (function () {
|
|
149
|
+
function Request(config) {
|
|
150
|
+
this._config = config || {};
|
|
151
|
+
this.axios = axios$1;
|
|
152
|
+
this.parseError = this.parseError.bind(this);
|
|
153
|
+
this.setting = this.setting.bind(this);
|
|
154
|
+
this.request = this.request.bind(this);
|
|
155
|
+
}
|
|
156
|
+
Request.prototype.parseError = function (err) {
|
|
157
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k;
|
|
158
|
+
if (typeof err === 'string')
|
|
159
|
+
err = new Error(err);
|
|
160
|
+
// Ensure we have a valid error object
|
|
161
|
+
if (!err || (_typeof(err) !== 'object' && _typeof(err) !== 'error')) {
|
|
162
|
+
err = new Error('Unknown error occurred');
|
|
163
|
+
}
|
|
164
|
+
var name = (_a = err === null || err === void 0 ? void 0 : err.name) !== null && _a !== void 0 ? _a : 'Error';
|
|
165
|
+
var message = (_d = (_b = err === null || err === void 0 ? void 0 : err.message) !== null && _b !== void 0 ? _b : (_c = err === null || err === void 0 ? void 0 : err.toString) === null || _c === void 0 ? void 0 : _c.call(err)) !== null && _d !== void 0 ? _d : 'Unknown error';
|
|
166
|
+
var stack = (_f = err === null || err === void 0 ? void 0 : err.stack) !== null && _f !== void 0 ? _f : '';
|
|
167
|
+
var status = (_h = (_g = err === null || err === void 0 ? void 0 : err.response) === null || _g === void 0 ? void 0 : _g.status) !== null && _h !== void 0 ? _h : 500;
|
|
168
|
+
var data = (_k = (_j = err === null || err === void 0 ? void 0 : err.response) === null || _j === void 0 ? void 0 : _j.data) !== null && _k !== void 0 ? _k : undefined;
|
|
169
|
+
// Validate status code
|
|
170
|
+
if (typeof status !== 'number' || status < 100 || status > 599) {
|
|
171
|
+
return {
|
|
172
|
+
name: 'InvalidStatusError',
|
|
173
|
+
message: 'Invalid HTTP status code',
|
|
174
|
+
stack: stack,
|
|
175
|
+
status: 500,
|
|
176
|
+
data: data
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
name: name,
|
|
181
|
+
message: message,
|
|
182
|
+
stack: stack,
|
|
183
|
+
status: status,
|
|
184
|
+
data: data
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
Request.prototype.setting = function (config) {
|
|
188
|
+
if (!config)
|
|
189
|
+
return console.warn('[1Money client]: setting method required correct parameters!');
|
|
190
|
+
this._config = __assign(__assign({}, this._config), config);
|
|
191
|
+
};
|
|
192
|
+
Request.prototype.request = function (options) {
|
|
193
|
+
var _this = this;
|
|
194
|
+
// Set default security headers
|
|
195
|
+
options.withCredentials = typeof options.withCredentials === 'boolean' ? options.withCredentials : true;
|
|
196
|
+
options.headers = options.headers || {};
|
|
197
|
+
options.headers['Accept'] = options.headers['Accept'] || '*/*';
|
|
198
|
+
options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
|
|
199
|
+
options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
|
|
200
|
+
var _a = this._config, initOnSuccess = _a.onSuccess, initOnFailure = _a.onFailure, initOnLogin = _a.onLogin, initOnError = _a.onError, initOnTimeout = _a.onTimeout, initIsSuccess = _a.isSuccess, initIsLogin = _a.isLogin, initTimeout = _a.timeout;
|
|
201
|
+
var onSuccess = options.onSuccess, onFailure = options.onFailure, onLogin = options.onLogin, onError = options.onError, onTimeout = options.onTimeout, isSuccess = options.isSuccess, isLogin = options.isLogin, timeout = options.timeout;
|
|
202
|
+
var rules = {
|
|
203
|
+
success: isSuccess !== null && isSuccess !== void 0 ? isSuccess : initIsSuccess,
|
|
204
|
+
login: isLogin !== null && isLogin !== void 0 ? isLogin : initIsLogin,
|
|
205
|
+
};
|
|
206
|
+
var ResPromise = new ResponsePromise();
|
|
207
|
+
Promise.resolve().then(function () {
|
|
208
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
|
|
209
|
+
var callbacks = {
|
|
210
|
+
success: (_d = (_c = (_b = (_a = ResPromise._success) !== null && _a !== void 0 ? _a : (~ResPromise._restScope.indexOf('success') ? ResPromise._rest : undefined)) !== null && _b !== void 0 ? _b : onSuccess) !== null && _c !== void 0 ? _c : initOnSuccess) !== null && _d !== void 0 ? _d : (function (r, h) { return r; }),
|
|
211
|
+
failure: (_j = (_h = (_g = (_f = ResPromise._failure) !== null && _f !== void 0 ? _f : (~ResPromise._restScope.indexOf('failure') ? ResPromise._rest : undefined)) !== null && _g !== void 0 ? _g : onFailure) !== null && _h !== void 0 ? _h : initOnFailure) !== null && _j !== void 0 ? _j : (function (v, h) { return v; }),
|
|
212
|
+
error: (_p = (_o = (_l = (_k = ResPromise._error) !== null && _k !== void 0 ? _k : (~ResPromise._restScope.indexOf('error') ? ResPromise._rest : undefined)) !== null && _l !== void 0 ? _l : onError) !== null && _o !== void 0 ? _o : initOnError) !== null && _p !== void 0 ? _p : (function (v, h) { return v; }),
|
|
213
|
+
login: (_t = (_s = (_r = (_q = ResPromise._login) !== null && _q !== void 0 ? _q : (~ResPromise._restScope.indexOf('login') ? ResPromise._rest : undefined)) !== null && _r !== void 0 ? _r : onLogin) !== null && _s !== void 0 ? _s : initOnLogin) !== null && _t !== void 0 ? _t : (function (v, h) { return v; }),
|
|
214
|
+
timeout: (_x = (_w = (_v = (_u = ResPromise._timeout) !== null && _u !== void 0 ? _u : (~ResPromise._restScope.indexOf('timeout') ? ResPromise._rest : undefined)) !== null && _v !== void 0 ? _v : onTimeout) !== null && _w !== void 0 ? _w : initOnTimeout) !== null && _x !== void 0 ? _x : (function (v, h) { return v; }),
|
|
215
|
+
};
|
|
216
|
+
var existedHandler = {
|
|
217
|
+
success: !!(ResPromise._success ||
|
|
218
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('success')) ||
|
|
219
|
+
onSuccess ||
|
|
220
|
+
initOnSuccess),
|
|
221
|
+
failure: !!(ResPromise._failure ||
|
|
222
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('failure')) ||
|
|
223
|
+
onFailure ||
|
|
224
|
+
initOnFailure),
|
|
225
|
+
login: !!(ResPromise._login ||
|
|
226
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('login')) ||
|
|
227
|
+
onLogin ||
|
|
228
|
+
initOnLogin),
|
|
229
|
+
error: !!(ResPromise._error ||
|
|
230
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('error')) ||
|
|
231
|
+
onError ||
|
|
232
|
+
initOnError),
|
|
233
|
+
timeout: !!(ResPromise._timeout ||
|
|
234
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('timeout')) ||
|
|
235
|
+
onTimeout ||
|
|
236
|
+
initOnTimeout),
|
|
237
|
+
};
|
|
238
|
+
var existedChainHandler = {
|
|
239
|
+
success: !!(ResPromise._success ||
|
|
240
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('success'))),
|
|
241
|
+
failure: !!(ResPromise._failure ||
|
|
242
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('failure'))),
|
|
243
|
+
login: !!(ResPromise._login ||
|
|
244
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('login'))),
|
|
245
|
+
error: !!(ResPromise._error ||
|
|
246
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('error'))),
|
|
247
|
+
timeout: !!(ResPromise._timeout ||
|
|
248
|
+
(ResPromise._rest && ~ResPromise._restScope.indexOf('timeout'))),
|
|
249
|
+
};
|
|
250
|
+
var errorHandler = function (e, headers) { return __awaiter(_this, void 0, void 0, function () {
|
|
251
|
+
var err, result, _e_1;
|
|
252
|
+
return __generator(this, function (_a) {
|
|
253
|
+
switch (_a.label) {
|
|
254
|
+
case 0:
|
|
255
|
+
_a.trys.push([0, 2, , 3]);
|
|
256
|
+
err = this.parseError(e);
|
|
257
|
+
return [4 /*yield*/, Promise.resolve(callbacks.error(err, headers))];
|
|
258
|
+
case 1:
|
|
259
|
+
result = _a.sent();
|
|
260
|
+
if (existedChainHandler.error)
|
|
261
|
+
err = result;
|
|
262
|
+
existedHandler.error ? ResPromise._resolve(err) : ResPromise._reject(err);
|
|
263
|
+
return [3 /*break*/, 3];
|
|
264
|
+
case 2:
|
|
265
|
+
_e_1 = _a.sent();
|
|
266
|
+
ResPromise._reject(this.parseError(_e_1));
|
|
267
|
+
return [3 /*break*/, 3];
|
|
268
|
+
case 3: return [2 /*return*/];
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}); };
|
|
272
|
+
var timer = null;
|
|
273
|
+
var isTimeout = false;
|
|
274
|
+
var _timeout = timeout !== null && timeout !== void 0 ? timeout : initTimeout;
|
|
275
|
+
// Cleanup function for timeout
|
|
276
|
+
var cleanup = function () {
|
|
277
|
+
if (timer !== null) {
|
|
278
|
+
clearTimeout(timer);
|
|
279
|
+
timer = null;
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
if (_timeout) {
|
|
283
|
+
timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
284
|
+
var err, res, e_1;
|
|
285
|
+
var _a, _b;
|
|
286
|
+
return __generator(this, function (_c) {
|
|
287
|
+
switch (_c.label) {
|
|
288
|
+
case 0:
|
|
289
|
+
_c.trys.push([0, 2, , 3]);
|
|
290
|
+
isTimeout = true;
|
|
291
|
+
cleanup();
|
|
292
|
+
err = this.parseError('timeout');
|
|
293
|
+
return [4 /*yield*/, Promise.resolve(callbacks.timeout(err, (_a = options.headers) !== null && _a !== void 0 ? _a : {}))];
|
|
294
|
+
case 1:
|
|
295
|
+
res = _c.sent();
|
|
296
|
+
if (existedChainHandler.timeout)
|
|
297
|
+
err = res;
|
|
298
|
+
existedHandler.timeout ? ResPromise._resolve(err) : ResPromise._reject(err);
|
|
299
|
+
return [3 /*break*/, 3];
|
|
300
|
+
case 2:
|
|
301
|
+
e_1 = _c.sent();
|
|
302
|
+
errorHandler(e_1, (_b = options.headers) !== null && _b !== void 0 ? _b : {});
|
|
303
|
+
return [3 /*break*/, 3];
|
|
304
|
+
case 3: return [2 /*return*/];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); }, _timeout);
|
|
308
|
+
}
|
|
309
|
+
_this.axios(options).then(function (response) { return __awaiter(_this, void 0, void 0, function () {
|
|
310
|
+
var status, data, headers, doSuccess, doLogin, res, result, result, result, e_2;
|
|
311
|
+
var _a, _b;
|
|
312
|
+
return __generator(this, function (_c) {
|
|
313
|
+
switch (_c.label) {
|
|
314
|
+
case 0:
|
|
315
|
+
if (isTimeout)
|
|
316
|
+
return [2 /*return*/];
|
|
317
|
+
cleanup();
|
|
318
|
+
status = response.status, data = response.data, headers = response.headers;
|
|
319
|
+
_c.label = 1;
|
|
320
|
+
case 1:
|
|
321
|
+
_c.trys.push([1, 8, , 9]);
|
|
322
|
+
doSuccess = (_a = rules.success) === null || _a === void 0 ? void 0 : _a.call(rules, data, status, headers);
|
|
323
|
+
doLogin = (_b = rules.login) === null || _b === void 0 ? void 0 : _b.call(rules, data, status, headers);
|
|
324
|
+
res = data;
|
|
325
|
+
if (!doLogin) return [3 /*break*/, 3];
|
|
326
|
+
return [4 /*yield*/, Promise.resolve(callbacks.login(data, headers))];
|
|
327
|
+
case 2:
|
|
328
|
+
result = _c.sent();
|
|
329
|
+
if (existedChainHandler.login)
|
|
330
|
+
res = result;
|
|
331
|
+
return [3 /*break*/, 7];
|
|
332
|
+
case 3:
|
|
333
|
+
if (!doSuccess) return [3 /*break*/, 5];
|
|
334
|
+
return [4 /*yield*/, Promise.resolve(callbacks.success(data, headers))];
|
|
335
|
+
case 4:
|
|
336
|
+
result = _c.sent();
|
|
337
|
+
if (existedChainHandler.success)
|
|
338
|
+
res = result;
|
|
339
|
+
return [3 /*break*/, 7];
|
|
340
|
+
case 5: return [4 /*yield*/, Promise.resolve(callbacks.failure(data, headers))];
|
|
341
|
+
case 6:
|
|
342
|
+
result = _c.sent();
|
|
343
|
+
if (existedChainHandler.failure)
|
|
344
|
+
res = result;
|
|
345
|
+
_c.label = 7;
|
|
346
|
+
case 7:
|
|
347
|
+
ResPromise._resolve(res);
|
|
348
|
+
return [3 /*break*/, 9];
|
|
349
|
+
case 8:
|
|
350
|
+
e_2 = _c.sent();
|
|
351
|
+
errorHandler(e_2, headers);
|
|
352
|
+
return [3 /*break*/, 9];
|
|
353
|
+
case 9: return [2 /*return*/];
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}); }).catch(function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
357
|
+
var status, data, headers, res, doLogin, e_3;
|
|
358
|
+
var _a, _b, _c, _d, _f, _g, _h, _j, _k, _l, _o, _p, _q, _r, _s, _t, _u, _v;
|
|
359
|
+
return __generator(this, function (_w) {
|
|
360
|
+
switch (_w.label) {
|
|
361
|
+
case 0:
|
|
362
|
+
if (isTimeout)
|
|
363
|
+
return [2 /*return*/];
|
|
364
|
+
cleanup();
|
|
365
|
+
console.error("[1Money client]: Error(".concat((_a = err.status) !== null && _a !== void 0 ? _a : 500, ", ").concat((_b = err.code) !== null && _b !== void 0 ? _b : 'UNKNOWN', "), Message: ").concat(err.message, ", Config: ").concat((_c = err.config) === null || _c === void 0 ? void 0 : _c.method, ", ").concat((_f = (_d = err.config) === null || _d === void 0 ? void 0 : _d.baseURL) !== null && _f !== void 0 ? _f : '').concat((_h = (_g = err.config) === null || _g === void 0 ? void 0 : _g.url) !== null && _h !== void 0 ? _h : '', ", ").concat(JSON.stringify((_k = (_j = err.config) === null || _j === void 0 ? void 0 : _j.headers) !== null && _k !== void 0 ? _k : {}), ", Request: ").concat(JSON.stringify((_o = (_l = err.config) === null || _l === void 0 ? void 0 : _l.data) !== null && _o !== void 0 ? _o : {}), ";"));
|
|
366
|
+
status = (_q = (_p = err.response) === null || _p === void 0 ? void 0 : _p.status) !== null && _q !== void 0 ? _q : 500;
|
|
367
|
+
data = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.data) !== null && _s !== void 0 ? _s : {};
|
|
368
|
+
headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
|
|
369
|
+
_w.label = 1;
|
|
370
|
+
case 1:
|
|
371
|
+
_w.trys.push([1, 5, , 6]);
|
|
372
|
+
res = data;
|
|
373
|
+
doLogin = (_v = rules.login) === null || _v === void 0 ? void 0 : _v.call(rules, data, status, headers);
|
|
374
|
+
if (!doLogin) return [3 /*break*/, 3];
|
|
375
|
+
return [4 /*yield*/, Promise.resolve(callbacks.login(res, headers))];
|
|
376
|
+
case 2:
|
|
377
|
+
res = _w.sent();
|
|
378
|
+
ResPromise._resolve(res);
|
|
379
|
+
return [3 /*break*/, 4];
|
|
380
|
+
case 3:
|
|
381
|
+
errorHandler(err, headers);
|
|
382
|
+
_w.label = 4;
|
|
383
|
+
case 4: return [3 /*break*/, 6];
|
|
384
|
+
case 5:
|
|
385
|
+
e_3 = _w.sent();
|
|
386
|
+
errorHandler(e_3, headers);
|
|
387
|
+
return [3 /*break*/, 6];
|
|
388
|
+
case 6: return [2 /*return*/];
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
}); });
|
|
392
|
+
});
|
|
393
|
+
return ResPromise.promiseWrapper;
|
|
394
|
+
};
|
|
395
|
+
return Request;
|
|
396
|
+
}());var _a = new Request({
|
|
397
|
+
isSuccess: function (res, status) { return status === 200 && res.code == 0; },
|
|
398
|
+
isLogin: function (res, status) { return status === 401 || res.code == 401; },
|
|
399
|
+
timeout: 10000
|
|
400
|
+
}), request = _a.request, setting = _a.setting, axios = _a.axios;
|
|
401
|
+
function get(url, options) {
|
|
402
|
+
return request(__assign(__assign({}, options), { method: 'get', url: url }));
|
|
403
|
+
}
|
|
404
|
+
function post(url, data, options) {
|
|
405
|
+
return request(__assign(__assign({}, options), { method: 'post', url: url, data: data, headers: __assign({ 'Content-Type': 'application/json' }, options === null || options === void 0 ? void 0 : options.headers) }));
|
|
406
|
+
}
|
|
407
|
+
function setInitConfig(config) {
|
|
408
|
+
var baseURL = config.baseURL, rest = __rest(config, ["baseURL"]);
|
|
409
|
+
axios.defaults.baseURL = baseURL || (typeof window !== 'undefined' ? location.origin : void 0);
|
|
410
|
+
setting(rest);
|
|
411
|
+
}// Base URLs for the API
|
|
412
|
+
var TESTNET_API_URL = 'https://api.testnet.1money.network';
|
|
413
|
+
var MAINNET_API_URL = 'https://api.1money.network';
|
|
414
|
+
var LOCAL_API_URL = 'http://localhost:18555';
|
|
415
|
+
// API version
|
|
416
|
+
var API_VERSION = 'v1';var API_PREFIX$5 = "/".concat(API_VERSION, "/accounts");
|
|
417
|
+
/**
|
|
418
|
+
* Accounts API methods
|
|
419
|
+
*/
|
|
420
|
+
var accountsApi = {
|
|
421
|
+
/**
|
|
422
|
+
* Get account nonce
|
|
423
|
+
* @param address Address of the account to lookup nonce for
|
|
424
|
+
* @returns Promise with account info response
|
|
425
|
+
*/
|
|
426
|
+
getNonce: function (address) {
|
|
427
|
+
return get("".concat(API_PREFIX$5, "/nonce?address=").concat(address), { withCredentials: false });
|
|
428
|
+
},
|
|
429
|
+
/**
|
|
430
|
+
* Get associated token account
|
|
431
|
+
* @param address Address of the account to lookup associated token account for
|
|
432
|
+
* @param token Token address to lookup associated token account for
|
|
433
|
+
* @returns Promise with associated token account response
|
|
434
|
+
*/
|
|
435
|
+
getTokenAccount: function (address, token) {
|
|
436
|
+
return get("".concat(API_PREFIX$5, "/token_account?address=").concat(address, "&token=").concat(token), { withCredentials: false });
|
|
437
|
+
}
|
|
438
|
+
};var API_PREFIX$4 = "/".concat(API_VERSION, "/checkpoints");
|
|
439
|
+
/**
|
|
440
|
+
* Checkpoint API methods
|
|
441
|
+
*/
|
|
442
|
+
var checkpointsApi = {
|
|
443
|
+
/**
|
|
444
|
+
* Get the current checkpoint number
|
|
445
|
+
* @returns Promise with checkpoint number response
|
|
446
|
+
*/
|
|
447
|
+
getNumber: function () {
|
|
448
|
+
return get("".concat(API_PREFIX$4, "/number"), { withCredentials: false });
|
|
449
|
+
},
|
|
450
|
+
/**
|
|
451
|
+
* Get checkpoint by hash
|
|
452
|
+
* @param hash Hash of the checkpoint to lookup
|
|
453
|
+
* @param full Whether to include full transaction details
|
|
454
|
+
* @returns Promise with checkpoint response
|
|
455
|
+
*/
|
|
456
|
+
getByHash: function (hash, full) {
|
|
457
|
+
if (full === void 0) { full = false; }
|
|
458
|
+
return get("".concat(API_PREFIX$4, "/by_hash?hash=").concat(hash, "&full=").concat(full), { withCredentials: false });
|
|
459
|
+
},
|
|
460
|
+
/**
|
|
461
|
+
* Get checkpoint by number
|
|
462
|
+
* @param number Number of the checkpoint to lookup
|
|
463
|
+
* @param full Whether to include full transaction details
|
|
464
|
+
* @returns Promise with checkpoint response
|
|
465
|
+
*/
|
|
466
|
+
getByNumber: function (number, full) {
|
|
467
|
+
if (full === void 0) { full = false; }
|
|
468
|
+
return get("".concat(API_PREFIX$4, "/by_number?number=").concat(number, "&full=").concat(full), { withCredentials: false });
|
|
469
|
+
}
|
|
470
|
+
};var API_PREFIX$3 = "/".concat(API_VERSION, "/tokens");
|
|
471
|
+
/**
|
|
472
|
+
* Tokens API methods
|
|
473
|
+
*/
|
|
474
|
+
var tokensApi = {
|
|
475
|
+
/**
|
|
476
|
+
* Get token metadata
|
|
477
|
+
* @param token Token address to lookup metadata for
|
|
478
|
+
* @returns Promise with token metadata response
|
|
479
|
+
*/
|
|
480
|
+
getTokenMetadata: function (token) {
|
|
481
|
+
return get("".concat(API_PREFIX$3, "/token_metadata?token=").concat(token), { withCredentials: false });
|
|
482
|
+
},
|
|
483
|
+
/**
|
|
484
|
+
* Manage token blacklist
|
|
485
|
+
* @param payload Token blacklist request payload
|
|
486
|
+
* @returns Promise with transaction hash response
|
|
487
|
+
*/
|
|
488
|
+
manageBlacklist: function (payload) {
|
|
489
|
+
return post("".concat(API_PREFIX$3, "/manage_blacklist"), payload, { withCredentials: false });
|
|
490
|
+
},
|
|
491
|
+
/**
|
|
492
|
+
* Manage token whitelist
|
|
493
|
+
* @param payload Token whitelist request payload
|
|
494
|
+
* @returns Promise with transaction hash response
|
|
495
|
+
*/
|
|
496
|
+
manageWhitelist: function (payload) {
|
|
497
|
+
return post("".concat(API_PREFIX$3, "/manage_whitelist"), payload, { withCredentials: false });
|
|
498
|
+
},
|
|
499
|
+
/**
|
|
500
|
+
* Burn tokens
|
|
501
|
+
* @param payload Token burn request payload
|
|
502
|
+
* @returns Promise with transaction hash response
|
|
503
|
+
*/
|
|
504
|
+
burnToken: function (payload) {
|
|
505
|
+
return post("".concat(API_PREFIX$3, "/burn"), payload, { withCredentials: false });
|
|
506
|
+
},
|
|
507
|
+
/**
|
|
508
|
+
* Grant or revoke token authority
|
|
509
|
+
* @param payload Token authority request payload
|
|
510
|
+
* @returns Promise with transaction hash response
|
|
511
|
+
*/
|
|
512
|
+
grantAuthority: function (payload) {
|
|
513
|
+
return post("".concat(API_PREFIX$3, "/grant_authority"), payload, { withCredentials: false });
|
|
514
|
+
},
|
|
515
|
+
/**
|
|
516
|
+
* Issue new token
|
|
517
|
+
* @param payload Token issue request payload
|
|
518
|
+
* @returns Promise with transaction hash and token address response
|
|
519
|
+
*/
|
|
520
|
+
issueToken: function (payload) {
|
|
521
|
+
return post("".concat(API_PREFIX$3, "/issue"), payload, { withCredentials: false });
|
|
522
|
+
},
|
|
523
|
+
/**
|
|
524
|
+
* Mint tokens
|
|
525
|
+
* @param payload Token mint request payload
|
|
526
|
+
* @returns Promise with transaction hash response
|
|
527
|
+
*/
|
|
528
|
+
mintToken: function (payload) {
|
|
529
|
+
return post("".concat(API_PREFIX$3, "/mint"), payload, { withCredentials: false });
|
|
530
|
+
},
|
|
531
|
+
/**
|
|
532
|
+
* Pause or unpause token
|
|
533
|
+
* @param payload Token pause request payload
|
|
534
|
+
* @returns Promise with transaction hash response
|
|
535
|
+
*/
|
|
536
|
+
pauseToken: function (payload) {
|
|
537
|
+
return post("".concat(API_PREFIX$3, "/pause"), payload, { withCredentials: false });
|
|
538
|
+
},
|
|
539
|
+
/**
|
|
540
|
+
* Update token metadata
|
|
541
|
+
* @param payload Token metadata request payload
|
|
542
|
+
* @returns Promise with transaction hash response
|
|
543
|
+
*/
|
|
544
|
+
updateMetadata: function (payload) {
|
|
545
|
+
return post("".concat(API_PREFIX$3, "/update_metadata"), payload, { withCredentials: false });
|
|
546
|
+
}
|
|
547
|
+
};var API_PREFIX$2 = "/".concat(API_VERSION, "/transactions");
|
|
548
|
+
/**
|
|
549
|
+
* Transactions API methods
|
|
550
|
+
*/
|
|
551
|
+
var transactionsApi = {
|
|
552
|
+
/**
|
|
553
|
+
* Get transaction by hash
|
|
554
|
+
* @param hash Hash of the transaction to lookup
|
|
555
|
+
* @returns Promise with transaction response
|
|
556
|
+
*/
|
|
557
|
+
getByHash: function (hash) {
|
|
558
|
+
return get("".concat(API_PREFIX$2, "/by_hash?hash=").concat(hash), { withCredentials: false });
|
|
559
|
+
},
|
|
560
|
+
/**
|
|
561
|
+
* Get transaction receipt by hash
|
|
562
|
+
* @param hash Hash of the transaction to lookup receipt for
|
|
563
|
+
* @returns Promise with transaction receipt response
|
|
564
|
+
*/
|
|
565
|
+
getReceiptByHash: function (hash) {
|
|
566
|
+
return get("".concat(API_PREFIX$2, "/receipt/by_hash?hash=").concat(hash), { withCredentials: false });
|
|
567
|
+
},
|
|
568
|
+
/**
|
|
569
|
+
* Estimate transaction fee
|
|
570
|
+
* @param from Address of the transaction author
|
|
571
|
+
* @param value Value of the transaction
|
|
572
|
+
* @param token Optional token address
|
|
573
|
+
* @returns Promise with fee estimate response
|
|
574
|
+
*/
|
|
575
|
+
estimateFee: function (from, value, token) {
|
|
576
|
+
var url = "".concat(API_PREFIX$2, "/estimate_fee?from=").concat(from, "&value=").concat(value);
|
|
577
|
+
if (token) {
|
|
578
|
+
url += "&token=".concat(token);
|
|
579
|
+
}
|
|
580
|
+
return get(url, { withCredentials: false });
|
|
581
|
+
},
|
|
582
|
+
/**
|
|
583
|
+
* Submit payment transaction
|
|
584
|
+
* @param payload Payment transaction payload
|
|
585
|
+
* @returns Promise with transaction hash response
|
|
586
|
+
*/
|
|
587
|
+
payment: function (payload) {
|
|
588
|
+
return post("".concat(API_PREFIX$2, "/payment"), payload, { withCredentials: false });
|
|
589
|
+
}
|
|
590
|
+
};var API_PREFIX$1 = "/".concat(API_VERSION, "/chains");
|
|
591
|
+
/**
|
|
592
|
+
* Checkpoint API methods
|
|
593
|
+
*/
|
|
594
|
+
var chainApi = {
|
|
595
|
+
/**
|
|
596
|
+
* Get the current chain id
|
|
597
|
+
* @returns Promise with chain id response
|
|
598
|
+
*/
|
|
599
|
+
getChainId: function () {
|
|
600
|
+
return get("".concat(API_PREFIX$1, "/chain_id"), { withCredentials: false });
|
|
601
|
+
},
|
|
602
|
+
};var API_PREFIX = "/".concat(API_VERSION, "/states");
|
|
603
|
+
/**
|
|
604
|
+
* State API methods
|
|
605
|
+
*/
|
|
606
|
+
var stateApi = {
|
|
607
|
+
/**
|
|
608
|
+
* Get latest epoch checkpoint
|
|
609
|
+
* @returns Promise with latest epoch checkpoint response
|
|
610
|
+
*/
|
|
611
|
+
getLatestEpochCheckpoint: function () {
|
|
612
|
+
return get("".concat(API_PREFIX, "/latest_epoch_checkpoint"), { withCredentials: false });
|
|
613
|
+
}
|
|
614
|
+
};// Authority types
|
|
615
|
+
exports.AuthorityType=void 0;
|
|
616
|
+
(function (AuthorityType) {
|
|
617
|
+
AuthorityType["MasterMint"] = "MasterMint";
|
|
618
|
+
AuthorityType["MintBurnTokens"] = "MintBurnTokens";
|
|
619
|
+
AuthorityType["Pause"] = "Pause";
|
|
620
|
+
AuthorityType["ManageList"] = "ManageList";
|
|
621
|
+
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
622
|
+
})(exports.AuthorityType || (exports.AuthorityType = {}));
|
|
623
|
+
exports.AuthorityAction=void 0;
|
|
624
|
+
(function (AuthorityAction) {
|
|
625
|
+
AuthorityAction["Grant"] = "Grant";
|
|
626
|
+
AuthorityAction["Revoke"] = "Revoke";
|
|
627
|
+
})(exports.AuthorityAction || (exports.AuthorityAction = {}));
|
|
628
|
+
exports.ManageListAction=void 0;
|
|
629
|
+
(function (ManageListAction) {
|
|
630
|
+
ManageListAction["Add"] = "Add";
|
|
631
|
+
ManageListAction["Remove"] = "Remove";
|
|
632
|
+
})(exports.ManageListAction || (exports.ManageListAction = {}));
|
|
633
|
+
exports.PauseAction=void 0;
|
|
634
|
+
(function (PauseAction) {
|
|
635
|
+
PauseAction["Pause"] = "Pause";
|
|
636
|
+
PauseAction["Unpause"] = "Unpause";
|
|
637
|
+
})(exports.PauseAction || (exports.PauseAction = {}));/**
|
|
638
|
+
* API client for 1money network
|
|
639
|
+
* @param options Configuration options
|
|
640
|
+
* @param options.network Network to use (testnet, mainnet, local)
|
|
641
|
+
* @param options.timeout Request timeout in milliseconds
|
|
642
|
+
* @param options.chainId Custom chain ID (overrides the default for the selected network)
|
|
643
|
+
*/
|
|
644
|
+
function api(options) {
|
|
645
|
+
var network = (options === null || options === void 0 ? void 0 : options.network) || 'mainnet';
|
|
646
|
+
var baseURL = MAINNET_API_URL;
|
|
647
|
+
// Set the base URL based on the network
|
|
648
|
+
switch (network) {
|
|
649
|
+
case 'mainnet':
|
|
650
|
+
baseURL = MAINNET_API_URL;
|
|
651
|
+
break;
|
|
652
|
+
case 'testnet':
|
|
653
|
+
baseURL = TESTNET_API_URL;
|
|
654
|
+
break;
|
|
655
|
+
case 'local':
|
|
656
|
+
baseURL = LOCAL_API_URL;
|
|
657
|
+
break;
|
|
658
|
+
}
|
|
659
|
+
// Initialize API configuration
|
|
660
|
+
setInitConfig({
|
|
661
|
+
baseURL: baseURL,
|
|
662
|
+
// Treat status code 200 as success
|
|
663
|
+
isSuccess: function (_res, status) { return status === 200; },
|
|
664
|
+
timeout: (options === null || options === void 0 ? void 0 : options.timeout) || 10000
|
|
665
|
+
});
|
|
666
|
+
return {
|
|
667
|
+
/**
|
|
668
|
+
* Accounts API methods
|
|
669
|
+
*/
|
|
670
|
+
accounts: accountsApi,
|
|
671
|
+
/**
|
|
672
|
+
* Checkpoint API methods
|
|
673
|
+
*/
|
|
674
|
+
checkpoints: checkpointsApi,
|
|
675
|
+
/**
|
|
676
|
+
* Tokens API methods
|
|
677
|
+
*/
|
|
678
|
+
tokens: tokensApi,
|
|
679
|
+
/**
|
|
680
|
+
* Transactions API methods
|
|
681
|
+
*/
|
|
682
|
+
transactions: transactionsApi,
|
|
683
|
+
/**
|
|
684
|
+
* Chain API methods
|
|
685
|
+
*/
|
|
686
|
+
chain: chainApi,
|
|
687
|
+
/**
|
|
688
|
+
* State API methods
|
|
689
|
+
*/
|
|
690
|
+
state: stateApi,
|
|
691
|
+
};
|
|
692
|
+
}exports.api=api;exports.default=api;
|