@coopenomics/sdk 2.2.3 → 2.2.5
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/dist/index.cjs +473 -228
- package/dist/index.d.cts +628 -455
- package/dist/index.d.mts +628 -455
- package/dist/index.d.ts +628 -455
- package/dist/index.mjs +473 -228
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -11,17 +11,17 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
const WebSocket__default = /*#__PURE__*/_interopDefaultCompat(WebSocket);
|
|
13
13
|
|
|
14
|
-
var __defProp$
|
|
15
|
-
var __defNormalProp$
|
|
16
|
-
var __publicField$
|
|
17
|
-
__defNormalProp$
|
|
14
|
+
var __defProp$4 = Object.defineProperty;
|
|
15
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
16
|
+
var __publicField$4 = (obj, key, value) => {
|
|
17
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
18
18
|
return value;
|
|
19
19
|
};
|
|
20
20
|
class Account {
|
|
21
21
|
constructor() {
|
|
22
|
-
__publicField$
|
|
23
|
-
__publicField$
|
|
24
|
-
__publicField$
|
|
22
|
+
__publicField$4(this, "username");
|
|
23
|
+
__publicField$4(this, "private_key");
|
|
24
|
+
__publicField$4(this, "public_key");
|
|
25
25
|
this.username = Account.generateUsername();
|
|
26
26
|
const keys = Account.generateKeys();
|
|
27
27
|
this.private_key = keys.private_key;
|
|
@@ -54,118 +54,43 @@ class Account {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
var __defProp$
|
|
58
|
-
var __defNormalProp$
|
|
59
|
-
var __publicField$
|
|
60
|
-
__defNormalProp$
|
|
57
|
+
var __defProp$3 = Object.defineProperty;
|
|
58
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
59
|
+
var __publicField$3 = (obj, key, value) => {
|
|
60
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
61
61
|
return value;
|
|
62
62
|
};
|
|
63
|
-
class
|
|
64
|
-
/**
|
|
65
|
-
* Создаёт элемент `<canvas>` внутри указанного контейнера.
|
|
66
|
-
* @param container - HTML-элемент, внутри которого создаётся canvas.
|
|
67
|
-
* @param width - Ширина canvas (по умолчанию 300).
|
|
68
|
-
* @param height - Высота canvas (по умолчанию 150).
|
|
69
|
-
*/
|
|
70
|
-
constructor(container, width = 300, height = 150) {
|
|
71
|
-
__publicField$1(this, "canvas");
|
|
72
|
-
__publicField$1(this, "ctx");
|
|
73
|
-
__publicField$1(this, "state", {
|
|
74
|
-
drawing: false,
|
|
75
|
-
lastX: 0,
|
|
76
|
-
lastY: 0
|
|
77
|
-
});
|
|
78
|
-
this.canvas = document.createElement("canvas");
|
|
79
|
-
this.canvas.width = width;
|
|
80
|
-
this.canvas.height = height;
|
|
81
|
-
container.appendChild(this.canvas);
|
|
82
|
-
this.ctx = this.canvas.getContext("2d");
|
|
83
|
-
this.ctx.lineWidth = 5;
|
|
84
|
-
this.ctx.lineJoin = "round";
|
|
85
|
-
this.ctx.lineCap = "round";
|
|
86
|
-
this.ctx.strokeStyle = "#000";
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Полностью очищает canvas.
|
|
90
|
-
*/
|
|
91
|
-
clearCanvas() {
|
|
92
|
-
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Запускает процесс рисования (фиксирует начальные координаты).
|
|
96
|
-
* @param e - Событие мыши или касания.
|
|
97
|
-
*/
|
|
98
|
-
startDrawing(e) {
|
|
99
|
-
e.preventDefault();
|
|
100
|
-
this.state.drawing = true;
|
|
101
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
102
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
103
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
104
|
-
this.state.lastX = clientX - rect.left;
|
|
105
|
-
this.state.lastY = clientY - rect.top;
|
|
106
|
-
}
|
|
63
|
+
class Blockchain {
|
|
107
64
|
/**
|
|
108
|
-
*
|
|
109
|
-
* @param
|
|
65
|
+
* Конструктор класса Blockchain.
|
|
66
|
+
* @param config Конфигурация блокчейна, включающая URL цепочки и идентификатор цепочки.
|
|
110
67
|
*/
|
|
111
|
-
draw(e) {
|
|
112
|
-
if (!this.state.drawing)
|
|
113
|
-
return;
|
|
114
|
-
e.preventDefault();
|
|
115
|
-
this.ctx.beginPath();
|
|
116
|
-
this.ctx.moveTo(this.state.lastX, this.state.lastY);
|
|
117
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
118
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
119
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
120
|
-
const x = clientX - rect.left;
|
|
121
|
-
const y = clientY - rect.top;
|
|
122
|
-
this.ctx.lineTo(x, y);
|
|
123
|
-
this.ctx.stroke();
|
|
124
|
-
this.state.lastX = x;
|
|
125
|
-
this.state.lastY = y;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Завершает процесс рисования (drawing = false).
|
|
129
|
-
*/
|
|
130
|
-
endDrawing() {
|
|
131
|
-
this.state.drawing = false;
|
|
132
|
-
}
|
|
133
|
-
/**
|
|
134
|
-
* Возвращает текущее содержимое canvas в формате base64 (PNG).
|
|
135
|
-
*/
|
|
136
|
-
getSignature() {
|
|
137
|
-
return this.canvas.toDataURL("image/png");
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
var __defProp = Object.defineProperty;
|
|
142
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
143
|
-
var __publicField = (obj, key, value) => {
|
|
144
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
145
|
-
return value;
|
|
146
|
-
};
|
|
147
|
-
class Wallet {
|
|
148
68
|
constructor(config) {
|
|
149
69
|
this.config = config;
|
|
150
|
-
__publicField(this, "apiClient");
|
|
151
|
-
__publicField(this, "contractKit");
|
|
152
|
-
__publicField(this, "session");
|
|
70
|
+
__publicField$3(this, "apiClient");
|
|
71
|
+
__publicField$3(this, "contractKit");
|
|
72
|
+
__publicField$3(this, "session");
|
|
153
73
|
this.apiClient = new antelope.APIClient({ url: config.chain_url });
|
|
154
74
|
this.contractKit = new contract.ContractKit({ client: this.apiClient });
|
|
155
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Получение информации о блокчейне.
|
|
78
|
+
* @returns Объект с информацией о текущем состоянии блокчейна.
|
|
79
|
+
*/
|
|
156
80
|
async getInfo() {
|
|
157
81
|
return this.apiClient.v1.chain.get_info();
|
|
158
82
|
}
|
|
159
83
|
/**
|
|
160
|
-
*
|
|
161
|
-
* @param username
|
|
162
|
-
* @param wif
|
|
163
|
-
* @
|
|
84
|
+
* Устанавливает приватный ключ (WIF) для текущей сессии.
|
|
85
|
+
* @param username Имя пользователя (аккаунт).
|
|
86
|
+
* @param wif Приватный ключ в формате WIF.
|
|
87
|
+
* @param permission Тип разрешения, который используется для подписания транзакции (по умолчанию = 'active')
|
|
88
|
+
* @returns Текущий экземпляр Blockchain для цепочного вызова.
|
|
164
89
|
*/
|
|
165
|
-
setWif(username, wif) {
|
|
90
|
+
setWif(username, wif, permission = "active") {
|
|
166
91
|
this.session = new session.Session({
|
|
167
92
|
actor: username,
|
|
168
|
-
permission
|
|
93
|
+
permission,
|
|
169
94
|
chain: {
|
|
170
95
|
id: this.config.chain_id,
|
|
171
96
|
url: this.config.chain_url
|
|
@@ -174,18 +99,40 @@ class Wallet {
|
|
|
174
99
|
});
|
|
175
100
|
return this;
|
|
176
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Выполнение транзакции с передачей одного или нескольких действий.
|
|
104
|
+
* @param actionOrActions Действие или массив действий для выполнения.
|
|
105
|
+
* @param broadcast Если true, транзакция будет отправлена в сеть.
|
|
106
|
+
* @returns Результат выполнения транзакции.
|
|
107
|
+
* @throws Ошибка, если сессия не инициализирована.
|
|
108
|
+
*/
|
|
177
109
|
async transact(actionOrActions, broadcast = true) {
|
|
178
110
|
if (!this.session)
|
|
179
|
-
throw new Error("
|
|
111
|
+
throw new Error("\u0421\u0435\u0441\u0441\u0438\u044F \u043D\u0435 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u043D\u0430.");
|
|
180
112
|
const actions = Array.isArray(actionOrActions) ? await Promise.all(actionOrActions.map((action) => this.formActionFromAbi(action))) : [await this.formActionFromAbi(actionOrActions)];
|
|
181
113
|
return this.session.transact({ actions }, { broadcast });
|
|
182
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Получение всех строк таблицы смарт-контракта.
|
|
117
|
+
* @param code Код (аккаунт) контракта.
|
|
118
|
+
* @param scope Область видимости (scope) таблицы.
|
|
119
|
+
* @param tableName Имя таблицы.
|
|
120
|
+
* @returns Массив строк таблицы.
|
|
121
|
+
*/
|
|
183
122
|
async getAllRows(code, scope, tableName) {
|
|
184
123
|
const abi = await this.getAbi(code);
|
|
185
124
|
const table = this.createTable(code, tableName, abi);
|
|
186
125
|
const rows = await table.all({ scope });
|
|
187
126
|
return JSON.parse(JSON.stringify(rows));
|
|
188
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Запрос строк таблицы с использованием фильтров.
|
|
130
|
+
* @param code Код (аккаунт) контракта.
|
|
131
|
+
* @param scope Область видимости (scope) таблицы.
|
|
132
|
+
* @param tableName Имя таблицы.
|
|
133
|
+
* @param options Опции для фильтрации данных.
|
|
134
|
+
* @returns Массив строк, соответствующих фильтрам.
|
|
135
|
+
*/
|
|
189
136
|
async query(code, scope, tableName, options = { indexPosition: "primary" }) {
|
|
190
137
|
const { indexPosition = "primary", from, to, maxRows } = options;
|
|
191
138
|
const abi = await this.getAbi(code);
|
|
@@ -199,6 +146,15 @@ class Wallet {
|
|
|
199
146
|
});
|
|
200
147
|
return JSON.parse(JSON.stringify(rows));
|
|
201
148
|
}
|
|
149
|
+
/**
|
|
150
|
+
* Получение одной строки таблицы по первичному ключу.
|
|
151
|
+
* @param code Код (аккаунт) контракта.
|
|
152
|
+
* @param scope Область видимости (scope) таблицы.
|
|
153
|
+
* @param tableName Имя таблицы.
|
|
154
|
+
* @param primaryKey Первичный ключ строки.
|
|
155
|
+
* @param indexPosition Индекс для поиска строки (по умолчанию 'primary').
|
|
156
|
+
* @returns Строка таблицы или null, если не найдена.
|
|
157
|
+
*/
|
|
202
158
|
async getRow(code, scope, tableName, primaryKey, indexPosition = "primary") {
|
|
203
159
|
const abi = await this.getAbi(code);
|
|
204
160
|
const table = this.createTable(code, tableName, abi);
|
|
@@ -208,16 +164,34 @@ class Wallet {
|
|
|
208
164
|
});
|
|
209
165
|
return row ? JSON.parse(JSON.stringify(row)) : null;
|
|
210
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Создает объект действия (Action) из ABI контракта.
|
|
169
|
+
* @param action Объект действия.
|
|
170
|
+
* @returns Объект Action.
|
|
171
|
+
*/
|
|
211
172
|
async formActionFromAbi(action) {
|
|
212
173
|
const abi = await this.getAbi(action.account);
|
|
213
174
|
return antelope.Action.from(action, abi);
|
|
214
175
|
}
|
|
176
|
+
/**
|
|
177
|
+
* Получение ABI контракта.
|
|
178
|
+
* @param account Код (аккаунт) контракта.
|
|
179
|
+
* @returns ABI контракта.
|
|
180
|
+
* @throws Ошибка, если ABI не найден.
|
|
181
|
+
*/
|
|
215
182
|
async getAbi(account) {
|
|
216
183
|
const { abi } = await this.apiClient.v1.chain.get_abi(account);
|
|
217
184
|
if (!abi)
|
|
218
|
-
throw new Error(`ABI
|
|
185
|
+
throw new Error(`ABI \u0434\u043B\u044F \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u0430 "${account}" \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D.`);
|
|
219
186
|
return abi;
|
|
220
187
|
}
|
|
188
|
+
/**
|
|
189
|
+
* Создает объект таблицы (Table) для работы с данными.
|
|
190
|
+
* @param code Код (аккаунт) контракта.
|
|
191
|
+
* @param tableName Имя таблицы.
|
|
192
|
+
* @param abi ABI контракта.
|
|
193
|
+
* @returns Объект Table.
|
|
194
|
+
*/
|
|
221
195
|
createTable(code, tableName, abi) {
|
|
222
196
|
return new contract.Table({
|
|
223
197
|
abi,
|
|
@@ -228,11 +202,193 @@ class Wallet {
|
|
|
228
202
|
}
|
|
229
203
|
}
|
|
230
204
|
|
|
205
|
+
var __defProp$2 = Object.defineProperty;
|
|
206
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
207
|
+
var __publicField$2 = (obj, key, value) => {
|
|
208
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
209
|
+
return value;
|
|
210
|
+
};
|
|
211
|
+
class Canvas {
|
|
212
|
+
/**
|
|
213
|
+
* Создаёт экземпляр класса `Canvas` и подготавливает холст для рисования подписи.
|
|
214
|
+
*
|
|
215
|
+
* @param container - HTML-элемент, внутри которого создаётся `<canvas>`.
|
|
216
|
+
* @param opts - Настройки:
|
|
217
|
+
* - `lineWidth` - Толщина линии для рисования (по умолчанию 5).
|
|
218
|
+
* - `strokeStyle` - Цвет линии для рисования (по умолчанию чёрный, `#000`).
|
|
219
|
+
*/
|
|
220
|
+
constructor(container, opts = {}) {
|
|
221
|
+
this.container = container;
|
|
222
|
+
this.opts = opts;
|
|
223
|
+
__publicField$2(this, "canvas");
|
|
224
|
+
__publicField$2(this, "ctx");
|
|
225
|
+
__publicField$2(this, "drawing", false);
|
|
226
|
+
__publicField$2(this, "lastX", 0);
|
|
227
|
+
__publicField$2(this, "lastY", 0);
|
|
228
|
+
__publicField$2(this, "onMouseDown", (e) => {
|
|
229
|
+
e.preventDefault();
|
|
230
|
+
this.drawing = true;
|
|
231
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
232
|
+
this.lastX = e.clientX - rect.left;
|
|
233
|
+
this.lastY = e.clientY - rect.top;
|
|
234
|
+
});
|
|
235
|
+
__publicField$2(this, "onMouseMove", (e) => {
|
|
236
|
+
if (!this.drawing)
|
|
237
|
+
return;
|
|
238
|
+
e.preventDefault();
|
|
239
|
+
this.drawLine(e.clientX, e.clientY);
|
|
240
|
+
});
|
|
241
|
+
__publicField$2(this, "onMouseUp", () => {
|
|
242
|
+
this.drawing = false;
|
|
243
|
+
});
|
|
244
|
+
__publicField$2(this, "onTouchStart", (e) => {
|
|
245
|
+
e.preventDefault();
|
|
246
|
+
this.drawing = true;
|
|
247
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
248
|
+
const t = e.touches[0];
|
|
249
|
+
this.lastX = t.clientX - rect.left;
|
|
250
|
+
this.lastY = t.clientY - rect.top;
|
|
251
|
+
});
|
|
252
|
+
__publicField$2(this, "onTouchMove", (e) => {
|
|
253
|
+
if (!this.drawing)
|
|
254
|
+
return;
|
|
255
|
+
e.preventDefault();
|
|
256
|
+
const t = e.touches[0];
|
|
257
|
+
this.drawLine(t.clientX, t.clientY);
|
|
258
|
+
});
|
|
259
|
+
__publicField$2(this, "onTouchEnd", () => {
|
|
260
|
+
this.drawing = false;
|
|
261
|
+
});
|
|
262
|
+
this.canvas = document.createElement("canvas");
|
|
263
|
+
this.canvas.width = container.offsetWidth;
|
|
264
|
+
this.canvas.height = container.offsetHeight;
|
|
265
|
+
this.canvas.style.touchAction = "none";
|
|
266
|
+
container.appendChild(this.canvas);
|
|
267
|
+
const ctx = this.canvas.getContext("2d");
|
|
268
|
+
if (!ctx) {
|
|
269
|
+
throw new Error("Canvas \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F");
|
|
270
|
+
}
|
|
271
|
+
this.ctx = ctx;
|
|
272
|
+
this.ctx.lineWidth = this.opts.lineWidth ?? 5;
|
|
273
|
+
this.ctx.lineJoin = "round";
|
|
274
|
+
this.ctx.lineCap = "round";
|
|
275
|
+
this.ctx.strokeStyle = this.opts.strokeStyle ?? "#000";
|
|
276
|
+
this.initEvents();
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Очищает холст.
|
|
280
|
+
*/
|
|
281
|
+
clearCanvas() {
|
|
282
|
+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Возвращает содержимое холста (подпись) в формате base64 (PNG).
|
|
286
|
+
*
|
|
287
|
+
* @returns Подпись в формате base64.
|
|
288
|
+
*/
|
|
289
|
+
getSignature() {
|
|
290
|
+
return this.canvas.toDataURL("image/png");
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Снимает все обработчики событий и очищает ресурсы.
|
|
294
|
+
*/
|
|
295
|
+
destroy() {
|
|
296
|
+
this.canvas.removeEventListener("mousedown", this.onMouseDown);
|
|
297
|
+
this.canvas.removeEventListener("mousemove", this.onMouseMove);
|
|
298
|
+
this.canvas.removeEventListener("mouseup", this.onMouseUp);
|
|
299
|
+
this.canvas.removeEventListener("touchstart", this.onTouchStart);
|
|
300
|
+
this.canvas.removeEventListener("touchmove", this.onTouchMove);
|
|
301
|
+
this.canvas.removeEventListener("touchend", this.onTouchEnd);
|
|
302
|
+
}
|
|
303
|
+
// Внутренние методы
|
|
304
|
+
/**
|
|
305
|
+
* Навешивает обработчики событий мыши и тач-устройств.
|
|
306
|
+
*/
|
|
307
|
+
initEvents() {
|
|
308
|
+
this.canvas.addEventListener("mousedown", this.onMouseDown);
|
|
309
|
+
this.canvas.addEventListener("mousemove", this.onMouseMove);
|
|
310
|
+
this.canvas.addEventListener("mouseup", this.onMouseUp);
|
|
311
|
+
this.canvas.addEventListener("touchstart", this.onTouchStart, { passive: false });
|
|
312
|
+
this.canvas.addEventListener("touchmove", this.onTouchMove, { passive: false });
|
|
313
|
+
this.canvas.addEventListener("touchend", this.onTouchEnd, { passive: false });
|
|
314
|
+
}
|
|
315
|
+
drawLine(clientX, clientY) {
|
|
316
|
+
this.ctx.beginPath();
|
|
317
|
+
this.ctx.moveTo(this.lastX, this.lastY);
|
|
318
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
319
|
+
const x = clientX - rect.left;
|
|
320
|
+
const y = clientY - rect.top;
|
|
321
|
+
this.ctx.lineTo(x, y);
|
|
322
|
+
this.ctx.stroke();
|
|
323
|
+
this.lastX = x;
|
|
324
|
+
this.lastY = y;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
var __defProp$1 = Object.defineProperty;
|
|
329
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
330
|
+
var __publicField$1 = (obj, key, value) => {
|
|
331
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
332
|
+
return value;
|
|
333
|
+
};
|
|
334
|
+
class Document {
|
|
335
|
+
/**
|
|
336
|
+
* Инициализация класса Document с WIF-ключом.
|
|
337
|
+
* @param wifKey WIF-ключ, используемый для подписи.
|
|
338
|
+
*/
|
|
339
|
+
constructor(wifKey) {
|
|
340
|
+
__publicField$1(this, "wif");
|
|
341
|
+
if (wifKey)
|
|
342
|
+
this.wif = antelope.PrivateKey.fromString(wifKey);
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Замена текущего WIF-ключа на новый.
|
|
346
|
+
* @param wifKey Новый WIF-ключ.
|
|
347
|
+
*/
|
|
348
|
+
setWif(wifKey) {
|
|
349
|
+
this.wif = antelope.PrivateKey.fromString(wifKey);
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Подписывает документ и возвращает его в формате ISignedDocument.
|
|
353
|
+
* @param document Сгенерированный документ для подписи.
|
|
354
|
+
* @returns Подписанный документ.
|
|
355
|
+
*/
|
|
356
|
+
async signDocument(document) {
|
|
357
|
+
const digitalSignature = this.signDigest(document.hash);
|
|
358
|
+
return {
|
|
359
|
+
hash: document.hash,
|
|
360
|
+
public_key: digitalSignature.public_key,
|
|
361
|
+
signature: digitalSignature.signature,
|
|
362
|
+
meta: document.meta
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
/**
|
|
366
|
+
* Подписывает хэш (digest) документа и проверяет подпись.
|
|
367
|
+
* @param digest Хэш документа для подписи.
|
|
368
|
+
* @returns Детали подписи.
|
|
369
|
+
*/
|
|
370
|
+
signDigest(digest) {
|
|
371
|
+
if (!this.wif)
|
|
372
|
+
throw new Error(`\u041A\u043B\u044E\u0447 \u043D\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D, \u0432\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u0435 \u0432\u044B\u0437\u043E\u0432 \u043C\u0435\u0442\u043E\u0434\u0430 setWif \u043F\u0435\u0440\u0435\u0434 \u043F\u043E\u0434\u043F\u0438\u0441\u044C\u044E \u0434\u043E\u043A\u0443\u043C\u0435\u043D\u0442\u0430`);
|
|
373
|
+
const signed = this.wif.signDigest(digest);
|
|
374
|
+
const verified = signed.verifyDigest(digest, this.wif.toPublic());
|
|
375
|
+
if (!verified) {
|
|
376
|
+
throw new Error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043F\u043E\u0434\u043F\u0438\u0441\u0438");
|
|
377
|
+
}
|
|
378
|
+
return {
|
|
379
|
+
message: digest,
|
|
380
|
+
signature: signed.toString(),
|
|
381
|
+
public_key: this.wif.toPublic().toString()
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
231
386
|
const Classes = {
|
|
232
387
|
__proto__: null,
|
|
233
388
|
Account: Account,
|
|
389
|
+
Blockchain: Blockchain,
|
|
234
390
|
Canvas: Canvas,
|
|
235
|
-
|
|
391
|
+
Document: Document
|
|
236
392
|
};
|
|
237
393
|
|
|
238
394
|
const AllTypesProps = {
|
|
@@ -308,7 +464,6 @@ const AllTypesProps = {
|
|
|
308
464
|
soviet: "SovietMemberInput"
|
|
309
465
|
},
|
|
310
466
|
JSON: `scalar.JSON`,
|
|
311
|
-
LangType: "enum",
|
|
312
467
|
LoginInput: {},
|
|
313
468
|
LogoutInput: {},
|
|
314
469
|
MetaDocumentInput: {},
|
|
@@ -866,7 +1021,7 @@ const ReturnTypes = {
|
|
|
866
1021
|
created_at: "String",
|
|
867
1022
|
decision_id: "Float",
|
|
868
1023
|
generator: "String",
|
|
869
|
-
lang: "
|
|
1024
|
+
lang: "String",
|
|
870
1025
|
links: "String",
|
|
871
1026
|
project_id: "String",
|
|
872
1027
|
registry_id: "Int",
|
|
@@ -903,7 +1058,7 @@ const ReturnTypes = {
|
|
|
903
1058
|
coopname: "String",
|
|
904
1059
|
created_at: "String",
|
|
905
1060
|
generator: "String",
|
|
906
|
-
lang: "
|
|
1061
|
+
lang: "String",
|
|
907
1062
|
links: "String",
|
|
908
1063
|
registry_id: "Int",
|
|
909
1064
|
timezone: "String",
|
|
@@ -1011,7 +1166,7 @@ const ReturnTypes = {
|
|
|
1011
1166
|
created_at: "String",
|
|
1012
1167
|
decision_id: "Float",
|
|
1013
1168
|
generator: "String",
|
|
1014
|
-
lang: "
|
|
1169
|
+
lang: "String",
|
|
1015
1170
|
links: "String",
|
|
1016
1171
|
registry_id: "Int",
|
|
1017
1172
|
timezone: "String",
|
|
@@ -1031,7 +1186,7 @@ const ReturnTypes = {
|
|
|
1031
1186
|
coopname: "String",
|
|
1032
1187
|
created_at: "String",
|
|
1033
1188
|
generator: "String",
|
|
1034
|
-
lang: "
|
|
1189
|
+
lang: "String",
|
|
1035
1190
|
links: "String",
|
|
1036
1191
|
registry_id: "Int",
|
|
1037
1192
|
timezone: "String",
|
|
@@ -1119,7 +1274,7 @@ const ReturnTypes = {
|
|
|
1119
1274
|
coopname: "String",
|
|
1120
1275
|
created_at: "String",
|
|
1121
1276
|
generator: "String",
|
|
1122
|
-
lang: "
|
|
1277
|
+
lang: "String",
|
|
1123
1278
|
links: "String",
|
|
1124
1279
|
project_id: "String",
|
|
1125
1280
|
registry_id: "Int",
|
|
@@ -1189,7 +1344,7 @@ const ReturnTypes = {
|
|
|
1189
1344
|
coopname: "String",
|
|
1190
1345
|
created_at: "String",
|
|
1191
1346
|
generator: "String",
|
|
1192
|
-
lang: "
|
|
1347
|
+
lang: "String",
|
|
1193
1348
|
links: "String",
|
|
1194
1349
|
registry_id: "Int",
|
|
1195
1350
|
timezone: "String",
|
|
@@ -1804,10 +1959,6 @@ var Country = /* @__PURE__ */ ((Country2) => {
|
|
|
1804
1959
|
Country2["Russia"] = "Russia";
|
|
1805
1960
|
return Country2;
|
|
1806
1961
|
})(Country || {});
|
|
1807
|
-
var LangType = /* @__PURE__ */ ((LangType2) => {
|
|
1808
|
-
LangType2["ru"] = "ru";
|
|
1809
|
-
return LangType2;
|
|
1810
|
-
})(LangType || {});
|
|
1811
1962
|
var OrganizationType = /* @__PURE__ */ ((OrganizationType2) => {
|
|
1812
1963
|
OrganizationType2["AO"] = "AO";
|
|
1813
1964
|
OrganizationType2["COOP"] = "COOP";
|
|
@@ -1848,7 +1999,7 @@ var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
|
1848
1999
|
return UserStatus2;
|
|
1849
2000
|
})(UserStatus || {});
|
|
1850
2001
|
|
|
1851
|
-
const index$
|
|
2002
|
+
const index$o = {
|
|
1852
2003
|
__proto__: null,
|
|
1853
2004
|
$: $,
|
|
1854
2005
|
AccountType: AccountType,
|
|
@@ -1861,7 +2012,6 @@ const index$k = {
|
|
|
1861
2012
|
HOST: HOST,
|
|
1862
2013
|
InternalArgsBuilt: InternalArgsBuilt,
|
|
1863
2014
|
InternalsBuildQuery: InternalsBuildQuery,
|
|
1864
|
-
LangType: LangType,
|
|
1865
2015
|
OrganizationType: OrganizationType,
|
|
1866
2016
|
PaymentStatus: PaymentStatus,
|
|
1867
2017
|
PrepareScalarPaths: PrepareScalarPaths,
|
|
@@ -1939,7 +2089,7 @@ const updateExtension = {
|
|
|
1939
2089
|
name: name$K
|
|
1940
2090
|
};
|
|
1941
2091
|
|
|
1942
|
-
const index$
|
|
2092
|
+
const index$n = {
|
|
1943
2093
|
__proto__: null,
|
|
1944
2094
|
InstallExtension: installExtension,
|
|
1945
2095
|
UninstallExtension: uninstallExtension,
|
|
@@ -2009,7 +2159,7 @@ const updateBankAccount = {
|
|
|
2009
2159
|
name: name$H
|
|
2010
2160
|
};
|
|
2011
2161
|
|
|
2012
|
-
const index$
|
|
2162
|
+
const index$m = {
|
|
2013
2163
|
__proto__: null,
|
|
2014
2164
|
CreateBankAccount: createBankAccount,
|
|
2015
2165
|
DeletePaymentMethod: deletePaymentMethod,
|
|
@@ -2575,7 +2725,7 @@ const selectBranch = {
|
|
|
2575
2725
|
|
|
2576
2726
|
const name$A = "generateSelectBranchDocument";
|
|
2577
2727
|
const mutation$q = Selector("Mutation")({
|
|
2578
|
-
[name$A]: [{ data: $("data", "SelectBranchGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2728
|
+
[name$A]: [{ data: $("data", "SelectBranchGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, generateSelectBranchDocumentSelector]
|
|
2579
2729
|
});
|
|
2580
2730
|
|
|
2581
2731
|
const generateSelectBranchDocument = {
|
|
@@ -2584,7 +2734,7 @@ const generateSelectBranchDocument = {
|
|
|
2584
2734
|
name: name$A
|
|
2585
2735
|
};
|
|
2586
2736
|
|
|
2587
|
-
const index$
|
|
2737
|
+
const index$l = {
|
|
2588
2738
|
__proto__: null,
|
|
2589
2739
|
AddTrustedAccount: addTrustedAccount,
|
|
2590
2740
|
CreateBranch: createBranch,
|
|
@@ -2607,7 +2757,7 @@ const projectFreeDecisionDocumentSelector = Selector("ProjectFreeDecisionDocumen
|
|
|
2607
2757
|
|
|
2608
2758
|
const name$z = "generateProjectOfFreeDecision";
|
|
2609
2759
|
const mutation$p = Selector("Mutation")({
|
|
2610
|
-
[name$z]: [{ data: $("data", "ProjectFreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2760
|
+
[name$z]: [{ data: $("data", "ProjectFreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, projectFreeDecisionDocumentSelector]
|
|
2611
2761
|
});
|
|
2612
2762
|
|
|
2613
2763
|
const generateProjectOfFreeDecisionDocument = {
|
|
@@ -2637,7 +2787,7 @@ const createdProjectFreeDecisionSelector = Selector("CreatedProjectFreeDecision"
|
|
|
2637
2787
|
|
|
2638
2788
|
const name$y = "generateFreeDecision";
|
|
2639
2789
|
const mutation$o = Selector("Mutation")({
|
|
2640
|
-
[name$y]: [{ data: $("data", "FreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2790
|
+
[name$y]: [{ data: $("data", "FreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, freeDecisionDocumentSelector]
|
|
2641
2791
|
});
|
|
2642
2792
|
|
|
2643
2793
|
const generateFreeDecision = {
|
|
@@ -2668,7 +2818,7 @@ const createProjectOfFreeDecision = {
|
|
|
2668
2818
|
name: name$w
|
|
2669
2819
|
};
|
|
2670
2820
|
|
|
2671
|
-
const index$
|
|
2821
|
+
const index$k = {
|
|
2672
2822
|
__proto__: null,
|
|
2673
2823
|
CreateProjectOfFreeDecision: createProjectOfFreeDecision,
|
|
2674
2824
|
GenerateFreeDecision: generateFreeDecision,
|
|
@@ -2736,7 +2886,7 @@ const resetKey = {
|
|
|
2736
2886
|
name: name$s
|
|
2737
2887
|
};
|
|
2738
2888
|
|
|
2739
|
-
const index$
|
|
2889
|
+
const index$j = {
|
|
2740
2890
|
__proto__: null,
|
|
2741
2891
|
RegisterAccount: registerAccount,
|
|
2742
2892
|
ResetKey: resetKey,
|
|
@@ -2777,7 +2927,7 @@ const login = {
|
|
|
2777
2927
|
name: name$p
|
|
2778
2928
|
};
|
|
2779
2929
|
|
|
2780
|
-
const index$
|
|
2930
|
+
const index$i = {
|
|
2781
2931
|
__proto__: null,
|
|
2782
2932
|
Login: login,
|
|
2783
2933
|
Logout: logout,
|
|
@@ -2828,7 +2978,7 @@ const updateSystem = {
|
|
|
2828
2978
|
name: name$l
|
|
2829
2979
|
};
|
|
2830
2980
|
|
|
2831
|
-
const index$
|
|
2981
|
+
const index$h = {
|
|
2832
2982
|
__proto__: null,
|
|
2833
2983
|
InitSystem: initSystem,
|
|
2834
2984
|
InstallSystem: installSystem,
|
|
@@ -2838,7 +2988,7 @@ const index$d = {
|
|
|
2838
2988
|
|
|
2839
2989
|
const name$k = "generateParticipantApplication";
|
|
2840
2990
|
const mutation$a = Selector("Mutation")({
|
|
2841
|
-
[name$k]: [{ data: $("data", "ParticipantApplicationGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2991
|
+
[name$k]: [{ data: $("data", "ParticipantApplicationGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, participantApplicationDocumentSelector]
|
|
2842
2992
|
});
|
|
2843
2993
|
|
|
2844
2994
|
const generateParticipantApplication = {
|
|
@@ -2849,7 +2999,7 @@ const generateParticipantApplication = {
|
|
|
2849
2999
|
|
|
2850
3000
|
const name$j = "generateParticipantApplicationDecision";
|
|
2851
3001
|
const mutation$9 = Selector("Mutation")({
|
|
2852
|
-
[name$j]: [{ data: $("data", "ParticipantApplicationDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3002
|
+
[name$j]: [{ data: $("data", "ParticipantApplicationDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, participantApplicationDecisionDocumentSelector]
|
|
2853
3003
|
});
|
|
2854
3004
|
|
|
2855
3005
|
const generateParticipantApplicationDecision = {
|
|
@@ -2880,7 +3030,7 @@ const addParticipant = {
|
|
|
2880
3030
|
name: name$h
|
|
2881
3031
|
};
|
|
2882
3032
|
|
|
2883
|
-
const index$
|
|
3033
|
+
const index$g = {
|
|
2884
3034
|
__proto__: null,
|
|
2885
3035
|
AddParticipant: addParticipant,
|
|
2886
3036
|
GenerateParticipantApplication: generateParticipantApplication,
|
|
@@ -2946,7 +3096,7 @@ const setPaymentStatus = {
|
|
|
2946
3096
|
name: name$e
|
|
2947
3097
|
};
|
|
2948
3098
|
|
|
2949
|
-
const index$
|
|
3099
|
+
const index$f = {
|
|
2950
3100
|
__proto__: null,
|
|
2951
3101
|
CreateDepositPayment: createDeposit,
|
|
2952
3102
|
CreateInitialPayment: createInitial,
|
|
@@ -2955,7 +3105,7 @@ const index$b = {
|
|
|
2955
3105
|
|
|
2956
3106
|
const name$d = "generatePrivacyAgreement";
|
|
2957
3107
|
const mutation$3 = Selector("Mutation")({
|
|
2958
|
-
[name$d]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3108
|
+
[name$d]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2959
3109
|
});
|
|
2960
3110
|
|
|
2961
3111
|
const generatePrivacyAgreement = {
|
|
@@ -2966,7 +3116,7 @@ const generatePrivacyAgreement = {
|
|
|
2966
3116
|
|
|
2967
3117
|
const name$c = "generateSignatureAgreement";
|
|
2968
3118
|
const mutation$2 = Selector("Mutation")({
|
|
2969
|
-
[name$c]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3119
|
+
[name$c]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2970
3120
|
});
|
|
2971
3121
|
|
|
2972
3122
|
const generateSignatureAgreement = {
|
|
@@ -2977,7 +3127,7 @@ const generateSignatureAgreement = {
|
|
|
2977
3127
|
|
|
2978
3128
|
const name$b = "generateWalletAgreement";
|
|
2979
3129
|
const mutation$1 = Selector("Mutation")({
|
|
2980
|
-
[name$b]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3130
|
+
[name$b]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2981
3131
|
});
|
|
2982
3132
|
|
|
2983
3133
|
const generateWalletAgreement = {
|
|
@@ -2988,7 +3138,7 @@ const generateWalletAgreement = {
|
|
|
2988
3138
|
|
|
2989
3139
|
const name$a = "generateUserAgreement";
|
|
2990
3140
|
const mutation = Selector("Mutation")({
|
|
2991
|
-
[name$a]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3141
|
+
[name$a]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2992
3142
|
});
|
|
2993
3143
|
|
|
2994
3144
|
const generateUserAgreement = {
|
|
@@ -2997,7 +3147,7 @@ const generateUserAgreement = {
|
|
|
2997
3147
|
name: name$a
|
|
2998
3148
|
};
|
|
2999
3149
|
|
|
3000
|
-
const index$
|
|
3150
|
+
const index$e = {
|
|
3001
3151
|
__proto__: null,
|
|
3002
3152
|
GeneratePrivacyAgreement: generatePrivacyAgreement,
|
|
3003
3153
|
GenerateSignatureAgreement: generateSignatureAgreement,
|
|
@@ -3007,16 +3157,16 @@ const index$a = {
|
|
|
3007
3157
|
|
|
3008
3158
|
const Mutations = {
|
|
3009
3159
|
__proto__: null,
|
|
3010
|
-
Accounts: index$
|
|
3011
|
-
Agreements: index$
|
|
3012
|
-
Auth: index$
|
|
3013
|
-
Branches: index$
|
|
3014
|
-
Extensions: index$
|
|
3015
|
-
FreeDecisions: index$
|
|
3016
|
-
Participants: index$
|
|
3017
|
-
PaymentMethods: index$
|
|
3018
|
-
Payments: index$
|
|
3019
|
-
System: index$
|
|
3160
|
+
Accounts: index$j,
|
|
3161
|
+
Agreements: index$e,
|
|
3162
|
+
Auth: index$i,
|
|
3163
|
+
Branches: index$l,
|
|
3164
|
+
Extensions: index$n,
|
|
3165
|
+
FreeDecisions: index$k,
|
|
3166
|
+
Participants: index$g,
|
|
3167
|
+
PaymentMethods: index$m,
|
|
3168
|
+
Payments: index$f,
|
|
3169
|
+
System: index$h
|
|
3020
3170
|
};
|
|
3021
3171
|
|
|
3022
3172
|
const name$9 = "getExtensions";
|
|
@@ -3030,7 +3180,7 @@ const getExtensions = {
|
|
|
3030
3180
|
query: query$9
|
|
3031
3181
|
};
|
|
3032
3182
|
|
|
3033
|
-
const index$
|
|
3183
|
+
const index$d = {
|
|
3034
3184
|
__proto__: null,
|
|
3035
3185
|
GetExtensions: getExtensions
|
|
3036
3186
|
};
|
|
@@ -3055,7 +3205,7 @@ const getPaymentMethods = {
|
|
|
3055
3205
|
query: query$8
|
|
3056
3206
|
};
|
|
3057
3207
|
|
|
3058
|
-
const index$
|
|
3208
|
+
const index$c = {
|
|
3059
3209
|
__proto__: null,
|
|
3060
3210
|
GetPaymentMethods: getPaymentMethods
|
|
3061
3211
|
};
|
|
@@ -3071,7 +3221,7 @@ const getSystemInfo = {
|
|
|
3071
3221
|
query: query$7
|
|
3072
3222
|
};
|
|
3073
3223
|
|
|
3074
|
-
const index$
|
|
3224
|
+
const index$b = {
|
|
3075
3225
|
__proto__: null,
|
|
3076
3226
|
GetSystemInfo: getSystemInfo
|
|
3077
3227
|
};
|
|
@@ -3101,7 +3251,7 @@ const getAccounts = {
|
|
|
3101
3251
|
query: query$5
|
|
3102
3252
|
};
|
|
3103
3253
|
|
|
3104
|
-
const index$
|
|
3254
|
+
const index$a = {
|
|
3105
3255
|
__proto__: null,
|
|
3106
3256
|
GetAccount: getAccount,
|
|
3107
3257
|
GetAccounts: getAccounts
|
|
@@ -3129,7 +3279,7 @@ const getPublicBranches = {
|
|
|
3129
3279
|
query: query$3
|
|
3130
3280
|
};
|
|
3131
3281
|
|
|
3132
|
-
const index$
|
|
3282
|
+
const index$9 = {
|
|
3133
3283
|
__proto__: null,
|
|
3134
3284
|
GetBranches: getBranches,
|
|
3135
3285
|
GetPublicBranches: getPublicBranches
|
|
@@ -3146,7 +3296,7 @@ const getPayments = {
|
|
|
3146
3296
|
query: query$2
|
|
3147
3297
|
};
|
|
3148
3298
|
|
|
3149
|
-
const index$
|
|
3299
|
+
const index$8 = {
|
|
3150
3300
|
__proto__: null,
|
|
3151
3301
|
GetPayments: getPayments
|
|
3152
3302
|
};
|
|
@@ -3210,7 +3360,7 @@ const getDocuments = {
|
|
|
3210
3360
|
query: query$1
|
|
3211
3361
|
};
|
|
3212
3362
|
|
|
3213
|
-
const index$
|
|
3363
|
+
const index$7 = {
|
|
3214
3364
|
__proto__: null,
|
|
3215
3365
|
GetDocuments: getDocuments
|
|
3216
3366
|
};
|
|
@@ -3261,75 +3411,101 @@ const getAgenda = {
|
|
|
3261
3411
|
query: query
|
|
3262
3412
|
};
|
|
3263
3413
|
|
|
3264
|
-
const index$
|
|
3414
|
+
const index$6 = {
|
|
3265
3415
|
__proto__: null,
|
|
3266
3416
|
GetAgenda: getAgenda
|
|
3267
3417
|
};
|
|
3268
3418
|
|
|
3269
|
-
const index$
|
|
3419
|
+
const index$5 = {
|
|
3270
3420
|
__proto__: null,
|
|
3271
|
-
Accounts: index$
|
|
3272
|
-
Agenda: index$
|
|
3273
|
-
Branches: index$
|
|
3274
|
-
Documents: index$
|
|
3275
|
-
Extensions: index$
|
|
3276
|
-
PaymentMethods: index$
|
|
3277
|
-
Payments: index$
|
|
3278
|
-
System: index$
|
|
3421
|
+
Accounts: index$a,
|
|
3422
|
+
Agenda: index$6,
|
|
3423
|
+
Branches: index$9,
|
|
3424
|
+
Documents: index$7,
|
|
3425
|
+
Extensions: index$d,
|
|
3426
|
+
PaymentMethods: index$c,
|
|
3427
|
+
Payments: index$8,
|
|
3428
|
+
System: index$b
|
|
3279
3429
|
};
|
|
3280
3430
|
|
|
3281
|
-
const index = {
|
|
3431
|
+
const index$4 = {
|
|
3432
|
+
__proto__: null
|
|
3433
|
+
};
|
|
3434
|
+
|
|
3435
|
+
const index$3 = {
|
|
3282
3436
|
__proto__: null
|
|
3283
3437
|
};
|
|
3284
3438
|
|
|
3439
|
+
const index$2 = {
|
|
3440
|
+
__proto__: null
|
|
3441
|
+
};
|
|
3442
|
+
|
|
3443
|
+
const index$1 = {
|
|
3444
|
+
__proto__: null
|
|
3445
|
+
};
|
|
3446
|
+
|
|
3447
|
+
const index = {
|
|
3448
|
+
__proto__: null,
|
|
3449
|
+
Blockchain: index$4,
|
|
3450
|
+
Client: index$3,
|
|
3451
|
+
Controller: index$2,
|
|
3452
|
+
Document: index$1
|
|
3453
|
+
};
|
|
3454
|
+
|
|
3455
|
+
var __defProp = Object.defineProperty;
|
|
3456
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3457
|
+
var __publicField = (obj, key, value) => {
|
|
3458
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3459
|
+
return value;
|
|
3460
|
+
};
|
|
3285
3461
|
if (typeof globalThis.WebSocket === "undefined") {
|
|
3286
3462
|
globalThis.WebSocket = WebSocket__default;
|
|
3287
3463
|
}
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3464
|
+
const _Client = class _Client {
|
|
3465
|
+
constructor(options) {
|
|
3466
|
+
this.options = options;
|
|
3467
|
+
__publicField(this, "currentHeaders", {});
|
|
3468
|
+
__publicField(this, "blockchain");
|
|
3469
|
+
__publicField(this, "document");
|
|
3470
|
+
__publicField(this, "thunder");
|
|
3471
|
+
this.currentHeaders = options.headers || {};
|
|
3472
|
+
this.thunder = _Client.createThunder(options.api_url);
|
|
3473
|
+
this.blockchain = new Blockchain(options);
|
|
3474
|
+
this.document = new Document(options.wif);
|
|
3475
|
+
if (options.wif && options.username) {
|
|
3476
|
+
this.blockchain.setWif(options.username, options.wif);
|
|
3477
|
+
this.document.setWif(options.wif);
|
|
3478
|
+
} else if (options.wif && !options.username || !options.wif && options.username) {
|
|
3479
|
+
throw new Error("wif \u0438 username \u0434\u043E\u043B\u0436\u043D\u044B \u0431\u044B\u0442\u044C \u0443\u043A\u0430\u0437\u0430\u043D\u044B \u043E\u0434\u043D\u043E\u0432\u0440\u0435\u043C\u0435\u043D\u043D\u043E");
|
|
3480
|
+
}
|
|
3295
3481
|
}
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
"Content-Type": "application/json",
|
|
3304
|
-
...currentHeaders
|
|
3305
|
-
// Используем текущие заголовки, включая Authorization
|
|
3306
|
-
}
|
|
3307
|
-
});
|
|
3308
|
-
if (!response.ok) {
|
|
3309
|
-
return new Promise((resolve, reject) => {
|
|
3310
|
-
response.text().then((text) => {
|
|
3311
|
-
try {
|
|
3312
|
-
reject(JSON.parse(text));
|
|
3313
|
-
} catch (err) {
|
|
3314
|
-
reject(text);
|
|
3315
|
-
}
|
|
3316
|
-
}).catch(reject);
|
|
3317
|
-
});
|
|
3482
|
+
/**
|
|
3483
|
+
* Инициализация клиента с заданными опциями.
|
|
3484
|
+
* @param options Параметры соединения.
|
|
3485
|
+
*/
|
|
3486
|
+
static create(options) {
|
|
3487
|
+
if (!this.instance) {
|
|
3488
|
+
this.instance = new _Client(options);
|
|
3318
3489
|
}
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3490
|
+
return this.getInstance();
|
|
3491
|
+
}
|
|
3492
|
+
/**
|
|
3493
|
+
* Возвращает текущий экземпляр клиента.
|
|
3494
|
+
*/
|
|
3495
|
+
static getInstance() {
|
|
3496
|
+
if (!this.instance) {
|
|
3497
|
+
throw new Error("\u041A\u043B\u0438\u0435\u043D\u0442 \u043D\u0435 \u0438\u043D\u0438\u0446\u0438\u0430\u043B\u0438\u0437\u0438\u0440\u043E\u0432\u0430\u043D. \u0412\u044B\u0437\u043E\u0432\u0438\u0442\u0435 Client.create() \u043F\u0435\u0440\u0435\u0434 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u043D\u0438\u0435\u043C.");
|
|
3323
3498
|
}
|
|
3324
|
-
return
|
|
3325
|
-
}
|
|
3326
|
-
|
|
3327
|
-
|
|
3328
|
-
|
|
3329
|
-
|
|
3330
|
-
|
|
3331
|
-
|
|
3332
|
-
|
|
3499
|
+
return this.instance;
|
|
3500
|
+
}
|
|
3501
|
+
/**
|
|
3502
|
+
* Логин пользователя с использованием email и WIF.
|
|
3503
|
+
* @param email Email пользователя.
|
|
3504
|
+
* @param wif Приватный ключ в формате WIF.
|
|
3505
|
+
* @returns Результат логина.
|
|
3506
|
+
*/
|
|
3507
|
+
async login(email, wif) {
|
|
3508
|
+
const now = (await this.blockchain.getInfo()).head_block_time.toString();
|
|
3333
3509
|
const privateKey = session.PrivateKey.fromString(wif);
|
|
3334
3510
|
const bytes = session.Bytes.fromString(now, "utf8");
|
|
3335
3511
|
const checksum = session.Checksum256.hash(bytes);
|
|
@@ -3341,35 +3517,104 @@ function createClient(options) {
|
|
|
3341
3517
|
signature
|
|
3342
3518
|
}
|
|
3343
3519
|
};
|
|
3344
|
-
const { [name$p]: result } = await thunder("mutation")(
|
|
3520
|
+
const { [name$p]: result } = await this.thunder("mutation")(
|
|
3345
3521
|
mutation$f,
|
|
3346
3522
|
{
|
|
3347
3523
|
variables
|
|
3348
3524
|
}
|
|
3349
3525
|
);
|
|
3350
|
-
|
|
3526
|
+
const username = result.account.username;
|
|
3527
|
+
this.blockchain.setWif(username, wif);
|
|
3528
|
+
this.document.setWif(wif);
|
|
3529
|
+
this.currentHeaders.Authorization = `Bearer ${result.tokens.access.token}`;
|
|
3351
3530
|
return result;
|
|
3352
3531
|
}
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3532
|
+
/**
|
|
3533
|
+
* Установка токена авторизации.
|
|
3534
|
+
* @param token Токен для заголовков Authorization.
|
|
3535
|
+
*/
|
|
3536
|
+
setToken(token) {
|
|
3537
|
+
this.currentHeaders.Authorization = `Bearer ${token}`;
|
|
3357
3538
|
}
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3539
|
+
/**
|
|
3540
|
+
* Доступ к Blockchain.
|
|
3541
|
+
*/
|
|
3542
|
+
get Blockchain() {
|
|
3543
|
+
return this.blockchain;
|
|
3544
|
+
}
|
|
3545
|
+
/**
|
|
3546
|
+
* Доступ к Document.
|
|
3547
|
+
*/
|
|
3548
|
+
get Document() {
|
|
3549
|
+
return this.document;
|
|
3550
|
+
}
|
|
3551
|
+
/**
|
|
3552
|
+
* Доступ к GraphQL-запросам.
|
|
3553
|
+
*/
|
|
3554
|
+
get Query() {
|
|
3555
|
+
return this.thunder("query");
|
|
3556
|
+
}
|
|
3557
|
+
/**
|
|
3558
|
+
* Доступ к GraphQL-мутациям.
|
|
3559
|
+
*/
|
|
3560
|
+
get Mutation() {
|
|
3561
|
+
return this.thunder("mutation");
|
|
3562
|
+
}
|
|
3563
|
+
/**
|
|
3564
|
+
* Подписка на GraphQL-события.
|
|
3565
|
+
*/
|
|
3566
|
+
get Subscription() {
|
|
3567
|
+
return Subscription(this.options.api_url.replace(/^http/, "ws"));
|
|
3568
|
+
}
|
|
3569
|
+
/**
|
|
3570
|
+
* Создает функцию Thunder для выполнения GraphQL-запросов.
|
|
3571
|
+
* @param baseUrl URL GraphQL API.
|
|
3572
|
+
* @returns Функция Thunder.
|
|
3573
|
+
*/
|
|
3574
|
+
static createThunder(baseUrl) {
|
|
3575
|
+
return Thunder(async (query, variables) => {
|
|
3576
|
+
const response = await fetch(baseUrl, {
|
|
3577
|
+
body: JSON.stringify({ query, variables }),
|
|
3578
|
+
method: "POST",
|
|
3579
|
+
headers: {
|
|
3580
|
+
"Content-Type": "application/json",
|
|
3581
|
+
..._Client.getInstance().currentHeaders
|
|
3582
|
+
}
|
|
3583
|
+
});
|
|
3584
|
+
if (!response.ok) {
|
|
3585
|
+
return new Promise((resolve, reject) => {
|
|
3586
|
+
response.text().then((text) => {
|
|
3587
|
+
try {
|
|
3588
|
+
reject(JSON.parse(text));
|
|
3589
|
+
} catch {
|
|
3590
|
+
reject(text);
|
|
3591
|
+
}
|
|
3592
|
+
}).catch(reject);
|
|
3593
|
+
});
|
|
3594
|
+
}
|
|
3595
|
+
const json = await response.json();
|
|
3596
|
+
if (json.errors) {
|
|
3597
|
+
console.log("json.errors", json.errors);
|
|
3598
|
+
throw json.errors;
|
|
3599
|
+
}
|
|
3600
|
+
return json.data;
|
|
3601
|
+
}, { scalars: _Client.scalars });
|
|
3602
|
+
}
|
|
3603
|
+
};
|
|
3604
|
+
__publicField(_Client, "instance", null);
|
|
3605
|
+
__publicField(_Client, "scalars", ZeusScalars({
|
|
3606
|
+
DateTime: {
|
|
3607
|
+
decode: (e) => new Date(e),
|
|
3608
|
+
// Преобразует строку в объект Date
|
|
3609
|
+
encode: (e) => e.toISOString()
|
|
3610
|
+
// Преобразует Date в ISO-строку
|
|
3611
|
+
}
|
|
3612
|
+
}));
|
|
3613
|
+
let Client = _Client;
|
|
3369
3614
|
|
|
3370
3615
|
exports.Classes = Classes;
|
|
3616
|
+
exports.Client = Client;
|
|
3371
3617
|
exports.Mutations = Mutations;
|
|
3372
|
-
exports.Queries = index$
|
|
3618
|
+
exports.Queries = index$5;
|
|
3373
3619
|
exports.Types = index;
|
|
3374
|
-
exports.Zeus = index$
|
|
3375
|
-
exports.createClient = createClient;
|
|
3620
|
+
exports.Zeus = index$o;
|