@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.mjs
CHANGED
|
@@ -3,19 +3,19 @@ import WebSocket from 'isomorphic-ws';
|
|
|
3
3
|
import { PrivateKey, APIClient, Action } from '@wharfkit/antelope';
|
|
4
4
|
import { ContractKit, Table } from '@wharfkit/contract';
|
|
5
5
|
import { WalletPluginPrivateKey } from '@wharfkit/wallet-plugin-privatekey';
|
|
6
|
-
import { createClient
|
|
6
|
+
import { createClient } from 'graphql-ws';
|
|
7
7
|
|
|
8
|
-
var __defProp$
|
|
9
|
-
var __defNormalProp$
|
|
10
|
-
var __publicField$
|
|
11
|
-
__defNormalProp$
|
|
8
|
+
var __defProp$4 = Object.defineProperty;
|
|
9
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __publicField$4 = (obj, key, value) => {
|
|
11
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
12
12
|
return value;
|
|
13
13
|
};
|
|
14
14
|
class Account {
|
|
15
15
|
constructor() {
|
|
16
|
-
__publicField$
|
|
17
|
-
__publicField$
|
|
18
|
-
__publicField$
|
|
16
|
+
__publicField$4(this, "username");
|
|
17
|
+
__publicField$4(this, "private_key");
|
|
18
|
+
__publicField$4(this, "public_key");
|
|
19
19
|
this.username = Account.generateUsername();
|
|
20
20
|
const keys = Account.generateKeys();
|
|
21
21
|
this.private_key = keys.private_key;
|
|
@@ -48,118 +48,43 @@ class Account {
|
|
|
48
48
|
}
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
var __defProp$
|
|
52
|
-
var __defNormalProp$
|
|
53
|
-
var __publicField$
|
|
54
|
-
__defNormalProp$
|
|
51
|
+
var __defProp$3 = Object.defineProperty;
|
|
52
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
53
|
+
var __publicField$3 = (obj, key, value) => {
|
|
54
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
55
55
|
return value;
|
|
56
56
|
};
|
|
57
|
-
class
|
|
58
|
-
/**
|
|
59
|
-
* Создаёт элемент `<canvas>` внутри указанного контейнера.
|
|
60
|
-
* @param container - HTML-элемент, внутри которого создаётся canvas.
|
|
61
|
-
* @param width - Ширина canvas (по умолчанию 300).
|
|
62
|
-
* @param height - Высота canvas (по умолчанию 150).
|
|
63
|
-
*/
|
|
64
|
-
constructor(container, width = 300, height = 150) {
|
|
65
|
-
__publicField$1(this, "canvas");
|
|
66
|
-
__publicField$1(this, "ctx");
|
|
67
|
-
__publicField$1(this, "state", {
|
|
68
|
-
drawing: false,
|
|
69
|
-
lastX: 0,
|
|
70
|
-
lastY: 0
|
|
71
|
-
});
|
|
72
|
-
this.canvas = document.createElement("canvas");
|
|
73
|
-
this.canvas.width = width;
|
|
74
|
-
this.canvas.height = height;
|
|
75
|
-
container.appendChild(this.canvas);
|
|
76
|
-
this.ctx = this.canvas.getContext("2d");
|
|
77
|
-
this.ctx.lineWidth = 5;
|
|
78
|
-
this.ctx.lineJoin = "round";
|
|
79
|
-
this.ctx.lineCap = "round";
|
|
80
|
-
this.ctx.strokeStyle = "#000";
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Полностью очищает canvas.
|
|
84
|
-
*/
|
|
85
|
-
clearCanvas() {
|
|
86
|
-
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Запускает процесс рисования (фиксирует начальные координаты).
|
|
90
|
-
* @param e - Событие мыши или касания.
|
|
91
|
-
*/
|
|
92
|
-
startDrawing(e) {
|
|
93
|
-
e.preventDefault();
|
|
94
|
-
this.state.drawing = true;
|
|
95
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
96
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
97
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
98
|
-
this.state.lastX = clientX - rect.left;
|
|
99
|
-
this.state.lastY = clientY - rect.top;
|
|
100
|
-
}
|
|
57
|
+
class Blockchain {
|
|
101
58
|
/**
|
|
102
|
-
*
|
|
103
|
-
* @param
|
|
59
|
+
* Конструктор класса Blockchain.
|
|
60
|
+
* @param config Конфигурация блокчейна, включающая URL цепочки и идентификатор цепочки.
|
|
104
61
|
*/
|
|
105
|
-
draw(e) {
|
|
106
|
-
if (!this.state.drawing)
|
|
107
|
-
return;
|
|
108
|
-
e.preventDefault();
|
|
109
|
-
this.ctx.beginPath();
|
|
110
|
-
this.ctx.moveTo(this.state.lastX, this.state.lastY);
|
|
111
|
-
const rect = this.canvas.getBoundingClientRect();
|
|
112
|
-
const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
|
|
113
|
-
const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
|
|
114
|
-
const x = clientX - rect.left;
|
|
115
|
-
const y = clientY - rect.top;
|
|
116
|
-
this.ctx.lineTo(x, y);
|
|
117
|
-
this.ctx.stroke();
|
|
118
|
-
this.state.lastX = x;
|
|
119
|
-
this.state.lastY = y;
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Завершает процесс рисования (drawing = false).
|
|
123
|
-
*/
|
|
124
|
-
endDrawing() {
|
|
125
|
-
this.state.drawing = false;
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Возвращает текущее содержимое canvas в формате base64 (PNG).
|
|
129
|
-
*/
|
|
130
|
-
getSignature() {
|
|
131
|
-
return this.canvas.toDataURL("image/png");
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
var __defProp = Object.defineProperty;
|
|
136
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
137
|
-
var __publicField = (obj, key, value) => {
|
|
138
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
139
|
-
return value;
|
|
140
|
-
};
|
|
141
|
-
class Wallet {
|
|
142
62
|
constructor(config) {
|
|
143
63
|
this.config = config;
|
|
144
|
-
__publicField(this, "apiClient");
|
|
145
|
-
__publicField(this, "contractKit");
|
|
146
|
-
__publicField(this, "session");
|
|
64
|
+
__publicField$3(this, "apiClient");
|
|
65
|
+
__publicField$3(this, "contractKit");
|
|
66
|
+
__publicField$3(this, "session");
|
|
147
67
|
this.apiClient = new APIClient({ url: config.chain_url });
|
|
148
68
|
this.contractKit = new ContractKit({ client: this.apiClient });
|
|
149
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Получение информации о блокчейне.
|
|
72
|
+
* @returns Объект с информацией о текущем состоянии блокчейна.
|
|
73
|
+
*/
|
|
150
74
|
async getInfo() {
|
|
151
75
|
return this.apiClient.v1.chain.get_info();
|
|
152
76
|
}
|
|
153
77
|
/**
|
|
154
|
-
*
|
|
155
|
-
* @param username
|
|
156
|
-
* @param wif
|
|
157
|
-
* @
|
|
78
|
+
* Устанавливает приватный ключ (WIF) для текущей сессии.
|
|
79
|
+
* @param username Имя пользователя (аккаунт).
|
|
80
|
+
* @param wif Приватный ключ в формате WIF.
|
|
81
|
+
* @param permission Тип разрешения, который используется для подписания транзакции (по умолчанию = 'active')
|
|
82
|
+
* @returns Текущий экземпляр Blockchain для цепочного вызова.
|
|
158
83
|
*/
|
|
159
|
-
setWif(username, wif) {
|
|
84
|
+
setWif(username, wif, permission = "active") {
|
|
160
85
|
this.session = new Session({
|
|
161
86
|
actor: username,
|
|
162
|
-
permission
|
|
87
|
+
permission,
|
|
163
88
|
chain: {
|
|
164
89
|
id: this.config.chain_id,
|
|
165
90
|
url: this.config.chain_url
|
|
@@ -168,18 +93,40 @@ class Wallet {
|
|
|
168
93
|
});
|
|
169
94
|
return this;
|
|
170
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Выполнение транзакции с передачей одного или нескольких действий.
|
|
98
|
+
* @param actionOrActions Действие или массив действий для выполнения.
|
|
99
|
+
* @param broadcast Если true, транзакция будет отправлена в сеть.
|
|
100
|
+
* @returns Результат выполнения транзакции.
|
|
101
|
+
* @throws Ошибка, если сессия не инициализирована.
|
|
102
|
+
*/
|
|
171
103
|
async transact(actionOrActions, broadcast = true) {
|
|
172
104
|
if (!this.session)
|
|
173
|
-
throw new Error("
|
|
105
|
+
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.");
|
|
174
106
|
const actions = Array.isArray(actionOrActions) ? await Promise.all(actionOrActions.map((action) => this.formActionFromAbi(action))) : [await this.formActionFromAbi(actionOrActions)];
|
|
175
107
|
return this.session.transact({ actions }, { broadcast });
|
|
176
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* Получение всех строк таблицы смарт-контракта.
|
|
111
|
+
* @param code Код (аккаунт) контракта.
|
|
112
|
+
* @param scope Область видимости (scope) таблицы.
|
|
113
|
+
* @param tableName Имя таблицы.
|
|
114
|
+
* @returns Массив строк таблицы.
|
|
115
|
+
*/
|
|
177
116
|
async getAllRows(code, scope, tableName) {
|
|
178
117
|
const abi = await this.getAbi(code);
|
|
179
118
|
const table = this.createTable(code, tableName, abi);
|
|
180
119
|
const rows = await table.all({ scope });
|
|
181
120
|
return JSON.parse(JSON.stringify(rows));
|
|
182
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Запрос строк таблицы с использованием фильтров.
|
|
124
|
+
* @param code Код (аккаунт) контракта.
|
|
125
|
+
* @param scope Область видимости (scope) таблицы.
|
|
126
|
+
* @param tableName Имя таблицы.
|
|
127
|
+
* @param options Опции для фильтрации данных.
|
|
128
|
+
* @returns Массив строк, соответствующих фильтрам.
|
|
129
|
+
*/
|
|
183
130
|
async query(code, scope, tableName, options = { indexPosition: "primary" }) {
|
|
184
131
|
const { indexPosition = "primary", from, to, maxRows } = options;
|
|
185
132
|
const abi = await this.getAbi(code);
|
|
@@ -193,6 +140,15 @@ class Wallet {
|
|
|
193
140
|
});
|
|
194
141
|
return JSON.parse(JSON.stringify(rows));
|
|
195
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Получение одной строки таблицы по первичному ключу.
|
|
145
|
+
* @param code Код (аккаунт) контракта.
|
|
146
|
+
* @param scope Область видимости (scope) таблицы.
|
|
147
|
+
* @param tableName Имя таблицы.
|
|
148
|
+
* @param primaryKey Первичный ключ строки.
|
|
149
|
+
* @param indexPosition Индекс для поиска строки (по умолчанию 'primary').
|
|
150
|
+
* @returns Строка таблицы или null, если не найдена.
|
|
151
|
+
*/
|
|
196
152
|
async getRow(code, scope, tableName, primaryKey, indexPosition = "primary") {
|
|
197
153
|
const abi = await this.getAbi(code);
|
|
198
154
|
const table = this.createTable(code, tableName, abi);
|
|
@@ -202,16 +158,34 @@ class Wallet {
|
|
|
202
158
|
});
|
|
203
159
|
return row ? JSON.parse(JSON.stringify(row)) : null;
|
|
204
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* Создает объект действия (Action) из ABI контракта.
|
|
163
|
+
* @param action Объект действия.
|
|
164
|
+
* @returns Объект Action.
|
|
165
|
+
*/
|
|
205
166
|
async formActionFromAbi(action) {
|
|
206
167
|
const abi = await this.getAbi(action.account);
|
|
207
168
|
return Action.from(action, abi);
|
|
208
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Получение ABI контракта.
|
|
172
|
+
* @param account Код (аккаунт) контракта.
|
|
173
|
+
* @returns ABI контракта.
|
|
174
|
+
* @throws Ошибка, если ABI не найден.
|
|
175
|
+
*/
|
|
209
176
|
async getAbi(account) {
|
|
210
177
|
const { abi } = await this.apiClient.v1.chain.get_abi(account);
|
|
211
178
|
if (!abi)
|
|
212
|
-
throw new Error(`ABI
|
|
179
|
+
throw new Error(`ABI \u0434\u043B\u044F \u0430\u043A\u043A\u0430\u0443\u043D\u0442\u0430 "${account}" \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D.`);
|
|
213
180
|
return abi;
|
|
214
181
|
}
|
|
182
|
+
/**
|
|
183
|
+
* Создает объект таблицы (Table) для работы с данными.
|
|
184
|
+
* @param code Код (аккаунт) контракта.
|
|
185
|
+
* @param tableName Имя таблицы.
|
|
186
|
+
* @param abi ABI контракта.
|
|
187
|
+
* @returns Объект Table.
|
|
188
|
+
*/
|
|
215
189
|
createTable(code, tableName, abi) {
|
|
216
190
|
return new Table({
|
|
217
191
|
abi,
|
|
@@ -222,11 +196,193 @@ class Wallet {
|
|
|
222
196
|
}
|
|
223
197
|
}
|
|
224
198
|
|
|
199
|
+
var __defProp$2 = Object.defineProperty;
|
|
200
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
201
|
+
var __publicField$2 = (obj, key, value) => {
|
|
202
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
203
|
+
return value;
|
|
204
|
+
};
|
|
205
|
+
class Canvas {
|
|
206
|
+
/**
|
|
207
|
+
* Создаёт экземпляр класса `Canvas` и подготавливает холст для рисования подписи.
|
|
208
|
+
*
|
|
209
|
+
* @param container - HTML-элемент, внутри которого создаётся `<canvas>`.
|
|
210
|
+
* @param opts - Настройки:
|
|
211
|
+
* - `lineWidth` - Толщина линии для рисования (по умолчанию 5).
|
|
212
|
+
* - `strokeStyle` - Цвет линии для рисования (по умолчанию чёрный, `#000`).
|
|
213
|
+
*/
|
|
214
|
+
constructor(container, opts = {}) {
|
|
215
|
+
this.container = container;
|
|
216
|
+
this.opts = opts;
|
|
217
|
+
__publicField$2(this, "canvas");
|
|
218
|
+
__publicField$2(this, "ctx");
|
|
219
|
+
__publicField$2(this, "drawing", false);
|
|
220
|
+
__publicField$2(this, "lastX", 0);
|
|
221
|
+
__publicField$2(this, "lastY", 0);
|
|
222
|
+
__publicField$2(this, "onMouseDown", (e) => {
|
|
223
|
+
e.preventDefault();
|
|
224
|
+
this.drawing = true;
|
|
225
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
226
|
+
this.lastX = e.clientX - rect.left;
|
|
227
|
+
this.lastY = e.clientY - rect.top;
|
|
228
|
+
});
|
|
229
|
+
__publicField$2(this, "onMouseMove", (e) => {
|
|
230
|
+
if (!this.drawing)
|
|
231
|
+
return;
|
|
232
|
+
e.preventDefault();
|
|
233
|
+
this.drawLine(e.clientX, e.clientY);
|
|
234
|
+
});
|
|
235
|
+
__publicField$2(this, "onMouseUp", () => {
|
|
236
|
+
this.drawing = false;
|
|
237
|
+
});
|
|
238
|
+
__publicField$2(this, "onTouchStart", (e) => {
|
|
239
|
+
e.preventDefault();
|
|
240
|
+
this.drawing = true;
|
|
241
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
242
|
+
const t = e.touches[0];
|
|
243
|
+
this.lastX = t.clientX - rect.left;
|
|
244
|
+
this.lastY = t.clientY - rect.top;
|
|
245
|
+
});
|
|
246
|
+
__publicField$2(this, "onTouchMove", (e) => {
|
|
247
|
+
if (!this.drawing)
|
|
248
|
+
return;
|
|
249
|
+
e.preventDefault();
|
|
250
|
+
const t = e.touches[0];
|
|
251
|
+
this.drawLine(t.clientX, t.clientY);
|
|
252
|
+
});
|
|
253
|
+
__publicField$2(this, "onTouchEnd", () => {
|
|
254
|
+
this.drawing = false;
|
|
255
|
+
});
|
|
256
|
+
this.canvas = document.createElement("canvas");
|
|
257
|
+
this.canvas.width = container.offsetWidth;
|
|
258
|
+
this.canvas.height = container.offsetHeight;
|
|
259
|
+
this.canvas.style.touchAction = "none";
|
|
260
|
+
container.appendChild(this.canvas);
|
|
261
|
+
const ctx = this.canvas.getContext("2d");
|
|
262
|
+
if (!ctx) {
|
|
263
|
+
throw new Error("Canvas \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044F");
|
|
264
|
+
}
|
|
265
|
+
this.ctx = ctx;
|
|
266
|
+
this.ctx.lineWidth = this.opts.lineWidth ?? 5;
|
|
267
|
+
this.ctx.lineJoin = "round";
|
|
268
|
+
this.ctx.lineCap = "round";
|
|
269
|
+
this.ctx.strokeStyle = this.opts.strokeStyle ?? "#000";
|
|
270
|
+
this.initEvents();
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Очищает холст.
|
|
274
|
+
*/
|
|
275
|
+
clearCanvas() {
|
|
276
|
+
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Возвращает содержимое холста (подпись) в формате base64 (PNG).
|
|
280
|
+
*
|
|
281
|
+
* @returns Подпись в формате base64.
|
|
282
|
+
*/
|
|
283
|
+
getSignature() {
|
|
284
|
+
return this.canvas.toDataURL("image/png");
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Снимает все обработчики событий и очищает ресурсы.
|
|
288
|
+
*/
|
|
289
|
+
destroy() {
|
|
290
|
+
this.canvas.removeEventListener("mousedown", this.onMouseDown);
|
|
291
|
+
this.canvas.removeEventListener("mousemove", this.onMouseMove);
|
|
292
|
+
this.canvas.removeEventListener("mouseup", this.onMouseUp);
|
|
293
|
+
this.canvas.removeEventListener("touchstart", this.onTouchStart);
|
|
294
|
+
this.canvas.removeEventListener("touchmove", this.onTouchMove);
|
|
295
|
+
this.canvas.removeEventListener("touchend", this.onTouchEnd);
|
|
296
|
+
}
|
|
297
|
+
// Внутренние методы
|
|
298
|
+
/**
|
|
299
|
+
* Навешивает обработчики событий мыши и тач-устройств.
|
|
300
|
+
*/
|
|
301
|
+
initEvents() {
|
|
302
|
+
this.canvas.addEventListener("mousedown", this.onMouseDown);
|
|
303
|
+
this.canvas.addEventListener("mousemove", this.onMouseMove);
|
|
304
|
+
this.canvas.addEventListener("mouseup", this.onMouseUp);
|
|
305
|
+
this.canvas.addEventListener("touchstart", this.onTouchStart, { passive: false });
|
|
306
|
+
this.canvas.addEventListener("touchmove", this.onTouchMove, { passive: false });
|
|
307
|
+
this.canvas.addEventListener("touchend", this.onTouchEnd, { passive: false });
|
|
308
|
+
}
|
|
309
|
+
drawLine(clientX, clientY) {
|
|
310
|
+
this.ctx.beginPath();
|
|
311
|
+
this.ctx.moveTo(this.lastX, this.lastY);
|
|
312
|
+
const rect = this.canvas.getBoundingClientRect();
|
|
313
|
+
const x = clientX - rect.left;
|
|
314
|
+
const y = clientY - rect.top;
|
|
315
|
+
this.ctx.lineTo(x, y);
|
|
316
|
+
this.ctx.stroke();
|
|
317
|
+
this.lastX = x;
|
|
318
|
+
this.lastY = y;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
var __defProp$1 = Object.defineProperty;
|
|
323
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
324
|
+
var __publicField$1 = (obj, key, value) => {
|
|
325
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
326
|
+
return value;
|
|
327
|
+
};
|
|
328
|
+
class Document {
|
|
329
|
+
/**
|
|
330
|
+
* Инициализация класса Document с WIF-ключом.
|
|
331
|
+
* @param wifKey WIF-ключ, используемый для подписи.
|
|
332
|
+
*/
|
|
333
|
+
constructor(wifKey) {
|
|
334
|
+
__publicField$1(this, "wif");
|
|
335
|
+
if (wifKey)
|
|
336
|
+
this.wif = PrivateKey.fromString(wifKey);
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Замена текущего WIF-ключа на новый.
|
|
340
|
+
* @param wifKey Новый WIF-ключ.
|
|
341
|
+
*/
|
|
342
|
+
setWif(wifKey) {
|
|
343
|
+
this.wif = PrivateKey.fromString(wifKey);
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Подписывает документ и возвращает его в формате ISignedDocument.
|
|
347
|
+
* @param document Сгенерированный документ для подписи.
|
|
348
|
+
* @returns Подписанный документ.
|
|
349
|
+
*/
|
|
350
|
+
async signDocument(document) {
|
|
351
|
+
const digitalSignature = this.signDigest(document.hash);
|
|
352
|
+
return {
|
|
353
|
+
hash: document.hash,
|
|
354
|
+
public_key: digitalSignature.public_key,
|
|
355
|
+
signature: digitalSignature.signature,
|
|
356
|
+
meta: document.meta
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* Подписывает хэш (digest) документа и проверяет подпись.
|
|
361
|
+
* @param digest Хэш документа для подписи.
|
|
362
|
+
* @returns Детали подписи.
|
|
363
|
+
*/
|
|
364
|
+
signDigest(digest) {
|
|
365
|
+
if (!this.wif)
|
|
366
|
+
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`);
|
|
367
|
+
const signed = this.wif.signDigest(digest);
|
|
368
|
+
const verified = signed.verifyDigest(digest, this.wif.toPublic());
|
|
369
|
+
if (!verified) {
|
|
370
|
+
throw new Error("\u041E\u0448\u0438\u0431\u043A\u0430 \u043F\u0440\u043E\u0432\u0435\u0440\u043A\u0438 \u043F\u043E\u0434\u043F\u0438\u0441\u0438");
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
message: digest,
|
|
374
|
+
signature: signed.toString(),
|
|
375
|
+
public_key: this.wif.toPublic().toString()
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
225
380
|
const Classes = {
|
|
226
381
|
__proto__: null,
|
|
227
382
|
Account: Account,
|
|
383
|
+
Blockchain: Blockchain,
|
|
228
384
|
Canvas: Canvas,
|
|
229
|
-
|
|
385
|
+
Document: Document
|
|
230
386
|
};
|
|
231
387
|
|
|
232
388
|
const AllTypesProps = {
|
|
@@ -302,7 +458,6 @@ const AllTypesProps = {
|
|
|
302
458
|
soviet: "SovietMemberInput"
|
|
303
459
|
},
|
|
304
460
|
JSON: `scalar.JSON`,
|
|
305
|
-
LangType: "enum",
|
|
306
461
|
LoginInput: {},
|
|
307
462
|
LogoutInput: {},
|
|
308
463
|
MetaDocumentInput: {},
|
|
@@ -860,7 +1015,7 @@ const ReturnTypes = {
|
|
|
860
1015
|
created_at: "String",
|
|
861
1016
|
decision_id: "Float",
|
|
862
1017
|
generator: "String",
|
|
863
|
-
lang: "
|
|
1018
|
+
lang: "String",
|
|
864
1019
|
links: "String",
|
|
865
1020
|
project_id: "String",
|
|
866
1021
|
registry_id: "Int",
|
|
@@ -897,7 +1052,7 @@ const ReturnTypes = {
|
|
|
897
1052
|
coopname: "String",
|
|
898
1053
|
created_at: "String",
|
|
899
1054
|
generator: "String",
|
|
900
|
-
lang: "
|
|
1055
|
+
lang: "String",
|
|
901
1056
|
links: "String",
|
|
902
1057
|
registry_id: "Int",
|
|
903
1058
|
timezone: "String",
|
|
@@ -1005,7 +1160,7 @@ const ReturnTypes = {
|
|
|
1005
1160
|
created_at: "String",
|
|
1006
1161
|
decision_id: "Float",
|
|
1007
1162
|
generator: "String",
|
|
1008
|
-
lang: "
|
|
1163
|
+
lang: "String",
|
|
1009
1164
|
links: "String",
|
|
1010
1165
|
registry_id: "Int",
|
|
1011
1166
|
timezone: "String",
|
|
@@ -1025,7 +1180,7 @@ const ReturnTypes = {
|
|
|
1025
1180
|
coopname: "String",
|
|
1026
1181
|
created_at: "String",
|
|
1027
1182
|
generator: "String",
|
|
1028
|
-
lang: "
|
|
1183
|
+
lang: "String",
|
|
1029
1184
|
links: "String",
|
|
1030
1185
|
registry_id: "Int",
|
|
1031
1186
|
timezone: "String",
|
|
@@ -1113,7 +1268,7 @@ const ReturnTypes = {
|
|
|
1113
1268
|
coopname: "String",
|
|
1114
1269
|
created_at: "String",
|
|
1115
1270
|
generator: "String",
|
|
1116
|
-
lang: "
|
|
1271
|
+
lang: "String",
|
|
1117
1272
|
links: "String",
|
|
1118
1273
|
project_id: "String",
|
|
1119
1274
|
registry_id: "Int",
|
|
@@ -1183,7 +1338,7 @@ const ReturnTypes = {
|
|
|
1183
1338
|
coopname: "String",
|
|
1184
1339
|
created_at: "String",
|
|
1185
1340
|
generator: "String",
|
|
1186
|
-
lang: "
|
|
1341
|
+
lang: "String",
|
|
1187
1342
|
links: "String",
|
|
1188
1343
|
registry_id: "Int",
|
|
1189
1344
|
timezone: "String",
|
|
@@ -1278,7 +1433,7 @@ const Ops = {
|
|
|
1278
1433
|
const HOST = "Specify host";
|
|
1279
1434
|
const HEADERS = {};
|
|
1280
1435
|
const apiSubscription = (options) => {
|
|
1281
|
-
const client = createClient
|
|
1436
|
+
const client = createClient({
|
|
1282
1437
|
url: String(options[0]),
|
|
1283
1438
|
connectionParams: Object.fromEntries(new Headers(options[1]?.headers).entries())
|
|
1284
1439
|
});
|
|
@@ -1798,10 +1953,6 @@ var Country = /* @__PURE__ */ ((Country2) => {
|
|
|
1798
1953
|
Country2["Russia"] = "Russia";
|
|
1799
1954
|
return Country2;
|
|
1800
1955
|
})(Country || {});
|
|
1801
|
-
var LangType = /* @__PURE__ */ ((LangType2) => {
|
|
1802
|
-
LangType2["ru"] = "ru";
|
|
1803
|
-
return LangType2;
|
|
1804
|
-
})(LangType || {});
|
|
1805
1956
|
var OrganizationType = /* @__PURE__ */ ((OrganizationType2) => {
|
|
1806
1957
|
OrganizationType2["AO"] = "AO";
|
|
1807
1958
|
OrganizationType2["COOP"] = "COOP";
|
|
@@ -1842,7 +1993,7 @@ var UserStatus = /* @__PURE__ */ ((UserStatus2) => {
|
|
|
1842
1993
|
return UserStatus2;
|
|
1843
1994
|
})(UserStatus || {});
|
|
1844
1995
|
|
|
1845
|
-
const index$
|
|
1996
|
+
const index$o = {
|
|
1846
1997
|
__proto__: null,
|
|
1847
1998
|
$: $,
|
|
1848
1999
|
AccountType: AccountType,
|
|
@@ -1855,7 +2006,6 @@ const index$k = {
|
|
|
1855
2006
|
HOST: HOST,
|
|
1856
2007
|
InternalArgsBuilt: InternalArgsBuilt,
|
|
1857
2008
|
InternalsBuildQuery: InternalsBuildQuery,
|
|
1858
|
-
LangType: LangType,
|
|
1859
2009
|
OrganizationType: OrganizationType,
|
|
1860
2010
|
PaymentStatus: PaymentStatus,
|
|
1861
2011
|
PrepareScalarPaths: PrepareScalarPaths,
|
|
@@ -1933,7 +2083,7 @@ const updateExtension = {
|
|
|
1933
2083
|
name: name$K
|
|
1934
2084
|
};
|
|
1935
2085
|
|
|
1936
|
-
const index$
|
|
2086
|
+
const index$n = {
|
|
1937
2087
|
__proto__: null,
|
|
1938
2088
|
InstallExtension: installExtension,
|
|
1939
2089
|
UninstallExtension: uninstallExtension,
|
|
@@ -2003,7 +2153,7 @@ const updateBankAccount = {
|
|
|
2003
2153
|
name: name$H
|
|
2004
2154
|
};
|
|
2005
2155
|
|
|
2006
|
-
const index$
|
|
2156
|
+
const index$m = {
|
|
2007
2157
|
__proto__: null,
|
|
2008
2158
|
CreateBankAccount: createBankAccount,
|
|
2009
2159
|
DeletePaymentMethod: deletePaymentMethod,
|
|
@@ -2569,7 +2719,7 @@ const selectBranch = {
|
|
|
2569
2719
|
|
|
2570
2720
|
const name$A = "generateSelectBranchDocument";
|
|
2571
2721
|
const mutation$q = Selector("Mutation")({
|
|
2572
|
-
[name$A]: [{ data: $("data", "SelectBranchGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2722
|
+
[name$A]: [{ data: $("data", "SelectBranchGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, generateSelectBranchDocumentSelector]
|
|
2573
2723
|
});
|
|
2574
2724
|
|
|
2575
2725
|
const generateSelectBranchDocument = {
|
|
@@ -2578,7 +2728,7 @@ const generateSelectBranchDocument = {
|
|
|
2578
2728
|
name: name$A
|
|
2579
2729
|
};
|
|
2580
2730
|
|
|
2581
|
-
const index$
|
|
2731
|
+
const index$l = {
|
|
2582
2732
|
__proto__: null,
|
|
2583
2733
|
AddTrustedAccount: addTrustedAccount,
|
|
2584
2734
|
CreateBranch: createBranch,
|
|
@@ -2601,7 +2751,7 @@ const projectFreeDecisionDocumentSelector = Selector("ProjectFreeDecisionDocumen
|
|
|
2601
2751
|
|
|
2602
2752
|
const name$z = "generateProjectOfFreeDecision";
|
|
2603
2753
|
const mutation$p = Selector("Mutation")({
|
|
2604
|
-
[name$z]: [{ data: $("data", "ProjectFreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2754
|
+
[name$z]: [{ data: $("data", "ProjectFreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, projectFreeDecisionDocumentSelector]
|
|
2605
2755
|
});
|
|
2606
2756
|
|
|
2607
2757
|
const generateProjectOfFreeDecisionDocument = {
|
|
@@ -2631,7 +2781,7 @@ const createdProjectFreeDecisionSelector = Selector("CreatedProjectFreeDecision"
|
|
|
2631
2781
|
|
|
2632
2782
|
const name$y = "generateFreeDecision";
|
|
2633
2783
|
const mutation$o = Selector("Mutation")({
|
|
2634
|
-
[name$y]: [{ data: $("data", "FreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2784
|
+
[name$y]: [{ data: $("data", "FreeDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, freeDecisionDocumentSelector]
|
|
2635
2785
|
});
|
|
2636
2786
|
|
|
2637
2787
|
const generateFreeDecision = {
|
|
@@ -2662,7 +2812,7 @@ const createProjectOfFreeDecision = {
|
|
|
2662
2812
|
name: name$w
|
|
2663
2813
|
};
|
|
2664
2814
|
|
|
2665
|
-
const index$
|
|
2815
|
+
const index$k = {
|
|
2666
2816
|
__proto__: null,
|
|
2667
2817
|
CreateProjectOfFreeDecision: createProjectOfFreeDecision,
|
|
2668
2818
|
GenerateFreeDecision: generateFreeDecision,
|
|
@@ -2730,7 +2880,7 @@ const resetKey = {
|
|
|
2730
2880
|
name: name$s
|
|
2731
2881
|
};
|
|
2732
2882
|
|
|
2733
|
-
const index$
|
|
2883
|
+
const index$j = {
|
|
2734
2884
|
__proto__: null,
|
|
2735
2885
|
RegisterAccount: registerAccount,
|
|
2736
2886
|
ResetKey: resetKey,
|
|
@@ -2771,7 +2921,7 @@ const login = {
|
|
|
2771
2921
|
name: name$p
|
|
2772
2922
|
};
|
|
2773
2923
|
|
|
2774
|
-
const index$
|
|
2924
|
+
const index$i = {
|
|
2775
2925
|
__proto__: null,
|
|
2776
2926
|
Login: login,
|
|
2777
2927
|
Logout: logout,
|
|
@@ -2822,7 +2972,7 @@ const updateSystem = {
|
|
|
2822
2972
|
name: name$l
|
|
2823
2973
|
};
|
|
2824
2974
|
|
|
2825
|
-
const index$
|
|
2975
|
+
const index$h = {
|
|
2826
2976
|
__proto__: null,
|
|
2827
2977
|
InitSystem: initSystem,
|
|
2828
2978
|
InstallSystem: installSystem,
|
|
@@ -2832,7 +2982,7 @@ const index$d = {
|
|
|
2832
2982
|
|
|
2833
2983
|
const name$k = "generateParticipantApplication";
|
|
2834
2984
|
const mutation$a = Selector("Mutation")({
|
|
2835
|
-
[name$k]: [{ data: $("data", "ParticipantApplicationGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2985
|
+
[name$k]: [{ data: $("data", "ParticipantApplicationGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, participantApplicationDocumentSelector]
|
|
2836
2986
|
});
|
|
2837
2987
|
|
|
2838
2988
|
const generateParticipantApplication = {
|
|
@@ -2843,7 +2993,7 @@ const generateParticipantApplication = {
|
|
|
2843
2993
|
|
|
2844
2994
|
const name$j = "generateParticipantApplicationDecision";
|
|
2845
2995
|
const mutation$9 = Selector("Mutation")({
|
|
2846
|
-
[name$j]: [{ data: $("data", "ParticipantApplicationDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
2996
|
+
[name$j]: [{ data: $("data", "ParticipantApplicationDecisionGenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, participantApplicationDecisionDocumentSelector]
|
|
2847
2997
|
});
|
|
2848
2998
|
|
|
2849
2999
|
const generateParticipantApplicationDecision = {
|
|
@@ -2874,7 +3024,7 @@ const addParticipant = {
|
|
|
2874
3024
|
name: name$h
|
|
2875
3025
|
};
|
|
2876
3026
|
|
|
2877
|
-
const index$
|
|
3027
|
+
const index$g = {
|
|
2878
3028
|
__proto__: null,
|
|
2879
3029
|
AddParticipant: addParticipant,
|
|
2880
3030
|
GenerateParticipantApplication: generateParticipantApplication,
|
|
@@ -2940,7 +3090,7 @@ const setPaymentStatus = {
|
|
|
2940
3090
|
name: name$e
|
|
2941
3091
|
};
|
|
2942
3092
|
|
|
2943
|
-
const index$
|
|
3093
|
+
const index$f = {
|
|
2944
3094
|
__proto__: null,
|
|
2945
3095
|
CreateDepositPayment: createDeposit,
|
|
2946
3096
|
CreateInitialPayment: createInitial,
|
|
@@ -2949,7 +3099,7 @@ const index$b = {
|
|
|
2949
3099
|
|
|
2950
3100
|
const name$d = "generatePrivacyAgreement";
|
|
2951
3101
|
const mutation$3 = Selector("Mutation")({
|
|
2952
|
-
[name$d]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3102
|
+
[name$d]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2953
3103
|
});
|
|
2954
3104
|
|
|
2955
3105
|
const generatePrivacyAgreement = {
|
|
@@ -2960,7 +3110,7 @@ const generatePrivacyAgreement = {
|
|
|
2960
3110
|
|
|
2961
3111
|
const name$c = "generateSignatureAgreement";
|
|
2962
3112
|
const mutation$2 = Selector("Mutation")({
|
|
2963
|
-
[name$c]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3113
|
+
[name$c]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2964
3114
|
});
|
|
2965
3115
|
|
|
2966
3116
|
const generateSignatureAgreement = {
|
|
@@ -2971,7 +3121,7 @@ const generateSignatureAgreement = {
|
|
|
2971
3121
|
|
|
2972
3122
|
const name$b = "generateWalletAgreement";
|
|
2973
3123
|
const mutation$1 = Selector("Mutation")({
|
|
2974
|
-
[name$b]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3124
|
+
[name$b]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2975
3125
|
});
|
|
2976
3126
|
|
|
2977
3127
|
const generateWalletAgreement = {
|
|
@@ -2982,7 +3132,7 @@ const generateWalletAgreement = {
|
|
|
2982
3132
|
|
|
2983
3133
|
const name$a = "generateUserAgreement";
|
|
2984
3134
|
const mutation = Selector("Mutation")({
|
|
2985
|
-
[name$a]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput
|
|
3135
|
+
[name$a]: [{ data: $("data", "GenerateDocumentInput!"), options: $("options", "GenerateDocumentOptionsInput") }, documentSelector]
|
|
2986
3136
|
});
|
|
2987
3137
|
|
|
2988
3138
|
const generateUserAgreement = {
|
|
@@ -2991,7 +3141,7 @@ const generateUserAgreement = {
|
|
|
2991
3141
|
name: name$a
|
|
2992
3142
|
};
|
|
2993
3143
|
|
|
2994
|
-
const index$
|
|
3144
|
+
const index$e = {
|
|
2995
3145
|
__proto__: null,
|
|
2996
3146
|
GeneratePrivacyAgreement: generatePrivacyAgreement,
|
|
2997
3147
|
GenerateSignatureAgreement: generateSignatureAgreement,
|
|
@@ -3001,16 +3151,16 @@ const index$a = {
|
|
|
3001
3151
|
|
|
3002
3152
|
const Mutations = {
|
|
3003
3153
|
__proto__: null,
|
|
3004
|
-
Accounts: index$
|
|
3005
|
-
Agreements: index$
|
|
3006
|
-
Auth: index$
|
|
3007
|
-
Branches: index$
|
|
3008
|
-
Extensions: index$
|
|
3009
|
-
FreeDecisions: index$
|
|
3010
|
-
Participants: index$
|
|
3011
|
-
PaymentMethods: index$
|
|
3012
|
-
Payments: index$
|
|
3013
|
-
System: index$
|
|
3154
|
+
Accounts: index$j,
|
|
3155
|
+
Agreements: index$e,
|
|
3156
|
+
Auth: index$i,
|
|
3157
|
+
Branches: index$l,
|
|
3158
|
+
Extensions: index$n,
|
|
3159
|
+
FreeDecisions: index$k,
|
|
3160
|
+
Participants: index$g,
|
|
3161
|
+
PaymentMethods: index$m,
|
|
3162
|
+
Payments: index$f,
|
|
3163
|
+
System: index$h
|
|
3014
3164
|
};
|
|
3015
3165
|
|
|
3016
3166
|
const name$9 = "getExtensions";
|
|
@@ -3024,7 +3174,7 @@ const getExtensions = {
|
|
|
3024
3174
|
query: query$9
|
|
3025
3175
|
};
|
|
3026
3176
|
|
|
3027
|
-
const index$
|
|
3177
|
+
const index$d = {
|
|
3028
3178
|
__proto__: null,
|
|
3029
3179
|
GetExtensions: getExtensions
|
|
3030
3180
|
};
|
|
@@ -3049,7 +3199,7 @@ const getPaymentMethods = {
|
|
|
3049
3199
|
query: query$8
|
|
3050
3200
|
};
|
|
3051
3201
|
|
|
3052
|
-
const index$
|
|
3202
|
+
const index$c = {
|
|
3053
3203
|
__proto__: null,
|
|
3054
3204
|
GetPaymentMethods: getPaymentMethods
|
|
3055
3205
|
};
|
|
@@ -3065,7 +3215,7 @@ const getSystemInfo = {
|
|
|
3065
3215
|
query: query$7
|
|
3066
3216
|
};
|
|
3067
3217
|
|
|
3068
|
-
const index$
|
|
3218
|
+
const index$b = {
|
|
3069
3219
|
__proto__: null,
|
|
3070
3220
|
GetSystemInfo: getSystemInfo
|
|
3071
3221
|
};
|
|
@@ -3095,7 +3245,7 @@ const getAccounts = {
|
|
|
3095
3245
|
query: query$5
|
|
3096
3246
|
};
|
|
3097
3247
|
|
|
3098
|
-
const index$
|
|
3248
|
+
const index$a = {
|
|
3099
3249
|
__proto__: null,
|
|
3100
3250
|
GetAccount: getAccount,
|
|
3101
3251
|
GetAccounts: getAccounts
|
|
@@ -3123,7 +3273,7 @@ const getPublicBranches = {
|
|
|
3123
3273
|
query: query$3
|
|
3124
3274
|
};
|
|
3125
3275
|
|
|
3126
|
-
const index$
|
|
3276
|
+
const index$9 = {
|
|
3127
3277
|
__proto__: null,
|
|
3128
3278
|
GetBranches: getBranches,
|
|
3129
3279
|
GetPublicBranches: getPublicBranches
|
|
@@ -3140,7 +3290,7 @@ const getPayments = {
|
|
|
3140
3290
|
query: query$2
|
|
3141
3291
|
};
|
|
3142
3292
|
|
|
3143
|
-
const index$
|
|
3293
|
+
const index$8 = {
|
|
3144
3294
|
__proto__: null,
|
|
3145
3295
|
GetPayments: getPayments
|
|
3146
3296
|
};
|
|
@@ -3204,7 +3354,7 @@ const getDocuments = {
|
|
|
3204
3354
|
query: query$1
|
|
3205
3355
|
};
|
|
3206
3356
|
|
|
3207
|
-
const index$
|
|
3357
|
+
const index$7 = {
|
|
3208
3358
|
__proto__: null,
|
|
3209
3359
|
GetDocuments: getDocuments
|
|
3210
3360
|
};
|
|
@@ -3255,75 +3405,101 @@ const getAgenda = {
|
|
|
3255
3405
|
query: query
|
|
3256
3406
|
};
|
|
3257
3407
|
|
|
3258
|
-
const index$
|
|
3408
|
+
const index$6 = {
|
|
3259
3409
|
__proto__: null,
|
|
3260
3410
|
GetAgenda: getAgenda
|
|
3261
3411
|
};
|
|
3262
3412
|
|
|
3263
|
-
const index$
|
|
3413
|
+
const index$5 = {
|
|
3264
3414
|
__proto__: null,
|
|
3265
|
-
Accounts: index$
|
|
3266
|
-
Agenda: index$
|
|
3267
|
-
Branches: index$
|
|
3268
|
-
Documents: index$
|
|
3269
|
-
Extensions: index$
|
|
3270
|
-
PaymentMethods: index$
|
|
3271
|
-
Payments: index$
|
|
3272
|
-
System: index$
|
|
3415
|
+
Accounts: index$a,
|
|
3416
|
+
Agenda: index$6,
|
|
3417
|
+
Branches: index$9,
|
|
3418
|
+
Documents: index$7,
|
|
3419
|
+
Extensions: index$d,
|
|
3420
|
+
PaymentMethods: index$c,
|
|
3421
|
+
Payments: index$8,
|
|
3422
|
+
System: index$b
|
|
3273
3423
|
};
|
|
3274
3424
|
|
|
3275
|
-
const index = {
|
|
3425
|
+
const index$4 = {
|
|
3426
|
+
__proto__: null
|
|
3427
|
+
};
|
|
3428
|
+
|
|
3429
|
+
const index$3 = {
|
|
3276
3430
|
__proto__: null
|
|
3277
3431
|
};
|
|
3278
3432
|
|
|
3433
|
+
const index$2 = {
|
|
3434
|
+
__proto__: null
|
|
3435
|
+
};
|
|
3436
|
+
|
|
3437
|
+
const index$1 = {
|
|
3438
|
+
__proto__: null
|
|
3439
|
+
};
|
|
3440
|
+
|
|
3441
|
+
const index = {
|
|
3442
|
+
__proto__: null,
|
|
3443
|
+
Blockchain: index$4,
|
|
3444
|
+
Client: index$3,
|
|
3445
|
+
Controller: index$2,
|
|
3446
|
+
Document: index$1
|
|
3447
|
+
};
|
|
3448
|
+
|
|
3449
|
+
var __defProp = Object.defineProperty;
|
|
3450
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3451
|
+
var __publicField = (obj, key, value) => {
|
|
3452
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3453
|
+
return value;
|
|
3454
|
+
};
|
|
3279
3455
|
if (typeof globalThis.WebSocket === "undefined") {
|
|
3280
3456
|
globalThis.WebSocket = WebSocket;
|
|
3281
3457
|
}
|
|
3282
|
-
|
|
3283
|
-
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
|
|
3287
|
-
|
|
3288
|
-
|
|
3458
|
+
const _Client = class _Client {
|
|
3459
|
+
constructor(options) {
|
|
3460
|
+
this.options = options;
|
|
3461
|
+
__publicField(this, "currentHeaders", {});
|
|
3462
|
+
__publicField(this, "blockchain");
|
|
3463
|
+
__publicField(this, "document");
|
|
3464
|
+
__publicField(this, "thunder");
|
|
3465
|
+
this.currentHeaders = options.headers || {};
|
|
3466
|
+
this.thunder = _Client.createThunder(options.api_url);
|
|
3467
|
+
this.blockchain = new Blockchain(options);
|
|
3468
|
+
this.document = new Document(options.wif);
|
|
3469
|
+
if (options.wif && options.username) {
|
|
3470
|
+
this.blockchain.setWif(options.username, options.wif);
|
|
3471
|
+
this.document.setWif(options.wif);
|
|
3472
|
+
} else if (options.wif && !options.username || !options.wif && options.username) {
|
|
3473
|
+
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");
|
|
3474
|
+
}
|
|
3289
3475
|
}
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
"Content-Type": "application/json",
|
|
3298
|
-
...currentHeaders
|
|
3299
|
-
// Используем текущие заголовки, включая Authorization
|
|
3300
|
-
}
|
|
3301
|
-
});
|
|
3302
|
-
if (!response.ok) {
|
|
3303
|
-
return new Promise((resolve, reject) => {
|
|
3304
|
-
response.text().then((text) => {
|
|
3305
|
-
try {
|
|
3306
|
-
reject(JSON.parse(text));
|
|
3307
|
-
} catch (err) {
|
|
3308
|
-
reject(text);
|
|
3309
|
-
}
|
|
3310
|
-
}).catch(reject);
|
|
3311
|
-
});
|
|
3476
|
+
/**
|
|
3477
|
+
* Инициализация клиента с заданными опциями.
|
|
3478
|
+
* @param options Параметры соединения.
|
|
3479
|
+
*/
|
|
3480
|
+
static create(options) {
|
|
3481
|
+
if (!this.instance) {
|
|
3482
|
+
this.instance = new _Client(options);
|
|
3312
3483
|
}
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3484
|
+
return this.getInstance();
|
|
3485
|
+
}
|
|
3486
|
+
/**
|
|
3487
|
+
* Возвращает текущий экземпляр клиента.
|
|
3488
|
+
*/
|
|
3489
|
+
static getInstance() {
|
|
3490
|
+
if (!this.instance) {
|
|
3491
|
+
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.");
|
|
3317
3492
|
}
|
|
3318
|
-
return
|
|
3319
|
-
}
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3493
|
+
return this.instance;
|
|
3494
|
+
}
|
|
3495
|
+
/**
|
|
3496
|
+
* Логин пользователя с использованием email и WIF.
|
|
3497
|
+
* @param email Email пользователя.
|
|
3498
|
+
* @param wif Приватный ключ в формате WIF.
|
|
3499
|
+
* @returns Результат логина.
|
|
3500
|
+
*/
|
|
3501
|
+
async login(email, wif) {
|
|
3502
|
+
const now = (await this.blockchain.getInfo()).head_block_time.toString();
|
|
3327
3503
|
const privateKey = PrivateKey$1.fromString(wif);
|
|
3328
3504
|
const bytes = Bytes.fromString(now, "utf8");
|
|
3329
3505
|
const checksum = Checksum256.hash(bytes);
|
|
@@ -3335,30 +3511,99 @@ function createClient(options) {
|
|
|
3335
3511
|
signature
|
|
3336
3512
|
}
|
|
3337
3513
|
};
|
|
3338
|
-
const { [name$p]: result } = await thunder("mutation")(
|
|
3514
|
+
const { [name$p]: result } = await this.thunder("mutation")(
|
|
3339
3515
|
mutation$f,
|
|
3340
3516
|
{
|
|
3341
3517
|
variables
|
|
3342
3518
|
}
|
|
3343
3519
|
);
|
|
3344
|
-
|
|
3520
|
+
const username = result.account.username;
|
|
3521
|
+
this.blockchain.setWif(username, wif);
|
|
3522
|
+
this.document.setWif(wif);
|
|
3523
|
+
this.currentHeaders.Authorization = `Bearer ${result.tokens.access.token}`;
|
|
3345
3524
|
return result;
|
|
3346
3525
|
}
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3526
|
+
/**
|
|
3527
|
+
* Установка токена авторизации.
|
|
3528
|
+
* @param token Токен для заголовков Authorization.
|
|
3529
|
+
*/
|
|
3530
|
+
setToken(token) {
|
|
3531
|
+
this.currentHeaders.Authorization = `Bearer ${token}`;
|
|
3351
3532
|
}
|
|
3352
|
-
|
|
3353
|
-
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
|
|
3360
|
-
|
|
3361
|
-
|
|
3362
|
-
|
|
3533
|
+
/**
|
|
3534
|
+
* Доступ к Blockchain.
|
|
3535
|
+
*/
|
|
3536
|
+
get Blockchain() {
|
|
3537
|
+
return this.blockchain;
|
|
3538
|
+
}
|
|
3539
|
+
/**
|
|
3540
|
+
* Доступ к Document.
|
|
3541
|
+
*/
|
|
3542
|
+
get Document() {
|
|
3543
|
+
return this.document;
|
|
3544
|
+
}
|
|
3545
|
+
/**
|
|
3546
|
+
* Доступ к GraphQL-запросам.
|
|
3547
|
+
*/
|
|
3548
|
+
get Query() {
|
|
3549
|
+
return this.thunder("query");
|
|
3550
|
+
}
|
|
3551
|
+
/**
|
|
3552
|
+
* Доступ к GraphQL-мутациям.
|
|
3553
|
+
*/
|
|
3554
|
+
get Mutation() {
|
|
3555
|
+
return this.thunder("mutation");
|
|
3556
|
+
}
|
|
3557
|
+
/**
|
|
3558
|
+
* Подписка на GraphQL-события.
|
|
3559
|
+
*/
|
|
3560
|
+
get Subscription() {
|
|
3561
|
+
return Subscription(this.options.api_url.replace(/^http/, "ws"));
|
|
3562
|
+
}
|
|
3563
|
+
/**
|
|
3564
|
+
* Создает функцию Thunder для выполнения GraphQL-запросов.
|
|
3565
|
+
* @param baseUrl URL GraphQL API.
|
|
3566
|
+
* @returns Функция Thunder.
|
|
3567
|
+
*/
|
|
3568
|
+
static createThunder(baseUrl) {
|
|
3569
|
+
return Thunder(async (query, variables) => {
|
|
3570
|
+
const response = await fetch(baseUrl, {
|
|
3571
|
+
body: JSON.stringify({ query, variables }),
|
|
3572
|
+
method: "POST",
|
|
3573
|
+
headers: {
|
|
3574
|
+
"Content-Type": "application/json",
|
|
3575
|
+
..._Client.getInstance().currentHeaders
|
|
3576
|
+
}
|
|
3577
|
+
});
|
|
3578
|
+
if (!response.ok) {
|
|
3579
|
+
return new Promise((resolve, reject) => {
|
|
3580
|
+
response.text().then((text) => {
|
|
3581
|
+
try {
|
|
3582
|
+
reject(JSON.parse(text));
|
|
3583
|
+
} catch {
|
|
3584
|
+
reject(text);
|
|
3585
|
+
}
|
|
3586
|
+
}).catch(reject);
|
|
3587
|
+
});
|
|
3588
|
+
}
|
|
3589
|
+
const json = await response.json();
|
|
3590
|
+
if (json.errors) {
|
|
3591
|
+
console.log("json.errors", json.errors);
|
|
3592
|
+
throw json.errors;
|
|
3593
|
+
}
|
|
3594
|
+
return json.data;
|
|
3595
|
+
}, { scalars: _Client.scalars });
|
|
3596
|
+
}
|
|
3597
|
+
};
|
|
3598
|
+
__publicField(_Client, "instance", null);
|
|
3599
|
+
__publicField(_Client, "scalars", ZeusScalars({
|
|
3600
|
+
DateTime: {
|
|
3601
|
+
decode: (e) => new Date(e),
|
|
3602
|
+
// Преобразует строку в объект Date
|
|
3603
|
+
encode: (e) => e.toISOString()
|
|
3604
|
+
// Преобразует Date в ISO-строку
|
|
3605
|
+
}
|
|
3606
|
+
}));
|
|
3607
|
+
let Client = _Client;
|
|
3363
3608
|
|
|
3364
|
-
export { Classes, Mutations, index$
|
|
3609
|
+
export { Classes, Client, Mutations, index$5 as Queries, index as Types, index$o as Zeus };
|