1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.ApiBase = void 0;
|
4 | const util_1 = require("@polkadot/util");
|
5 | const Getters_js_1 = require("./Getters.js");
|
6 | class ApiBase extends Getters_js_1.Getters {
|
7 | |
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | constructor(options = {}, type, decorateMethod) {
|
26 | super(options, type, decorateMethod);
|
27 | }
|
28 | |
29 |
|
30 |
|
31 | connect() {
|
32 | return this._rpcCore.connect();
|
33 | }
|
34 | |
35 |
|
36 |
|
37 | disconnect() {
|
38 | this._unsubscribe();
|
39 | return this._rpcCore.disconnect();
|
40 | }
|
41 | |
42 |
|
43 |
|
44 | setSigner(signer) {
|
45 | this._rx.signer = signer;
|
46 | }
|
47 | |
48 |
|
49 |
|
50 | async sign(address, data, { signer } = {}) {
|
51 | if ((0, util_1.isString)(address)) {
|
52 | const _signer = signer || this._rx.signer;
|
53 | if (!_signer?.signRaw) {
|
54 | throw new Error('No signer exists with a signRaw interface. You possibly need to pass through an explicit keypair for the origin so it can be used for signing.');
|
55 | }
|
56 | return (await _signer.signRaw((0, util_1.objectSpread)({ type: 'bytes' }, data, { address }))).signature;
|
57 | }
|
58 | return (0, util_1.u8aToHex)(address.sign((0, util_1.u8aToU8a)(data.data)));
|
59 | }
|
60 | }
|
61 | exports.ApiBase = ApiBase;
|