@massalabs/wallet-provider 1.2.1-dev.20230803141012 → 1.2.1-dev.20230810090154
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/bundle.js +3143 -27
- package/bundle.min.js +1 -1
- package/dist/bearbyWallet/BalanceResponse.d.ts +28 -0
- package/dist/bearbyWallet/BalanceResponse.d.ts.map +1 -0
- package/dist/bearbyWallet/BalanceResponse.js +2 -0
- package/dist/bearbyWallet/BearbyAccount.d.ts +118 -0
- package/dist/bearbyWallet/BearbyAccount.d.ts.map +1 -0
- package/dist/bearbyWallet/BearbyAccount.js +418 -0
- package/dist/bearbyWallet/BearbyConnect.d.ts +4 -0
- package/dist/bearbyWallet/BearbyConnect.d.ts.map +1 -0
- package/dist/bearbyWallet/BearbyConnect.js +26 -0
- package/dist/bearbyWallet/BearbyProvider.d.ts +19 -0
- package/dist/bearbyWallet/BearbyProvider.d.ts.map +1 -0
- package/dist/bearbyWallet/BearbyProvider.js +43 -0
- package/dist/bearbyWallet/ICallData.d.ts +26 -0
- package/dist/bearbyWallet/ICallData.d.ts.map +1 -0
- package/dist/bearbyWallet/ICallData.js +2 -0
- package/dist/bearbyWallet/IcontractData.d.ts +28 -0
- package/dist/bearbyWallet/IcontractData.d.ts.map +1 -0
- package/dist/bearbyWallet/IcontractData.js +2 -0
- package/dist/bearbyWallet/NodeStatus.d.ts +84 -0
- package/dist/bearbyWallet/NodeStatus.d.ts.map +1 -0
- package/dist/bearbyWallet/NodeStatus.js +2 -0
- package/dist/bearbyWallet/Xbqcrypto.d.ts +45 -0
- package/dist/bearbyWallet/Xbqcrypto.d.ts.map +1 -0
- package/dist/bearbyWallet/Xbqcrypto.js +75 -0
- package/dist/bearbyWallet/compactBytesForOperation.d.ts +39 -0
- package/dist/bearbyWallet/compactBytesForOperation.d.ts.map +1 -0
- package/dist/bearbyWallet/compactBytesForOperation.js +53 -0
- package/dist/bearbyWallet/jsonRpcMethods.d.ts +31 -0
- package/dist/bearbyWallet/jsonRpcMethods.d.ts.map +1 -0
- package/dist/bearbyWallet/jsonRpcMethods.js +36 -0
- package/dist/bearbyWallet/jsonRpcResponseData.d.ts +13 -0
- package/dist/bearbyWallet/jsonRpcResponseData.d.ts.map +1 -0
- package/dist/bearbyWallet/jsonRpcResponseData.js +2 -0
- package/dist/bearbyWallet/unsignedBigIntUtils.d.ts +30 -0
- package/dist/bearbyWallet/unsignedBigIntUtils.d.ts.map +1 -0
- package/dist/bearbyWallet/unsignedBigIntUtils.js +75 -0
- package/dist/cmd/bearbyWallet/BalanceResponse.d.ts +28 -0
- package/dist/cmd/bearbyWallet/BalanceResponse.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/BalanceResponse.js +3 -0
- package/dist/cmd/bearbyWallet/BalanceResponse.js.map +1 -0
- package/dist/cmd/bearbyWallet/BearbyAccount.d.ts +118 -0
- package/dist/cmd/bearbyWallet/BearbyAccount.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/BearbyAccount.js +419 -0
- package/dist/cmd/bearbyWallet/BearbyAccount.js.map +1 -0
- package/dist/cmd/bearbyWallet/BearbyConnect.d.ts +4 -0
- package/dist/cmd/bearbyWallet/BearbyConnect.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/BearbyConnect.js +27 -0
- package/dist/cmd/bearbyWallet/BearbyConnect.js.map +1 -0
- package/dist/cmd/bearbyWallet/BearbyProvider.d.ts +19 -0
- package/dist/cmd/bearbyWallet/BearbyProvider.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/BearbyProvider.js +44 -0
- package/dist/cmd/bearbyWallet/BearbyProvider.js.map +1 -0
- package/dist/cmd/bearbyWallet/ICallData.d.ts +26 -0
- package/dist/cmd/bearbyWallet/ICallData.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/ICallData.js +3 -0
- package/dist/cmd/bearbyWallet/ICallData.js.map +1 -0
- package/dist/cmd/bearbyWallet/IcontractData.d.ts +28 -0
- package/dist/cmd/bearbyWallet/IcontractData.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/IcontractData.js +3 -0
- package/dist/cmd/bearbyWallet/IcontractData.js.map +1 -0
- package/dist/cmd/bearbyWallet/NodeStatus.d.ts +84 -0
- package/dist/cmd/bearbyWallet/NodeStatus.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/NodeStatus.js +3 -0
- package/dist/cmd/bearbyWallet/NodeStatus.js.map +1 -0
- package/dist/cmd/bearbyWallet/Xbqcrypto.d.ts +45 -0
- package/dist/cmd/bearbyWallet/Xbqcrypto.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/Xbqcrypto.js +76 -0
- package/dist/cmd/bearbyWallet/Xbqcrypto.js.map +1 -0
- package/dist/cmd/bearbyWallet/compactBytesForOperation.d.ts +39 -0
- package/dist/cmd/bearbyWallet/compactBytesForOperation.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/compactBytesForOperation.js +54 -0
- package/dist/cmd/bearbyWallet/compactBytesForOperation.js.map +1 -0
- package/dist/cmd/bearbyWallet/jsonRpcMethods.d.ts +31 -0
- package/dist/cmd/bearbyWallet/jsonRpcMethods.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/jsonRpcMethods.js +37 -0
- package/dist/cmd/bearbyWallet/jsonRpcMethods.js.map +1 -0
- package/dist/cmd/bearbyWallet/jsonRpcResponseData.d.ts +13 -0
- package/dist/cmd/bearbyWallet/jsonRpcResponseData.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/jsonRpcResponseData.js +3 -0
- package/dist/cmd/bearbyWallet/jsonRpcResponseData.js.map +1 -0
- package/dist/cmd/bearbyWallet/unsignedBigIntUtils.d.ts +30 -0
- package/dist/cmd/bearbyWallet/unsignedBigIntUtils.d.ts.map +1 -0
- package/dist/cmd/bearbyWallet/unsignedBigIntUtils.js +76 -0
- package/dist/cmd/bearbyWallet/unsignedBigIntUtils.js.map +1 -0
- package/dist/cmd/connector/Connector.d.ts.map +1 -1
- package/dist/cmd/connector/Connector.js +1 -0
- package/dist/cmd/connector/Connector.js.map +1 -1
- package/dist/cmd/index.d.ts.map +1 -1
- package/dist/cmd/index.js +11 -0
- package/dist/cmd/index.js.map +1 -1
- package/dist/connector/Connector.d.ts.map +1 -1
- package/dist/connector/Connector.js +1 -0
- package/dist/esm/bearbyWallet/BalanceResponse.d.ts +28 -0
- package/dist/esm/bearbyWallet/BalanceResponse.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/BalanceResponse.js +2 -0
- package/dist/esm/bearbyWallet/BalanceResponse.js.map +1 -0
- package/dist/esm/bearbyWallet/BearbyAccount.d.ts +118 -0
- package/dist/esm/bearbyWallet/BearbyAccount.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/BearbyAccount.js +417 -0
- package/dist/esm/bearbyWallet/BearbyAccount.js.map +1 -0
- package/dist/esm/bearbyWallet/BearbyConnect.d.ts +4 -0
- package/dist/esm/bearbyWallet/BearbyConnect.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/BearbyConnect.js +21 -0
- package/dist/esm/bearbyWallet/BearbyConnect.js.map +1 -0
- package/dist/esm/bearbyWallet/BearbyProvider.d.ts +19 -0
- package/dist/esm/bearbyWallet/BearbyProvider.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/BearbyProvider.js +41 -0
- package/dist/esm/bearbyWallet/BearbyProvider.js.map +1 -0
- package/dist/esm/bearbyWallet/ICallData.d.ts +26 -0
- package/dist/esm/bearbyWallet/ICallData.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/ICallData.js +2 -0
- package/dist/esm/bearbyWallet/ICallData.js.map +1 -0
- package/dist/esm/bearbyWallet/IcontractData.d.ts +28 -0
- package/dist/esm/bearbyWallet/IcontractData.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/IcontractData.js +2 -0
- package/dist/esm/bearbyWallet/IcontractData.js.map +1 -0
- package/dist/esm/bearbyWallet/NodeStatus.d.ts +84 -0
- package/dist/esm/bearbyWallet/NodeStatus.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/NodeStatus.js +2 -0
- package/dist/esm/bearbyWallet/NodeStatus.js.map +1 -0
- package/dist/esm/bearbyWallet/Xbqcrypto.d.ts +45 -0
- package/dist/esm/bearbyWallet/Xbqcrypto.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/Xbqcrypto.js +68 -0
- package/dist/esm/bearbyWallet/Xbqcrypto.js.map +1 -0
- package/dist/esm/bearbyWallet/compactBytesForOperation.d.ts +39 -0
- package/dist/esm/bearbyWallet/compactBytesForOperation.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/compactBytesForOperation.js +50 -0
- package/dist/esm/bearbyWallet/compactBytesForOperation.js.map +1 -0
- package/dist/esm/bearbyWallet/jsonRpcMethods.d.ts +31 -0
- package/dist/esm/bearbyWallet/jsonRpcMethods.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/jsonRpcMethods.js +34 -0
- package/dist/esm/bearbyWallet/jsonRpcMethods.js.map +1 -0
- package/dist/esm/bearbyWallet/jsonRpcResponseData.d.ts +13 -0
- package/dist/esm/bearbyWallet/jsonRpcResponseData.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/jsonRpcResponseData.js +2 -0
- package/dist/esm/bearbyWallet/jsonRpcResponseData.js.map +1 -0
- package/dist/esm/bearbyWallet/unsignedBigIntUtils.d.ts +30 -0
- package/dist/esm/bearbyWallet/unsignedBigIntUtils.d.ts.map +1 -0
- package/dist/esm/bearbyWallet/unsignedBigIntUtils.js +70 -0
- package/dist/esm/bearbyWallet/unsignedBigIntUtils.js.map +1 -0
- package/dist/esm/connector/Connector.d.ts.map +1 -1
- package/dist/esm/connector/Connector.js +1 -0
- package/dist/esm/connector/Connector.js.map +1 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +11 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/package.json +6 -3
package/bundle.js
CHANGED
|
@@ -1,6 +1,1116 @@
|
|
|
1
1
|
/******/ (() => { // webpackBootstrap
|
|
2
2
|
/******/ var __webpack_modules__ = ({
|
|
3
3
|
|
|
4
|
+
/***/ "./node_modules/@noble/hashes/_assert.js":
|
|
5
|
+
/*!***********************************************!*\
|
|
6
|
+
!*** ./node_modules/@noble/hashes/_assert.js ***!
|
|
7
|
+
\***********************************************/
|
|
8
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
9
|
+
|
|
10
|
+
"use strict";
|
|
11
|
+
|
|
12
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
13
|
+
exports.output = exports.exists = exports.hash = exports.bytes = exports.bool = exports.number = void 0;
|
|
14
|
+
function number(n) {
|
|
15
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
16
|
+
throw new Error(`Wrong positive integer: ${n}`);
|
|
17
|
+
}
|
|
18
|
+
exports.number = number;
|
|
19
|
+
function bool(b) {
|
|
20
|
+
if (typeof b !== 'boolean')
|
|
21
|
+
throw new Error(`Expected boolean, not ${b}`);
|
|
22
|
+
}
|
|
23
|
+
exports.bool = bool;
|
|
24
|
+
function bytes(b, ...lengths) {
|
|
25
|
+
if (!(b instanceof Uint8Array))
|
|
26
|
+
throw new Error('Expected Uint8Array');
|
|
27
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
28
|
+
throw new Error(`Expected Uint8Array of length ${lengths}, not of length=${b.length}`);
|
|
29
|
+
}
|
|
30
|
+
exports.bytes = bytes;
|
|
31
|
+
function hash(hash) {
|
|
32
|
+
if (typeof hash !== 'function' || typeof hash.create !== 'function')
|
|
33
|
+
throw new Error('Hash should be wrapped by utils.wrapConstructor');
|
|
34
|
+
number(hash.outputLen);
|
|
35
|
+
number(hash.blockLen);
|
|
36
|
+
}
|
|
37
|
+
exports.hash = hash;
|
|
38
|
+
function exists(instance, checkFinished = true) {
|
|
39
|
+
if (instance.destroyed)
|
|
40
|
+
throw new Error('Hash instance has been destroyed');
|
|
41
|
+
if (checkFinished && instance.finished)
|
|
42
|
+
throw new Error('Hash#digest() has already been called');
|
|
43
|
+
}
|
|
44
|
+
exports.exists = exists;
|
|
45
|
+
function output(out, instance) {
|
|
46
|
+
bytes(out);
|
|
47
|
+
const min = instance.outputLen;
|
|
48
|
+
if (out.length < min) {
|
|
49
|
+
throw new Error(`digestInto() expects output buffer of length at least ${min}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
exports.output = output;
|
|
53
|
+
const assert = {
|
|
54
|
+
number,
|
|
55
|
+
bool,
|
|
56
|
+
bytes,
|
|
57
|
+
hash,
|
|
58
|
+
exists,
|
|
59
|
+
output,
|
|
60
|
+
};
|
|
61
|
+
exports["default"] = assert;
|
|
62
|
+
//# sourceMappingURL=_assert.js.map
|
|
63
|
+
|
|
64
|
+
/***/ }),
|
|
65
|
+
|
|
66
|
+
/***/ "./node_modules/@noble/hashes/_blake2.js":
|
|
67
|
+
/*!***********************************************!*\
|
|
68
|
+
!*** ./node_modules/@noble/hashes/_blake2.js ***!
|
|
69
|
+
\***********************************************/
|
|
70
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
71
|
+
|
|
72
|
+
"use strict";
|
|
73
|
+
|
|
74
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
75
|
+
exports.BLAKE2 = exports.SIGMA = void 0;
|
|
76
|
+
const _assert_js_1 = __webpack_require__(/*! ./_assert.js */ "./node_modules/@noble/hashes/_assert.js");
|
|
77
|
+
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
78
|
+
// For BLAKE2b, the two extra permutations for rounds 10 and 11 are SIGMA[10..11] = SIGMA[0..1].
|
|
79
|
+
// prettier-ignore
|
|
80
|
+
exports.SIGMA = new Uint8Array([
|
|
81
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
82
|
+
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
83
|
+
11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4,
|
|
84
|
+
7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8,
|
|
85
|
+
9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13,
|
|
86
|
+
2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9,
|
|
87
|
+
12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11,
|
|
88
|
+
13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10,
|
|
89
|
+
6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5,
|
|
90
|
+
10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0,
|
|
91
|
+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
92
|
+
14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3,
|
|
93
|
+
]);
|
|
94
|
+
class BLAKE2 extends utils_js_1.Hash {
|
|
95
|
+
constructor(blockLen, outputLen, opts = {}, keyLen, saltLen, persLen) {
|
|
96
|
+
super();
|
|
97
|
+
this.blockLen = blockLen;
|
|
98
|
+
this.outputLen = outputLen;
|
|
99
|
+
this.length = 0;
|
|
100
|
+
this.pos = 0;
|
|
101
|
+
this.finished = false;
|
|
102
|
+
this.destroyed = false;
|
|
103
|
+
_assert_js_1.default.number(blockLen);
|
|
104
|
+
_assert_js_1.default.number(outputLen);
|
|
105
|
+
_assert_js_1.default.number(keyLen);
|
|
106
|
+
if (outputLen < 0 || outputLen > keyLen)
|
|
107
|
+
throw new Error('outputLen bigger than keyLen');
|
|
108
|
+
if (opts.key !== undefined && (opts.key.length < 1 || opts.key.length > keyLen))
|
|
109
|
+
throw new Error(`key must be up 1..${keyLen} byte long or undefined`);
|
|
110
|
+
if (opts.salt !== undefined && opts.salt.length !== saltLen)
|
|
111
|
+
throw new Error(`salt must be ${saltLen} byte long or undefined`);
|
|
112
|
+
if (opts.personalization !== undefined && opts.personalization.length !== persLen)
|
|
113
|
+
throw new Error(`personalization must be ${persLen} byte long or undefined`);
|
|
114
|
+
this.buffer32 = (0, utils_js_1.u32)((this.buffer = new Uint8Array(blockLen)));
|
|
115
|
+
}
|
|
116
|
+
update(data) {
|
|
117
|
+
_assert_js_1.default.exists(this);
|
|
118
|
+
// Main difference with other hashes: there is flag for last block,
|
|
119
|
+
// so we cannot process current block before we know that there
|
|
120
|
+
// is the next one. This significantly complicates logic and reduces ability
|
|
121
|
+
// to do zero-copy processing
|
|
122
|
+
const { blockLen, buffer, buffer32 } = this;
|
|
123
|
+
data = (0, utils_js_1.toBytes)(data);
|
|
124
|
+
const len = data.length;
|
|
125
|
+
const offset = data.byteOffset;
|
|
126
|
+
const buf = data.buffer;
|
|
127
|
+
for (let pos = 0; pos < len;) {
|
|
128
|
+
// If buffer is full and we still have input (don't process last block, same as blake2s)
|
|
129
|
+
if (this.pos === blockLen) {
|
|
130
|
+
this.compress(buffer32, 0, false);
|
|
131
|
+
this.pos = 0;
|
|
132
|
+
}
|
|
133
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
134
|
+
const dataOffset = offset + pos;
|
|
135
|
+
// full block && aligned to 4 bytes && not last in input
|
|
136
|
+
if (take === blockLen && !(dataOffset % 4) && pos + take < len) {
|
|
137
|
+
const data32 = new Uint32Array(buf, dataOffset, Math.floor((len - pos) / 4));
|
|
138
|
+
for (let pos32 = 0; pos + blockLen < len; pos32 += buffer32.length, pos += blockLen) {
|
|
139
|
+
this.length += blockLen;
|
|
140
|
+
this.compress(data32, pos32, false);
|
|
141
|
+
}
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
145
|
+
this.pos += take;
|
|
146
|
+
this.length += take;
|
|
147
|
+
pos += take;
|
|
148
|
+
}
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
digestInto(out) {
|
|
152
|
+
_assert_js_1.default.exists(this);
|
|
153
|
+
_assert_js_1.default.output(out, this);
|
|
154
|
+
const { pos, buffer32 } = this;
|
|
155
|
+
this.finished = true;
|
|
156
|
+
// Padding
|
|
157
|
+
this.buffer.subarray(pos).fill(0);
|
|
158
|
+
this.compress(buffer32, 0, true);
|
|
159
|
+
const out32 = (0, utils_js_1.u32)(out);
|
|
160
|
+
this.get().forEach((v, i) => (out32[i] = v));
|
|
161
|
+
}
|
|
162
|
+
digest() {
|
|
163
|
+
const { buffer, outputLen } = this;
|
|
164
|
+
this.digestInto(buffer);
|
|
165
|
+
const res = buffer.slice(0, outputLen);
|
|
166
|
+
this.destroy();
|
|
167
|
+
return res;
|
|
168
|
+
}
|
|
169
|
+
_cloneInto(to) {
|
|
170
|
+
const { buffer, length, finished, destroyed, outputLen, pos } = this;
|
|
171
|
+
to || (to = new this.constructor({ dkLen: outputLen }));
|
|
172
|
+
to.set(...this.get());
|
|
173
|
+
to.length = length;
|
|
174
|
+
to.finished = finished;
|
|
175
|
+
to.destroyed = destroyed;
|
|
176
|
+
to.outputLen = outputLen;
|
|
177
|
+
to.buffer.set(buffer);
|
|
178
|
+
to.pos = pos;
|
|
179
|
+
return to;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
exports.BLAKE2 = BLAKE2;
|
|
183
|
+
//# sourceMappingURL=_blake2.js.map
|
|
184
|
+
|
|
185
|
+
/***/ }),
|
|
186
|
+
|
|
187
|
+
/***/ "./node_modules/@noble/hashes/_sha2.js":
|
|
188
|
+
/*!*********************************************!*\
|
|
189
|
+
!*** ./node_modules/@noble/hashes/_sha2.js ***!
|
|
190
|
+
\*********************************************/
|
|
191
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
192
|
+
|
|
193
|
+
"use strict";
|
|
194
|
+
|
|
195
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
196
|
+
exports.SHA2 = void 0;
|
|
197
|
+
const _assert_js_1 = __webpack_require__(/*! ./_assert.js */ "./node_modules/@noble/hashes/_assert.js");
|
|
198
|
+
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
199
|
+
// Polyfill for Safari 14
|
|
200
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
201
|
+
if (typeof view.setBigUint64 === 'function')
|
|
202
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
203
|
+
const _32n = BigInt(32);
|
|
204
|
+
const _u32_max = BigInt(0xffffffff);
|
|
205
|
+
const wh = Number((value >> _32n) & _u32_max);
|
|
206
|
+
const wl = Number(value & _u32_max);
|
|
207
|
+
const h = isLE ? 4 : 0;
|
|
208
|
+
const l = isLE ? 0 : 4;
|
|
209
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
210
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
211
|
+
}
|
|
212
|
+
// Base SHA2 class (RFC 6234)
|
|
213
|
+
class SHA2 extends utils_js_1.Hash {
|
|
214
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
215
|
+
super();
|
|
216
|
+
this.blockLen = blockLen;
|
|
217
|
+
this.outputLen = outputLen;
|
|
218
|
+
this.padOffset = padOffset;
|
|
219
|
+
this.isLE = isLE;
|
|
220
|
+
this.finished = false;
|
|
221
|
+
this.length = 0;
|
|
222
|
+
this.pos = 0;
|
|
223
|
+
this.destroyed = false;
|
|
224
|
+
this.buffer = new Uint8Array(blockLen);
|
|
225
|
+
this.view = (0, utils_js_1.createView)(this.buffer);
|
|
226
|
+
}
|
|
227
|
+
update(data) {
|
|
228
|
+
_assert_js_1.default.exists(this);
|
|
229
|
+
const { view, buffer, blockLen } = this;
|
|
230
|
+
data = (0, utils_js_1.toBytes)(data);
|
|
231
|
+
const len = data.length;
|
|
232
|
+
for (let pos = 0; pos < len;) {
|
|
233
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
234
|
+
// Fast path: we have at least one block in input, cast it to view and process
|
|
235
|
+
if (take === blockLen) {
|
|
236
|
+
const dataView = (0, utils_js_1.createView)(data);
|
|
237
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
238
|
+
this.process(dataView, pos);
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
242
|
+
this.pos += take;
|
|
243
|
+
pos += take;
|
|
244
|
+
if (this.pos === blockLen) {
|
|
245
|
+
this.process(view, 0);
|
|
246
|
+
this.pos = 0;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
this.length += data.length;
|
|
250
|
+
this.roundClean();
|
|
251
|
+
return this;
|
|
252
|
+
}
|
|
253
|
+
digestInto(out) {
|
|
254
|
+
_assert_js_1.default.exists(this);
|
|
255
|
+
_assert_js_1.default.output(out, this);
|
|
256
|
+
this.finished = true;
|
|
257
|
+
// Padding
|
|
258
|
+
// We can avoid allocation of buffer for padding completely if it
|
|
259
|
+
// was previously not allocated here. But it won't change performance.
|
|
260
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
261
|
+
let { pos } = this;
|
|
262
|
+
// append the bit '1' to the message
|
|
263
|
+
buffer[pos++] = 0b10000000;
|
|
264
|
+
this.buffer.subarray(pos).fill(0);
|
|
265
|
+
// we have less than padOffset left in buffer, so we cannot put length in current block, need process it and pad again
|
|
266
|
+
if (this.padOffset > blockLen - pos) {
|
|
267
|
+
this.process(view, 0);
|
|
268
|
+
pos = 0;
|
|
269
|
+
}
|
|
270
|
+
// Pad until full block byte with zeros
|
|
271
|
+
for (let i = pos; i < blockLen; i++)
|
|
272
|
+
buffer[i] = 0;
|
|
273
|
+
// Note: sha512 requires length to be 128bit integer, but length in JS will overflow before that
|
|
274
|
+
// You need to write around 2 exabytes (u64_max / 8 / (1024**6)) for this to happen.
|
|
275
|
+
// So we just write lowest 64 bits of that value.
|
|
276
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
277
|
+
this.process(view, 0);
|
|
278
|
+
const oview = (0, utils_js_1.createView)(out);
|
|
279
|
+
const len = this.outputLen;
|
|
280
|
+
// NOTE: we do division by 4 later, which should be fused in single op with modulo by JIT
|
|
281
|
+
if (len % 4)
|
|
282
|
+
throw new Error('_sha2: outputLen should be aligned to 32bit');
|
|
283
|
+
const outLen = len / 4;
|
|
284
|
+
const state = this.get();
|
|
285
|
+
if (outLen > state.length)
|
|
286
|
+
throw new Error('_sha2: outputLen bigger than state');
|
|
287
|
+
for (let i = 0; i < outLen; i++)
|
|
288
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
289
|
+
}
|
|
290
|
+
digest() {
|
|
291
|
+
const { buffer, outputLen } = this;
|
|
292
|
+
this.digestInto(buffer);
|
|
293
|
+
const res = buffer.slice(0, outputLen);
|
|
294
|
+
this.destroy();
|
|
295
|
+
return res;
|
|
296
|
+
}
|
|
297
|
+
_cloneInto(to) {
|
|
298
|
+
to || (to = new this.constructor());
|
|
299
|
+
to.set(...this.get());
|
|
300
|
+
const { blockLen, buffer, length, finished, destroyed, pos } = this;
|
|
301
|
+
to.length = length;
|
|
302
|
+
to.pos = pos;
|
|
303
|
+
to.finished = finished;
|
|
304
|
+
to.destroyed = destroyed;
|
|
305
|
+
if (length % blockLen)
|
|
306
|
+
to.buffer.set(buffer);
|
|
307
|
+
return to;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
exports.SHA2 = SHA2;
|
|
311
|
+
//# sourceMappingURL=_sha2.js.map
|
|
312
|
+
|
|
313
|
+
/***/ }),
|
|
314
|
+
|
|
315
|
+
/***/ "./node_modules/@noble/hashes/_u64.js":
|
|
316
|
+
/*!********************************************!*\
|
|
317
|
+
!*** ./node_modules/@noble/hashes/_u64.js ***!
|
|
318
|
+
\********************************************/
|
|
319
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
320
|
+
|
|
321
|
+
"use strict";
|
|
322
|
+
|
|
323
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
324
|
+
exports.add = exports.toBig = exports.split = exports.fromBig = void 0;
|
|
325
|
+
const U32_MASK64 = BigInt(2 ** 32 - 1);
|
|
326
|
+
const _32n = BigInt(32);
|
|
327
|
+
// We are not using BigUint64Array, because they are extremely slow as per 2022
|
|
328
|
+
function fromBig(n, le = false) {
|
|
329
|
+
if (le)
|
|
330
|
+
return { h: Number(n & U32_MASK64), l: Number((n >> _32n) & U32_MASK64) };
|
|
331
|
+
return { h: Number((n >> _32n) & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
332
|
+
}
|
|
333
|
+
exports.fromBig = fromBig;
|
|
334
|
+
function split(lst, le = false) {
|
|
335
|
+
let Ah = new Uint32Array(lst.length);
|
|
336
|
+
let Al = new Uint32Array(lst.length);
|
|
337
|
+
for (let i = 0; i < lst.length; i++) {
|
|
338
|
+
const { h, l } = fromBig(lst[i], le);
|
|
339
|
+
[Ah[i], Al[i]] = [h, l];
|
|
340
|
+
}
|
|
341
|
+
return [Ah, Al];
|
|
342
|
+
}
|
|
343
|
+
exports.split = split;
|
|
344
|
+
const toBig = (h, l) => (BigInt(h >>> 0) << _32n) | BigInt(l >>> 0);
|
|
345
|
+
exports.toBig = toBig;
|
|
346
|
+
// for Shift in [0, 32)
|
|
347
|
+
const shrSH = (h, l, s) => h >>> s;
|
|
348
|
+
const shrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
349
|
+
// Right rotate for Shift in [1, 32)
|
|
350
|
+
const rotrSH = (h, l, s) => (h >>> s) | (l << (32 - s));
|
|
351
|
+
const rotrSL = (h, l, s) => (h << (32 - s)) | (l >>> s);
|
|
352
|
+
// Right rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
353
|
+
const rotrBH = (h, l, s) => (h << (64 - s)) | (l >>> (s - 32));
|
|
354
|
+
const rotrBL = (h, l, s) => (h >>> (s - 32)) | (l << (64 - s));
|
|
355
|
+
// Right rotate for shift===32 (just swaps l&h)
|
|
356
|
+
const rotr32H = (h, l) => l;
|
|
357
|
+
const rotr32L = (h, l) => h;
|
|
358
|
+
// Left rotate for Shift in [1, 32)
|
|
359
|
+
const rotlSH = (h, l, s) => (h << s) | (l >>> (32 - s));
|
|
360
|
+
const rotlSL = (h, l, s) => (l << s) | (h >>> (32 - s));
|
|
361
|
+
// Left rotate for Shift in (32, 64), NOTE: 32 is special case.
|
|
362
|
+
const rotlBH = (h, l, s) => (l << (s - 32)) | (h >>> (64 - s));
|
|
363
|
+
const rotlBL = (h, l, s) => (h << (s - 32)) | (l >>> (64 - s));
|
|
364
|
+
// JS uses 32-bit signed integers for bitwise operations which means we cannot
|
|
365
|
+
// simple take carry out of low bit sum by shift, we need to use division.
|
|
366
|
+
// Removing "export" has 5% perf penalty -_-
|
|
367
|
+
function add(Ah, Al, Bh, Bl) {
|
|
368
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
369
|
+
return { h: (Ah + Bh + ((l / 2 ** 32) | 0)) | 0, l: l | 0 };
|
|
370
|
+
}
|
|
371
|
+
exports.add = add;
|
|
372
|
+
// Addition with more than 2 elements
|
|
373
|
+
const add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
374
|
+
const add3H = (low, Ah, Bh, Ch) => (Ah + Bh + Ch + ((low / 2 ** 32) | 0)) | 0;
|
|
375
|
+
const add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
376
|
+
const add4H = (low, Ah, Bh, Ch, Dh) => (Ah + Bh + Ch + Dh + ((low / 2 ** 32) | 0)) | 0;
|
|
377
|
+
const add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
378
|
+
const add5H = (low, Ah, Bh, Ch, Dh, Eh) => (Ah + Bh + Ch + Dh + Eh + ((low / 2 ** 32) | 0)) | 0;
|
|
379
|
+
// prettier-ignore
|
|
380
|
+
const u64 = {
|
|
381
|
+
fromBig, split, toBig: exports.toBig,
|
|
382
|
+
shrSH, shrSL,
|
|
383
|
+
rotrSH, rotrSL, rotrBH, rotrBL,
|
|
384
|
+
rotr32H, rotr32L,
|
|
385
|
+
rotlSH, rotlSL, rotlBH, rotlBL,
|
|
386
|
+
add, add3L, add3H, add4L, add4H, add5H, add5L,
|
|
387
|
+
};
|
|
388
|
+
exports["default"] = u64;
|
|
389
|
+
//# sourceMappingURL=_u64.js.map
|
|
390
|
+
|
|
391
|
+
/***/ }),
|
|
392
|
+
|
|
393
|
+
/***/ "./node_modules/@noble/hashes/blake2s.js":
|
|
394
|
+
/*!***********************************************!*\
|
|
395
|
+
!*** ./node_modules/@noble/hashes/blake2s.js ***!
|
|
396
|
+
\***********************************************/
|
|
397
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
398
|
+
|
|
399
|
+
"use strict";
|
|
400
|
+
|
|
401
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
402
|
+
exports.blake2s = exports.compress = exports.IV = void 0;
|
|
403
|
+
const _blake2_js_1 = __webpack_require__(/*! ./_blake2.js */ "./node_modules/@noble/hashes/_blake2.js");
|
|
404
|
+
const _u64_js_1 = __webpack_require__(/*! ./_u64.js */ "./node_modules/@noble/hashes/_u64.js");
|
|
405
|
+
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
406
|
+
// Initial state:
|
|
407
|
+
// first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19)
|
|
408
|
+
// same as SHA-256
|
|
409
|
+
// prettier-ignore
|
|
410
|
+
exports.IV = new Uint32Array([
|
|
411
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
412
|
+
]);
|
|
413
|
+
// Mixing function G splitted in two halfs
|
|
414
|
+
function G1(a, b, c, d, x) {
|
|
415
|
+
a = (a + b + x) | 0;
|
|
416
|
+
d = (0, utils_js_1.rotr)(d ^ a, 16);
|
|
417
|
+
c = (c + d) | 0;
|
|
418
|
+
b = (0, utils_js_1.rotr)(b ^ c, 12);
|
|
419
|
+
return { a, b, c, d };
|
|
420
|
+
}
|
|
421
|
+
function G2(a, b, c, d, x) {
|
|
422
|
+
a = (a + b + x) | 0;
|
|
423
|
+
d = (0, utils_js_1.rotr)(d ^ a, 8);
|
|
424
|
+
c = (c + d) | 0;
|
|
425
|
+
b = (0, utils_js_1.rotr)(b ^ c, 7);
|
|
426
|
+
return { a, b, c, d };
|
|
427
|
+
}
|
|
428
|
+
// prettier-ignore
|
|
429
|
+
function compress(s, offset, msg, rounds, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) {
|
|
430
|
+
let j = 0;
|
|
431
|
+
for (let i = 0; i < rounds; i++) {
|
|
432
|
+
({ a: v0, b: v4, c: v8, d: v12 } = G1(v0, v4, v8, v12, msg[offset + s[j++]]));
|
|
433
|
+
({ a: v0, b: v4, c: v8, d: v12 } = G2(v0, v4, v8, v12, msg[offset + s[j++]]));
|
|
434
|
+
({ a: v1, b: v5, c: v9, d: v13 } = G1(v1, v5, v9, v13, msg[offset + s[j++]]));
|
|
435
|
+
({ a: v1, b: v5, c: v9, d: v13 } = G2(v1, v5, v9, v13, msg[offset + s[j++]]));
|
|
436
|
+
({ a: v2, b: v6, c: v10, d: v14 } = G1(v2, v6, v10, v14, msg[offset + s[j++]]));
|
|
437
|
+
({ a: v2, b: v6, c: v10, d: v14 } = G2(v2, v6, v10, v14, msg[offset + s[j++]]));
|
|
438
|
+
({ a: v3, b: v7, c: v11, d: v15 } = G1(v3, v7, v11, v15, msg[offset + s[j++]]));
|
|
439
|
+
({ a: v3, b: v7, c: v11, d: v15 } = G2(v3, v7, v11, v15, msg[offset + s[j++]]));
|
|
440
|
+
({ a: v0, b: v5, c: v10, d: v15 } = G1(v0, v5, v10, v15, msg[offset + s[j++]]));
|
|
441
|
+
({ a: v0, b: v5, c: v10, d: v15 } = G2(v0, v5, v10, v15, msg[offset + s[j++]]));
|
|
442
|
+
({ a: v1, b: v6, c: v11, d: v12 } = G1(v1, v6, v11, v12, msg[offset + s[j++]]));
|
|
443
|
+
({ a: v1, b: v6, c: v11, d: v12 } = G2(v1, v6, v11, v12, msg[offset + s[j++]]));
|
|
444
|
+
({ a: v2, b: v7, c: v8, d: v13 } = G1(v2, v7, v8, v13, msg[offset + s[j++]]));
|
|
445
|
+
({ a: v2, b: v7, c: v8, d: v13 } = G2(v2, v7, v8, v13, msg[offset + s[j++]]));
|
|
446
|
+
({ a: v3, b: v4, c: v9, d: v14 } = G1(v3, v4, v9, v14, msg[offset + s[j++]]));
|
|
447
|
+
({ a: v3, b: v4, c: v9, d: v14 } = G2(v3, v4, v9, v14, msg[offset + s[j++]]));
|
|
448
|
+
}
|
|
449
|
+
return { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 };
|
|
450
|
+
}
|
|
451
|
+
exports.compress = compress;
|
|
452
|
+
class BLAKE2s extends _blake2_js_1.BLAKE2 {
|
|
453
|
+
constructor(opts = {}) {
|
|
454
|
+
super(64, opts.dkLen === undefined ? 32 : opts.dkLen, opts, 32, 8, 8);
|
|
455
|
+
// Internal state, same as SHA-256
|
|
456
|
+
this.v0 = exports.IV[0] | 0;
|
|
457
|
+
this.v1 = exports.IV[1] | 0;
|
|
458
|
+
this.v2 = exports.IV[2] | 0;
|
|
459
|
+
this.v3 = exports.IV[3] | 0;
|
|
460
|
+
this.v4 = exports.IV[4] | 0;
|
|
461
|
+
this.v5 = exports.IV[5] | 0;
|
|
462
|
+
this.v6 = exports.IV[6] | 0;
|
|
463
|
+
this.v7 = exports.IV[7] | 0;
|
|
464
|
+
const keyLength = opts.key ? opts.key.length : 0;
|
|
465
|
+
this.v0 ^= this.outputLen | (keyLength << 8) | (0x01 << 16) | (0x01 << 24);
|
|
466
|
+
if (opts.salt) {
|
|
467
|
+
const salt = (0, utils_js_1.u32)((0, utils_js_1.toBytes)(opts.salt));
|
|
468
|
+
this.v4 ^= salt[0];
|
|
469
|
+
this.v5 ^= salt[1];
|
|
470
|
+
}
|
|
471
|
+
if (opts.personalization) {
|
|
472
|
+
const pers = (0, utils_js_1.u32)((0, utils_js_1.toBytes)(opts.personalization));
|
|
473
|
+
this.v6 ^= pers[0];
|
|
474
|
+
this.v7 ^= pers[1];
|
|
475
|
+
}
|
|
476
|
+
if (opts.key) {
|
|
477
|
+
// Pad to blockLen and update
|
|
478
|
+
const tmp = new Uint8Array(this.blockLen);
|
|
479
|
+
tmp.set((0, utils_js_1.toBytes)(opts.key));
|
|
480
|
+
this.update(tmp);
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
get() {
|
|
484
|
+
const { v0, v1, v2, v3, v4, v5, v6, v7 } = this;
|
|
485
|
+
return [v0, v1, v2, v3, v4, v5, v6, v7];
|
|
486
|
+
}
|
|
487
|
+
// prettier-ignore
|
|
488
|
+
set(v0, v1, v2, v3, v4, v5, v6, v7) {
|
|
489
|
+
this.v0 = v0 | 0;
|
|
490
|
+
this.v1 = v1 | 0;
|
|
491
|
+
this.v2 = v2 | 0;
|
|
492
|
+
this.v3 = v3 | 0;
|
|
493
|
+
this.v4 = v4 | 0;
|
|
494
|
+
this.v5 = v5 | 0;
|
|
495
|
+
this.v6 = v6 | 0;
|
|
496
|
+
this.v7 = v7 | 0;
|
|
497
|
+
}
|
|
498
|
+
compress(msg, offset, isLast) {
|
|
499
|
+
const { h, l } = _u64_js_1.default.fromBig(BigInt(this.length));
|
|
500
|
+
// prettier-ignore
|
|
501
|
+
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = compress(_blake2_js_1.SIGMA, offset, msg, 10, this.v0, this.v1, this.v2, this.v3, this.v4, this.v5, this.v6, this.v7, exports.IV[0], exports.IV[1], exports.IV[2], exports.IV[3], l ^ exports.IV[4], h ^ exports.IV[5], isLast ? ~exports.IV[6] : exports.IV[6], exports.IV[7]);
|
|
502
|
+
this.v0 ^= v0 ^ v8;
|
|
503
|
+
this.v1 ^= v1 ^ v9;
|
|
504
|
+
this.v2 ^= v2 ^ v10;
|
|
505
|
+
this.v3 ^= v3 ^ v11;
|
|
506
|
+
this.v4 ^= v4 ^ v12;
|
|
507
|
+
this.v5 ^= v5 ^ v13;
|
|
508
|
+
this.v6 ^= v6 ^ v14;
|
|
509
|
+
this.v7 ^= v7 ^ v15;
|
|
510
|
+
}
|
|
511
|
+
destroy() {
|
|
512
|
+
this.destroyed = true;
|
|
513
|
+
this.buffer32.fill(0);
|
|
514
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* BLAKE2s - optimized for 32-bit platforms. JS doesn't have uint64, so it's faster than BLAKE2b.
|
|
519
|
+
* @param msg - message that would be hashed
|
|
520
|
+
* @param opts - dkLen, key, salt, personalization
|
|
521
|
+
*/
|
|
522
|
+
exports.blake2s = (0, utils_js_1.wrapConstructorWithOpts)((opts) => new BLAKE2s(opts));
|
|
523
|
+
//# sourceMappingURL=blake2s.js.map
|
|
524
|
+
|
|
525
|
+
/***/ }),
|
|
526
|
+
|
|
527
|
+
/***/ "./node_modules/@noble/hashes/blake3.js":
|
|
528
|
+
/*!**********************************************!*\
|
|
529
|
+
!*** ./node_modules/@noble/hashes/blake3.js ***!
|
|
530
|
+
\**********************************************/
|
|
531
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
532
|
+
|
|
533
|
+
"use strict";
|
|
534
|
+
|
|
535
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
536
|
+
exports.blake3 = void 0;
|
|
537
|
+
const _assert_js_1 = __webpack_require__(/*! ./_assert.js */ "./node_modules/@noble/hashes/_assert.js");
|
|
538
|
+
const _u64_js_1 = __webpack_require__(/*! ./_u64.js */ "./node_modules/@noble/hashes/_u64.js");
|
|
539
|
+
const _blake2_js_1 = __webpack_require__(/*! ./_blake2.js */ "./node_modules/@noble/hashes/_blake2.js");
|
|
540
|
+
const blake2s_js_1 = __webpack_require__(/*! ./blake2s.js */ "./node_modules/@noble/hashes/blake2s.js");
|
|
541
|
+
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
542
|
+
// Flag bitset
|
|
543
|
+
var Flags;
|
|
544
|
+
(function (Flags) {
|
|
545
|
+
Flags[Flags["CHUNK_START"] = 1] = "CHUNK_START";
|
|
546
|
+
Flags[Flags["CHUNK_END"] = 2] = "CHUNK_END";
|
|
547
|
+
Flags[Flags["PARENT"] = 4] = "PARENT";
|
|
548
|
+
Flags[Flags["ROOT"] = 8] = "ROOT";
|
|
549
|
+
Flags[Flags["KEYED_HASH"] = 16] = "KEYED_HASH";
|
|
550
|
+
Flags[Flags["DERIVE_KEY_CONTEXT"] = 32] = "DERIVE_KEY_CONTEXT";
|
|
551
|
+
Flags[Flags["DERIVE_KEY_MATERIAL"] = 64] = "DERIVE_KEY_MATERIAL";
|
|
552
|
+
})(Flags || (Flags = {}));
|
|
553
|
+
const SIGMA = (() => {
|
|
554
|
+
const Id = Array.from({ length: 16 }, (_, i) => i);
|
|
555
|
+
const permute = (arr) => [2, 6, 3, 10, 7, 0, 4, 13, 1, 11, 12, 5, 9, 14, 15, 8].map((i) => arr[i]);
|
|
556
|
+
const res = [];
|
|
557
|
+
for (let i = 0, v = Id; i < 7; i++, v = permute(v))
|
|
558
|
+
res.push(...v);
|
|
559
|
+
return Uint8Array.from(res);
|
|
560
|
+
})();
|
|
561
|
+
// Why is this so slow? It should be 6x faster than blake2b.
|
|
562
|
+
// - There is only 30% reduction in number of rounds from blake2s
|
|
563
|
+
// - This function uses tree mode to achive parallelisation via SIMD and threading,
|
|
564
|
+
// however in JS we don't have threads and SIMD, so we get only overhead from tree structure
|
|
565
|
+
// - It is possible to speed it up via Web Workers, hovewer it will make code singnificantly more
|
|
566
|
+
// complicated, which we are trying to avoid, since this library is intended to be used
|
|
567
|
+
// for cryptographic purposes. Also, parallelization happens only on chunk level (1024 bytes),
|
|
568
|
+
// which won't really benefit small inputs.
|
|
569
|
+
class BLAKE3 extends _blake2_js_1.BLAKE2 {
|
|
570
|
+
constructor(opts = {}, flags = 0) {
|
|
571
|
+
super(64, opts.dkLen === undefined ? 32 : opts.dkLen, {}, Number.MAX_SAFE_INTEGER, 0, 0);
|
|
572
|
+
this.flags = 0 | 0;
|
|
573
|
+
this.chunkPos = 0; // Position of current block in chunk
|
|
574
|
+
this.chunksDone = 0; // How many chunks we already have
|
|
575
|
+
this.stack = [];
|
|
576
|
+
// Output
|
|
577
|
+
this.posOut = 0;
|
|
578
|
+
this.bufferOut32 = new Uint32Array(16);
|
|
579
|
+
this.chunkOut = 0; // index of output chunk
|
|
580
|
+
this.enableXOF = true;
|
|
581
|
+
this.outputLen = opts.dkLen === undefined ? 32 : opts.dkLen;
|
|
582
|
+
_assert_js_1.default.number(this.outputLen);
|
|
583
|
+
if (opts.key !== undefined && opts.context !== undefined)
|
|
584
|
+
throw new Error('Blake3: only key or context can be specified at same time');
|
|
585
|
+
else if (opts.key !== undefined) {
|
|
586
|
+
const key = (0, utils_js_1.toBytes)(opts.key).slice();
|
|
587
|
+
if (key.length !== 32)
|
|
588
|
+
throw new Error('Blake3: key should be 32 byte');
|
|
589
|
+
this.IV = (0, utils_js_1.u32)(key);
|
|
590
|
+
this.flags = flags | Flags.KEYED_HASH;
|
|
591
|
+
}
|
|
592
|
+
else if (opts.context !== undefined) {
|
|
593
|
+
const context_key = new BLAKE3({ dkLen: 32 }, Flags.DERIVE_KEY_CONTEXT)
|
|
594
|
+
.update(opts.context)
|
|
595
|
+
.digest();
|
|
596
|
+
this.IV = (0, utils_js_1.u32)(context_key);
|
|
597
|
+
this.flags = flags | Flags.DERIVE_KEY_MATERIAL;
|
|
598
|
+
}
|
|
599
|
+
else {
|
|
600
|
+
this.IV = blake2s_js_1.IV.slice();
|
|
601
|
+
this.flags = flags;
|
|
602
|
+
}
|
|
603
|
+
this.state = this.IV.slice();
|
|
604
|
+
this.bufferOut = (0, utils_js_1.u8)(this.bufferOut32);
|
|
605
|
+
}
|
|
606
|
+
// Unused
|
|
607
|
+
get() {
|
|
608
|
+
return [];
|
|
609
|
+
}
|
|
610
|
+
set() { }
|
|
611
|
+
b2Compress(counter, flags, buf, bufPos = 0) {
|
|
612
|
+
const { state: s, pos } = this;
|
|
613
|
+
const { h, l } = _u64_js_1.default.fromBig(BigInt(counter), true);
|
|
614
|
+
// prettier-ignore
|
|
615
|
+
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = (0, blake2s_js_1.compress)(SIGMA, bufPos, buf, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], blake2s_js_1.IV[0], blake2s_js_1.IV[1], blake2s_js_1.IV[2], blake2s_js_1.IV[3], h, l, pos, flags);
|
|
616
|
+
s[0] = v0 ^ v8;
|
|
617
|
+
s[1] = v1 ^ v9;
|
|
618
|
+
s[2] = v2 ^ v10;
|
|
619
|
+
s[3] = v3 ^ v11;
|
|
620
|
+
s[4] = v4 ^ v12;
|
|
621
|
+
s[5] = v5 ^ v13;
|
|
622
|
+
s[6] = v6 ^ v14;
|
|
623
|
+
s[7] = v7 ^ v15;
|
|
624
|
+
}
|
|
625
|
+
compress(buf, bufPos = 0, isLast = false) {
|
|
626
|
+
// Compress last block
|
|
627
|
+
let flags = this.flags;
|
|
628
|
+
if (!this.chunkPos)
|
|
629
|
+
flags |= Flags.CHUNK_START;
|
|
630
|
+
if (this.chunkPos === 15 || isLast)
|
|
631
|
+
flags |= Flags.CHUNK_END;
|
|
632
|
+
if (!isLast)
|
|
633
|
+
this.pos = this.blockLen;
|
|
634
|
+
this.b2Compress(this.chunksDone, flags, buf, bufPos);
|
|
635
|
+
this.chunkPos += 1;
|
|
636
|
+
// If current block is last in chunk (16 blocks), then compress chunks
|
|
637
|
+
if (this.chunkPos === 16 || isLast) {
|
|
638
|
+
let chunk = this.state;
|
|
639
|
+
this.state = this.IV.slice();
|
|
640
|
+
// If not the last one, compress only when there are trailing zeros in chunk counter
|
|
641
|
+
// chunks used as binary tree where current stack is path. Zero means current leaf is finished and can be compressed.
|
|
642
|
+
// 1 (001) - leaf not finished (just push current chunk to stack)
|
|
643
|
+
// 2 (010) - leaf finished at depth=1 (merge with last elm on stack and push back)
|
|
644
|
+
// 3 (011) - last leaf not finished
|
|
645
|
+
// 4 (100) - leafs finished at depth=1 and depth=2
|
|
646
|
+
for (let last, chunks = this.chunksDone + 1; isLast || !(chunks & 1); chunks >>= 1) {
|
|
647
|
+
if (!(last = this.stack.pop()))
|
|
648
|
+
break;
|
|
649
|
+
this.buffer32.set(last, 0);
|
|
650
|
+
this.buffer32.set(chunk, 8);
|
|
651
|
+
this.pos = this.blockLen;
|
|
652
|
+
this.b2Compress(0, this.flags | Flags.PARENT, this.buffer32, 0);
|
|
653
|
+
chunk = this.state;
|
|
654
|
+
this.state = this.IV.slice();
|
|
655
|
+
}
|
|
656
|
+
this.chunksDone++;
|
|
657
|
+
this.chunkPos = 0;
|
|
658
|
+
this.stack.push(chunk);
|
|
659
|
+
}
|
|
660
|
+
this.pos = 0;
|
|
661
|
+
}
|
|
662
|
+
_cloneInto(to) {
|
|
663
|
+
to = super._cloneInto(to);
|
|
664
|
+
const { IV, flags, state, chunkPos, posOut, chunkOut, stack, chunksDone } = this;
|
|
665
|
+
to.state.set(state.slice());
|
|
666
|
+
to.stack = stack.map((i) => Uint32Array.from(i));
|
|
667
|
+
to.IV.set(IV);
|
|
668
|
+
to.flags = flags;
|
|
669
|
+
to.chunkPos = chunkPos;
|
|
670
|
+
to.chunksDone = chunksDone;
|
|
671
|
+
to.posOut = posOut;
|
|
672
|
+
to.chunkOut = chunkOut;
|
|
673
|
+
to.enableXOF = this.enableXOF;
|
|
674
|
+
to.bufferOut32.set(this.bufferOut32);
|
|
675
|
+
return to;
|
|
676
|
+
}
|
|
677
|
+
destroy() {
|
|
678
|
+
this.destroyed = true;
|
|
679
|
+
this.state.fill(0);
|
|
680
|
+
this.buffer32.fill(0);
|
|
681
|
+
this.IV.fill(0);
|
|
682
|
+
this.bufferOut32.fill(0);
|
|
683
|
+
for (let i of this.stack)
|
|
684
|
+
i.fill(0);
|
|
685
|
+
}
|
|
686
|
+
// Same as b2Compress, but doesn't modify state and returns 16 u32 array (instead of 8)
|
|
687
|
+
b2CompressOut() {
|
|
688
|
+
const { state: s, pos, flags, buffer32, bufferOut32: out32 } = this;
|
|
689
|
+
const { h, l } = _u64_js_1.default.fromBig(BigInt(this.chunkOut++));
|
|
690
|
+
// prettier-ignore
|
|
691
|
+
const { v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15 } = (0, blake2s_js_1.compress)(SIGMA, 0, buffer32, 7, s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], blake2s_js_1.IV[0], blake2s_js_1.IV[1], blake2s_js_1.IV[2], blake2s_js_1.IV[3], l, h, pos, flags);
|
|
692
|
+
out32[0] = v0 ^ v8;
|
|
693
|
+
out32[1] = v1 ^ v9;
|
|
694
|
+
out32[2] = v2 ^ v10;
|
|
695
|
+
out32[3] = v3 ^ v11;
|
|
696
|
+
out32[4] = v4 ^ v12;
|
|
697
|
+
out32[5] = v5 ^ v13;
|
|
698
|
+
out32[6] = v6 ^ v14;
|
|
699
|
+
out32[7] = v7 ^ v15;
|
|
700
|
+
out32[8] = s[0] ^ v8;
|
|
701
|
+
out32[9] = s[1] ^ v9;
|
|
702
|
+
out32[10] = s[2] ^ v10;
|
|
703
|
+
out32[11] = s[3] ^ v11;
|
|
704
|
+
out32[12] = s[4] ^ v12;
|
|
705
|
+
out32[13] = s[5] ^ v13;
|
|
706
|
+
out32[14] = s[6] ^ v14;
|
|
707
|
+
out32[15] = s[7] ^ v15;
|
|
708
|
+
this.posOut = 0;
|
|
709
|
+
}
|
|
710
|
+
finish() {
|
|
711
|
+
if (this.finished)
|
|
712
|
+
return;
|
|
713
|
+
this.finished = true;
|
|
714
|
+
// Padding
|
|
715
|
+
this.buffer.fill(0, this.pos);
|
|
716
|
+
// Process last chunk
|
|
717
|
+
let flags = this.flags | Flags.ROOT;
|
|
718
|
+
if (this.stack.length) {
|
|
719
|
+
flags |= Flags.PARENT;
|
|
720
|
+
this.compress(this.buffer32, 0, true);
|
|
721
|
+
this.chunksDone = 0;
|
|
722
|
+
this.pos = this.blockLen;
|
|
723
|
+
}
|
|
724
|
+
else {
|
|
725
|
+
flags |= (!this.chunkPos ? Flags.CHUNK_START : 0) | Flags.CHUNK_END;
|
|
726
|
+
}
|
|
727
|
+
this.flags = flags;
|
|
728
|
+
this.b2CompressOut();
|
|
729
|
+
}
|
|
730
|
+
writeInto(out) {
|
|
731
|
+
_assert_js_1.default.exists(this, false);
|
|
732
|
+
_assert_js_1.default.bytes(out);
|
|
733
|
+
this.finish();
|
|
734
|
+
const { blockLen, bufferOut } = this;
|
|
735
|
+
for (let pos = 0, len = out.length; pos < len;) {
|
|
736
|
+
if (this.posOut >= blockLen)
|
|
737
|
+
this.b2CompressOut();
|
|
738
|
+
const take = Math.min(blockLen - this.posOut, len - pos);
|
|
739
|
+
out.set(bufferOut.subarray(this.posOut, this.posOut + take), pos);
|
|
740
|
+
this.posOut += take;
|
|
741
|
+
pos += take;
|
|
742
|
+
}
|
|
743
|
+
return out;
|
|
744
|
+
}
|
|
745
|
+
xofInto(out) {
|
|
746
|
+
if (!this.enableXOF)
|
|
747
|
+
throw new Error('XOF is not possible after digest call');
|
|
748
|
+
return this.writeInto(out);
|
|
749
|
+
}
|
|
750
|
+
xof(bytes) {
|
|
751
|
+
_assert_js_1.default.number(bytes);
|
|
752
|
+
return this.xofInto(new Uint8Array(bytes));
|
|
753
|
+
}
|
|
754
|
+
digestInto(out) {
|
|
755
|
+
_assert_js_1.default.output(out, this);
|
|
756
|
+
if (this.finished)
|
|
757
|
+
throw new Error('digest() was already called');
|
|
758
|
+
this.enableXOF = false;
|
|
759
|
+
this.writeInto(out);
|
|
760
|
+
this.destroy();
|
|
761
|
+
return out;
|
|
762
|
+
}
|
|
763
|
+
digest() {
|
|
764
|
+
return this.digestInto(new Uint8Array(this.outputLen));
|
|
765
|
+
}
|
|
766
|
+
}
|
|
767
|
+
/**
|
|
768
|
+
* BLAKE3 hash function.
|
|
769
|
+
* @param msg - message that would be hashed
|
|
770
|
+
* @param opts - dkLen, key, context
|
|
771
|
+
*/
|
|
772
|
+
exports.blake3 = (0, utils_js_1.wrapXOFConstructorWithOpts)((opts) => new BLAKE3(opts));
|
|
773
|
+
//# sourceMappingURL=blake3.js.map
|
|
774
|
+
|
|
775
|
+
/***/ }),
|
|
776
|
+
|
|
777
|
+
/***/ "./node_modules/@noble/hashes/crypto.js":
|
|
778
|
+
/*!**********************************************!*\
|
|
779
|
+
!*** ./node_modules/@noble/hashes/crypto.js ***!
|
|
780
|
+
\**********************************************/
|
|
781
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
782
|
+
|
|
783
|
+
"use strict";
|
|
784
|
+
|
|
785
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
786
|
+
exports.crypto = void 0;
|
|
787
|
+
exports.crypto = typeof globalThis === 'object' && 'crypto' in globalThis ? globalThis.crypto : undefined;
|
|
788
|
+
//# sourceMappingURL=crypto.js.map
|
|
789
|
+
|
|
790
|
+
/***/ }),
|
|
791
|
+
|
|
792
|
+
/***/ "./node_modules/@noble/hashes/sha256.js":
|
|
793
|
+
/*!**********************************************!*\
|
|
794
|
+
!*** ./node_modules/@noble/hashes/sha256.js ***!
|
|
795
|
+
\**********************************************/
|
|
796
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
797
|
+
|
|
798
|
+
"use strict";
|
|
799
|
+
|
|
800
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
801
|
+
exports.sha224 = exports.sha256 = void 0;
|
|
802
|
+
const _sha2_js_1 = __webpack_require__(/*! ./_sha2.js */ "./node_modules/@noble/hashes/_sha2.js");
|
|
803
|
+
const utils_js_1 = __webpack_require__(/*! ./utils.js */ "./node_modules/@noble/hashes/utils.js");
|
|
804
|
+
// Choice: a ? b : c
|
|
805
|
+
const Chi = (a, b, c) => (a & b) ^ (~a & c);
|
|
806
|
+
// Majority function, true if any two inpust is true
|
|
807
|
+
const Maj = (a, b, c) => (a & b) ^ (a & c) ^ (b & c);
|
|
808
|
+
// Round constants:
|
|
809
|
+
// first 32 bits of the fractional parts of the cube roots of the first 64 primes 2..311)
|
|
810
|
+
// prettier-ignore
|
|
811
|
+
const SHA256_K = new Uint32Array([
|
|
812
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
813
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
814
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
815
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
816
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
817
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
818
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
819
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
820
|
+
]);
|
|
821
|
+
// Initial state (first 32 bits of the fractional parts of the square roots of the first 8 primes 2..19):
|
|
822
|
+
// prettier-ignore
|
|
823
|
+
const IV = new Uint32Array([
|
|
824
|
+
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19
|
|
825
|
+
]);
|
|
826
|
+
// Temporary buffer, not used to store anything between runs
|
|
827
|
+
// Named this way because it matches specification.
|
|
828
|
+
const SHA256_W = new Uint32Array(64);
|
|
829
|
+
class SHA256 extends _sha2_js_1.SHA2 {
|
|
830
|
+
constructor() {
|
|
831
|
+
super(64, 32, 8, false);
|
|
832
|
+
// We cannot use array here since array allows indexing by variable
|
|
833
|
+
// which means optimizer/compiler cannot use registers.
|
|
834
|
+
this.A = IV[0] | 0;
|
|
835
|
+
this.B = IV[1] | 0;
|
|
836
|
+
this.C = IV[2] | 0;
|
|
837
|
+
this.D = IV[3] | 0;
|
|
838
|
+
this.E = IV[4] | 0;
|
|
839
|
+
this.F = IV[5] | 0;
|
|
840
|
+
this.G = IV[6] | 0;
|
|
841
|
+
this.H = IV[7] | 0;
|
|
842
|
+
}
|
|
843
|
+
get() {
|
|
844
|
+
const { A, B, C, D, E, F, G, H } = this;
|
|
845
|
+
return [A, B, C, D, E, F, G, H];
|
|
846
|
+
}
|
|
847
|
+
// prettier-ignore
|
|
848
|
+
set(A, B, C, D, E, F, G, H) {
|
|
849
|
+
this.A = A | 0;
|
|
850
|
+
this.B = B | 0;
|
|
851
|
+
this.C = C | 0;
|
|
852
|
+
this.D = D | 0;
|
|
853
|
+
this.E = E | 0;
|
|
854
|
+
this.F = F | 0;
|
|
855
|
+
this.G = G | 0;
|
|
856
|
+
this.H = H | 0;
|
|
857
|
+
}
|
|
858
|
+
process(view, offset) {
|
|
859
|
+
// Extend the first 16 words into the remaining 48 words w[16..63] of the message schedule array
|
|
860
|
+
for (let i = 0; i < 16; i++, offset += 4)
|
|
861
|
+
SHA256_W[i] = view.getUint32(offset, false);
|
|
862
|
+
for (let i = 16; i < 64; i++) {
|
|
863
|
+
const W15 = SHA256_W[i - 15];
|
|
864
|
+
const W2 = SHA256_W[i - 2];
|
|
865
|
+
const s0 = (0, utils_js_1.rotr)(W15, 7) ^ (0, utils_js_1.rotr)(W15, 18) ^ (W15 >>> 3);
|
|
866
|
+
const s1 = (0, utils_js_1.rotr)(W2, 17) ^ (0, utils_js_1.rotr)(W2, 19) ^ (W2 >>> 10);
|
|
867
|
+
SHA256_W[i] = (s1 + SHA256_W[i - 7] + s0 + SHA256_W[i - 16]) | 0;
|
|
868
|
+
}
|
|
869
|
+
// Compression function main loop, 64 rounds
|
|
870
|
+
let { A, B, C, D, E, F, G, H } = this;
|
|
871
|
+
for (let i = 0; i < 64; i++) {
|
|
872
|
+
const sigma1 = (0, utils_js_1.rotr)(E, 6) ^ (0, utils_js_1.rotr)(E, 11) ^ (0, utils_js_1.rotr)(E, 25);
|
|
873
|
+
const T1 = (H + sigma1 + Chi(E, F, G) + SHA256_K[i] + SHA256_W[i]) | 0;
|
|
874
|
+
const sigma0 = (0, utils_js_1.rotr)(A, 2) ^ (0, utils_js_1.rotr)(A, 13) ^ (0, utils_js_1.rotr)(A, 22);
|
|
875
|
+
const T2 = (sigma0 + Maj(A, B, C)) | 0;
|
|
876
|
+
H = G;
|
|
877
|
+
G = F;
|
|
878
|
+
F = E;
|
|
879
|
+
E = (D + T1) | 0;
|
|
880
|
+
D = C;
|
|
881
|
+
C = B;
|
|
882
|
+
B = A;
|
|
883
|
+
A = (T1 + T2) | 0;
|
|
884
|
+
}
|
|
885
|
+
// Add the compressed chunk to the current hash value
|
|
886
|
+
A = (A + this.A) | 0;
|
|
887
|
+
B = (B + this.B) | 0;
|
|
888
|
+
C = (C + this.C) | 0;
|
|
889
|
+
D = (D + this.D) | 0;
|
|
890
|
+
E = (E + this.E) | 0;
|
|
891
|
+
F = (F + this.F) | 0;
|
|
892
|
+
G = (G + this.G) | 0;
|
|
893
|
+
H = (H + this.H) | 0;
|
|
894
|
+
this.set(A, B, C, D, E, F, G, H);
|
|
895
|
+
}
|
|
896
|
+
roundClean() {
|
|
897
|
+
SHA256_W.fill(0);
|
|
898
|
+
}
|
|
899
|
+
destroy() {
|
|
900
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
901
|
+
this.buffer.fill(0);
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
// Constants from https://nvlpubs.nist.gov/nistpubs/FIPS/NIST.FIPS.180-4.pdf
|
|
905
|
+
class SHA224 extends SHA256 {
|
|
906
|
+
constructor() {
|
|
907
|
+
super();
|
|
908
|
+
this.A = 0xc1059ed8 | 0;
|
|
909
|
+
this.B = 0x367cd507 | 0;
|
|
910
|
+
this.C = 0x3070dd17 | 0;
|
|
911
|
+
this.D = 0xf70e5939 | 0;
|
|
912
|
+
this.E = 0xffc00b31 | 0;
|
|
913
|
+
this.F = 0x68581511 | 0;
|
|
914
|
+
this.G = 0x64f98fa7 | 0;
|
|
915
|
+
this.H = 0xbefa4fa4 | 0;
|
|
916
|
+
this.outputLen = 28;
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
/**
|
|
920
|
+
* SHA2-256 hash function
|
|
921
|
+
* @param message - data that would be hashed
|
|
922
|
+
*/
|
|
923
|
+
exports.sha256 = (0, utils_js_1.wrapConstructor)(() => new SHA256());
|
|
924
|
+
exports.sha224 = (0, utils_js_1.wrapConstructor)(() => new SHA224());
|
|
925
|
+
//# sourceMappingURL=sha256.js.map
|
|
926
|
+
|
|
927
|
+
/***/ }),
|
|
928
|
+
|
|
929
|
+
/***/ "./node_modules/@noble/hashes/utils.js":
|
|
930
|
+
/*!*********************************************!*\
|
|
931
|
+
!*** ./node_modules/@noble/hashes/utils.js ***!
|
|
932
|
+
\*********************************************/
|
|
933
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
934
|
+
|
|
935
|
+
"use strict";
|
|
936
|
+
|
|
937
|
+
/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
938
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
939
|
+
exports.randomBytes = exports.wrapXOFConstructorWithOpts = exports.wrapConstructorWithOpts = exports.wrapConstructor = exports.checkOpts = exports.Hash = exports.concatBytes = exports.toBytes = exports.utf8ToBytes = exports.asyncLoop = exports.nextTick = exports.hexToBytes = exports.bytesToHex = exports.isLE = exports.rotr = exports.createView = exports.u32 = exports.u8 = void 0;
|
|
940
|
+
// We use WebCrypto aka globalThis.crypto, which exists in browsers and node.js 16+.
|
|
941
|
+
// node.js versions earlier than v19 don't declare it in global scope.
|
|
942
|
+
// For node.js, package.json#exports field mapping rewrites import
|
|
943
|
+
// from `crypto` to `cryptoNode`, which imports native module.
|
|
944
|
+
// Makes the utils un-importable in browsers without a bundler.
|
|
945
|
+
// Once node.js 18 is deprecated, we can just drop the import.
|
|
946
|
+
const crypto_1 = __webpack_require__(/*! @noble/hashes/crypto */ "./node_modules/@noble/hashes/crypto.js");
|
|
947
|
+
const u8a = (a) => a instanceof Uint8Array;
|
|
948
|
+
// Cast array to different type
|
|
949
|
+
const u8 = (arr) => new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
950
|
+
exports.u8 = u8;
|
|
951
|
+
const u32 = (arr) => new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
952
|
+
exports.u32 = u32;
|
|
953
|
+
// Cast array to view
|
|
954
|
+
const createView = (arr) => new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
955
|
+
exports.createView = createView;
|
|
956
|
+
// The rotate right (circular right shift) operation for uint32
|
|
957
|
+
const rotr = (word, shift) => (word << (32 - shift)) | (word >>> shift);
|
|
958
|
+
exports.rotr = rotr;
|
|
959
|
+
// big-endian hardware is rare. Just in case someone still decides to run hashes:
|
|
960
|
+
// early-throw an error because we don't support BE yet.
|
|
961
|
+
exports.isLE = new Uint8Array(new Uint32Array([0x11223344]).buffer)[0] === 0x44;
|
|
962
|
+
if (!exports.isLE)
|
|
963
|
+
throw new Error('Non little-endian hardware is not supported');
|
|
964
|
+
const hexes = Array.from({ length: 256 }, (v, i) => i.toString(16).padStart(2, '0'));
|
|
965
|
+
/**
|
|
966
|
+
* @example bytesToHex(Uint8Array.from([0xca, 0xfe, 0x01, 0x23])) // 'cafe0123'
|
|
967
|
+
*/
|
|
968
|
+
function bytesToHex(bytes) {
|
|
969
|
+
if (!u8a(bytes))
|
|
970
|
+
throw new Error('Uint8Array expected');
|
|
971
|
+
// pre-caching improves the speed 6x
|
|
972
|
+
let hex = '';
|
|
973
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
974
|
+
hex += hexes[bytes[i]];
|
|
975
|
+
}
|
|
976
|
+
return hex;
|
|
977
|
+
}
|
|
978
|
+
exports.bytesToHex = bytesToHex;
|
|
979
|
+
/**
|
|
980
|
+
* @example hexToBytes('cafe0123') // Uint8Array.from([0xca, 0xfe, 0x01, 0x23])
|
|
981
|
+
*/
|
|
982
|
+
function hexToBytes(hex) {
|
|
983
|
+
if (typeof hex !== 'string')
|
|
984
|
+
throw new Error('hex string expected, got ' + typeof hex);
|
|
985
|
+
const len = hex.length;
|
|
986
|
+
if (len % 2)
|
|
987
|
+
throw new Error('padded hex string expected, got unpadded hex of length ' + len);
|
|
988
|
+
const array = new Uint8Array(len / 2);
|
|
989
|
+
for (let i = 0; i < array.length; i++) {
|
|
990
|
+
const j = i * 2;
|
|
991
|
+
const hexByte = hex.slice(j, j + 2);
|
|
992
|
+
const byte = Number.parseInt(hexByte, 16);
|
|
993
|
+
if (Number.isNaN(byte) || byte < 0)
|
|
994
|
+
throw new Error('Invalid byte sequence');
|
|
995
|
+
array[i] = byte;
|
|
996
|
+
}
|
|
997
|
+
return array;
|
|
998
|
+
}
|
|
999
|
+
exports.hexToBytes = hexToBytes;
|
|
1000
|
+
// There is no setImmediate in browser and setTimeout is slow.
|
|
1001
|
+
// call of async fn will return Promise, which will be fullfiled only on
|
|
1002
|
+
// next scheduler queue processing step and this is exactly what we need.
|
|
1003
|
+
const nextTick = async () => { };
|
|
1004
|
+
exports.nextTick = nextTick;
|
|
1005
|
+
// Returns control to thread each 'tick' ms to avoid blocking
|
|
1006
|
+
async function asyncLoop(iters, tick, cb) {
|
|
1007
|
+
let ts = Date.now();
|
|
1008
|
+
for (let i = 0; i < iters; i++) {
|
|
1009
|
+
cb(i);
|
|
1010
|
+
// Date.now() is not monotonic, so in case if clock goes backwards we return return control too
|
|
1011
|
+
const diff = Date.now() - ts;
|
|
1012
|
+
if (diff >= 0 && diff < tick)
|
|
1013
|
+
continue;
|
|
1014
|
+
await (0, exports.nextTick)();
|
|
1015
|
+
ts += diff;
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
exports.asyncLoop = asyncLoop;
|
|
1019
|
+
/**
|
|
1020
|
+
* @example utf8ToBytes('abc') // new Uint8Array([97, 98, 99])
|
|
1021
|
+
*/
|
|
1022
|
+
function utf8ToBytes(str) {
|
|
1023
|
+
if (typeof str !== 'string')
|
|
1024
|
+
throw new Error(`utf8ToBytes expected string, got ${typeof str}`);
|
|
1025
|
+
return new Uint8Array(new TextEncoder().encode(str)); // https://bugzil.la/1681809
|
|
1026
|
+
}
|
|
1027
|
+
exports.utf8ToBytes = utf8ToBytes;
|
|
1028
|
+
/**
|
|
1029
|
+
* Normalizes (non-hex) string or Uint8Array to Uint8Array.
|
|
1030
|
+
* Warning: when Uint8Array is passed, it would NOT get copied.
|
|
1031
|
+
* Keep in mind for future mutable operations.
|
|
1032
|
+
*/
|
|
1033
|
+
function toBytes(data) {
|
|
1034
|
+
if (typeof data === 'string')
|
|
1035
|
+
data = utf8ToBytes(data);
|
|
1036
|
+
if (!u8a(data))
|
|
1037
|
+
throw new Error(`expected Uint8Array, got ${typeof data}`);
|
|
1038
|
+
return data;
|
|
1039
|
+
}
|
|
1040
|
+
exports.toBytes = toBytes;
|
|
1041
|
+
/**
|
|
1042
|
+
* Copies several Uint8Arrays into one.
|
|
1043
|
+
*/
|
|
1044
|
+
function concatBytes(...arrays) {
|
|
1045
|
+
const r = new Uint8Array(arrays.reduce((sum, a) => sum + a.length, 0));
|
|
1046
|
+
let pad = 0; // walk through each item, ensure they have proper type
|
|
1047
|
+
arrays.forEach((a) => {
|
|
1048
|
+
if (!u8a(a))
|
|
1049
|
+
throw new Error('Uint8Array expected');
|
|
1050
|
+
r.set(a, pad);
|
|
1051
|
+
pad += a.length;
|
|
1052
|
+
});
|
|
1053
|
+
return r;
|
|
1054
|
+
}
|
|
1055
|
+
exports.concatBytes = concatBytes;
|
|
1056
|
+
// For runtime check if class implements interface
|
|
1057
|
+
class Hash {
|
|
1058
|
+
// Safe version that clones internal state
|
|
1059
|
+
clone() {
|
|
1060
|
+
return this._cloneInto();
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
exports.Hash = Hash;
|
|
1064
|
+
// Check if object doens't have custom constructor (like Uint8Array/Array)
|
|
1065
|
+
const isPlainObject = (obj) => Object.prototype.toString.call(obj) === '[object Object]' && obj.constructor === Object;
|
|
1066
|
+
function checkOpts(defaults, opts) {
|
|
1067
|
+
if (opts !== undefined && (typeof opts !== 'object' || !isPlainObject(opts)))
|
|
1068
|
+
throw new Error('Options should be object or undefined');
|
|
1069
|
+
const merged = Object.assign(defaults, opts);
|
|
1070
|
+
return merged;
|
|
1071
|
+
}
|
|
1072
|
+
exports.checkOpts = checkOpts;
|
|
1073
|
+
function wrapConstructor(hashCons) {
|
|
1074
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
1075
|
+
const tmp = hashCons();
|
|
1076
|
+
hashC.outputLen = tmp.outputLen;
|
|
1077
|
+
hashC.blockLen = tmp.blockLen;
|
|
1078
|
+
hashC.create = () => hashCons();
|
|
1079
|
+
return hashC;
|
|
1080
|
+
}
|
|
1081
|
+
exports.wrapConstructor = wrapConstructor;
|
|
1082
|
+
function wrapConstructorWithOpts(hashCons) {
|
|
1083
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
1084
|
+
const tmp = hashCons({});
|
|
1085
|
+
hashC.outputLen = tmp.outputLen;
|
|
1086
|
+
hashC.blockLen = tmp.blockLen;
|
|
1087
|
+
hashC.create = (opts) => hashCons(opts);
|
|
1088
|
+
return hashC;
|
|
1089
|
+
}
|
|
1090
|
+
exports.wrapConstructorWithOpts = wrapConstructorWithOpts;
|
|
1091
|
+
function wrapXOFConstructorWithOpts(hashCons) {
|
|
1092
|
+
const hashC = (msg, opts) => hashCons(opts).update(toBytes(msg)).digest();
|
|
1093
|
+
const tmp = hashCons({});
|
|
1094
|
+
hashC.outputLen = tmp.outputLen;
|
|
1095
|
+
hashC.blockLen = tmp.blockLen;
|
|
1096
|
+
hashC.create = (opts) => hashCons(opts);
|
|
1097
|
+
return hashC;
|
|
1098
|
+
}
|
|
1099
|
+
exports.wrapXOFConstructorWithOpts = wrapXOFConstructorWithOpts;
|
|
1100
|
+
/**
|
|
1101
|
+
* Secure PRNG. Uses `crypto.getRandomValues`, which defers to OS.
|
|
1102
|
+
*/
|
|
1103
|
+
function randomBytes(bytesLength = 32) {
|
|
1104
|
+
if (crypto_1.crypto && typeof crypto_1.crypto.getRandomValues === 'function') {
|
|
1105
|
+
return crypto_1.crypto.getRandomValues(new Uint8Array(bytesLength));
|
|
1106
|
+
}
|
|
1107
|
+
throw new Error('crypto.getRandomValues must be defined');
|
|
1108
|
+
}
|
|
1109
|
+
exports.randomBytes = randomBytes;
|
|
1110
|
+
//# sourceMappingURL=utils.js.map
|
|
1111
|
+
|
|
1112
|
+
/***/ }),
|
|
1113
|
+
|
|
4
1114
|
/***/ "./node_modules/axios/index.js":
|
|
5
1115
|
/*!*************************************!*\
|
|
6
1116
|
!*** ./node_modules/axios/index.js ***!
|
|
@@ -2161,6 +3271,138 @@ module.exports = {
|
|
|
2161
3271
|
};
|
|
2162
3272
|
|
|
2163
3273
|
|
|
3274
|
+
/***/ }),
|
|
3275
|
+
|
|
3276
|
+
/***/ "./node_modules/base-x/src/index.js":
|
|
3277
|
+
/*!******************************************!*\
|
|
3278
|
+
!*** ./node_modules/base-x/src/index.js ***!
|
|
3279
|
+
\******************************************/
|
|
3280
|
+
/***/ ((module) => {
|
|
3281
|
+
|
|
3282
|
+
"use strict";
|
|
3283
|
+
|
|
3284
|
+
// base-x encoding / decoding
|
|
3285
|
+
// Copyright (c) 2018 base-x contributors
|
|
3286
|
+
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
3287
|
+
// Distributed under the MIT software license, see the accompanying
|
|
3288
|
+
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
3289
|
+
function base (ALPHABET) {
|
|
3290
|
+
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
3291
|
+
var BASE_MAP = new Uint8Array(256)
|
|
3292
|
+
for (var j = 0; j < BASE_MAP.length; j++) {
|
|
3293
|
+
BASE_MAP[j] = 255
|
|
3294
|
+
}
|
|
3295
|
+
for (var i = 0; i < ALPHABET.length; i++) {
|
|
3296
|
+
var x = ALPHABET.charAt(i)
|
|
3297
|
+
var xc = x.charCodeAt(0)
|
|
3298
|
+
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
3299
|
+
BASE_MAP[xc] = i
|
|
3300
|
+
}
|
|
3301
|
+
var BASE = ALPHABET.length
|
|
3302
|
+
var LEADER = ALPHABET.charAt(0)
|
|
3303
|
+
var FACTOR = Math.log(BASE) / Math.log(256) // log(BASE) / log(256), rounded up
|
|
3304
|
+
var iFACTOR = Math.log(256) / Math.log(BASE) // log(256) / log(BASE), rounded up
|
|
3305
|
+
function encode (source) {
|
|
3306
|
+
if (source instanceof Uint8Array) {
|
|
3307
|
+
} else if (ArrayBuffer.isView(source)) {
|
|
3308
|
+
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength)
|
|
3309
|
+
} else if (Array.isArray(source)) {
|
|
3310
|
+
source = Uint8Array.from(source)
|
|
3311
|
+
}
|
|
3312
|
+
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
3313
|
+
if (source.length === 0) { return '' }
|
|
3314
|
+
// Skip & count leading zeroes.
|
|
3315
|
+
var zeroes = 0
|
|
3316
|
+
var length = 0
|
|
3317
|
+
var pbegin = 0
|
|
3318
|
+
var pend = source.length
|
|
3319
|
+
while (pbegin !== pend && source[pbegin] === 0) {
|
|
3320
|
+
pbegin++
|
|
3321
|
+
zeroes++
|
|
3322
|
+
}
|
|
3323
|
+
// Allocate enough space in big-endian base58 representation.
|
|
3324
|
+
var size = ((pend - pbegin) * iFACTOR + 1) >>> 0
|
|
3325
|
+
var b58 = new Uint8Array(size)
|
|
3326
|
+
// Process the bytes.
|
|
3327
|
+
while (pbegin !== pend) {
|
|
3328
|
+
var carry = source[pbegin]
|
|
3329
|
+
// Apply "b58 = b58 * 256 + ch".
|
|
3330
|
+
var i = 0
|
|
3331
|
+
for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
3332
|
+
carry += (256 * b58[it1]) >>> 0
|
|
3333
|
+
b58[it1] = (carry % BASE) >>> 0
|
|
3334
|
+
carry = (carry / BASE) >>> 0
|
|
3335
|
+
}
|
|
3336
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3337
|
+
length = i
|
|
3338
|
+
pbegin++
|
|
3339
|
+
}
|
|
3340
|
+
// Skip leading zeroes in base58 result.
|
|
3341
|
+
var it2 = size - length
|
|
3342
|
+
while (it2 !== size && b58[it2] === 0) {
|
|
3343
|
+
it2++
|
|
3344
|
+
}
|
|
3345
|
+
// Translate the result into a string.
|
|
3346
|
+
var str = LEADER.repeat(zeroes)
|
|
3347
|
+
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]) }
|
|
3348
|
+
return str
|
|
3349
|
+
}
|
|
3350
|
+
function decodeUnsafe (source) {
|
|
3351
|
+
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
3352
|
+
if (source.length === 0) { return new Uint8Array() }
|
|
3353
|
+
var psz = 0
|
|
3354
|
+
// Skip and count leading '1's.
|
|
3355
|
+
var zeroes = 0
|
|
3356
|
+
var length = 0
|
|
3357
|
+
while (source[psz] === LEADER) {
|
|
3358
|
+
zeroes++
|
|
3359
|
+
psz++
|
|
3360
|
+
}
|
|
3361
|
+
// Allocate enough space in big-endian base256 representation.
|
|
3362
|
+
var size = (((source.length - psz) * FACTOR) + 1) >>> 0 // log(58) / log(256), rounded up.
|
|
3363
|
+
var b256 = new Uint8Array(size)
|
|
3364
|
+
// Process the characters.
|
|
3365
|
+
while (source[psz]) {
|
|
3366
|
+
// Decode character
|
|
3367
|
+
var carry = BASE_MAP[source.charCodeAt(psz)]
|
|
3368
|
+
// Invalid character
|
|
3369
|
+
if (carry === 255) { return }
|
|
3370
|
+
var i = 0
|
|
3371
|
+
for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
3372
|
+
carry += (BASE * b256[it3]) >>> 0
|
|
3373
|
+
b256[it3] = (carry % 256) >>> 0
|
|
3374
|
+
carry = (carry / 256) >>> 0
|
|
3375
|
+
}
|
|
3376
|
+
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
3377
|
+
length = i
|
|
3378
|
+
psz++
|
|
3379
|
+
}
|
|
3380
|
+
// Skip leading zeroes in b256.
|
|
3381
|
+
var it4 = size - length
|
|
3382
|
+
while (it4 !== size && b256[it4] === 0) {
|
|
3383
|
+
it4++
|
|
3384
|
+
}
|
|
3385
|
+
var vch = new Uint8Array(zeroes + (size - it4))
|
|
3386
|
+
var j = zeroes
|
|
3387
|
+
while (it4 !== size) {
|
|
3388
|
+
vch[j++] = b256[it4++]
|
|
3389
|
+
}
|
|
3390
|
+
return vch
|
|
3391
|
+
}
|
|
3392
|
+
function decode (string) {
|
|
3393
|
+
var buffer = decodeUnsafe(string)
|
|
3394
|
+
if (buffer) { return buffer }
|
|
3395
|
+
throw new Error('Non-base' + BASE + ' character')
|
|
3396
|
+
}
|
|
3397
|
+
return {
|
|
3398
|
+
encode: encode,
|
|
3399
|
+
decodeUnsafe: decodeUnsafe,
|
|
3400
|
+
decode: decode
|
|
3401
|
+
}
|
|
3402
|
+
}
|
|
3403
|
+
module.exports = base
|
|
3404
|
+
|
|
3405
|
+
|
|
2164
3406
|
/***/ }),
|
|
2165
3407
|
|
|
2166
3408
|
/***/ "./node_modules/base64-js/index.js":
|
|
@@ -2322,6 +3564,103 @@ function fromByteArray (uint8) {
|
|
|
2322
3564
|
}
|
|
2323
3565
|
|
|
2324
3566
|
|
|
3567
|
+
/***/ }),
|
|
3568
|
+
|
|
3569
|
+
/***/ "./node_modules/bs58/index.js":
|
|
3570
|
+
/*!************************************!*\
|
|
3571
|
+
!*** ./node_modules/bs58/index.js ***!
|
|
3572
|
+
\************************************/
|
|
3573
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
3574
|
+
|
|
3575
|
+
const basex = __webpack_require__(/*! base-x */ "./node_modules/base-x/src/index.js")
|
|
3576
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
|
|
3577
|
+
|
|
3578
|
+
module.exports = basex(ALPHABET)
|
|
3579
|
+
|
|
3580
|
+
|
|
3581
|
+
/***/ }),
|
|
3582
|
+
|
|
3583
|
+
/***/ "./node_modules/bs58check/base.js":
|
|
3584
|
+
/*!****************************************!*\
|
|
3585
|
+
!*** ./node_modules/bs58check/base.js ***!
|
|
3586
|
+
\****************************************/
|
|
3587
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
3588
|
+
|
|
3589
|
+
"use strict";
|
|
3590
|
+
|
|
3591
|
+
|
|
3592
|
+
var base58 = __webpack_require__(/*! bs58 */ "./node_modules/bs58/index.js")
|
|
3593
|
+
|
|
3594
|
+
module.exports = function (checksumFn) {
|
|
3595
|
+
// Encode a buffer as a base58-check encoded string
|
|
3596
|
+
function encode (payload) {
|
|
3597
|
+
var payloadU8 = Uint8Array.from(payload)
|
|
3598
|
+
var checksum = checksumFn(payloadU8)
|
|
3599
|
+
var length = payloadU8.length + 4
|
|
3600
|
+
var both = new Uint8Array(length)
|
|
3601
|
+
both.set(payloadU8, 0)
|
|
3602
|
+
both.set(checksum.subarray(0, 4), payloadU8.length)
|
|
3603
|
+
return base58.encode(both, length)
|
|
3604
|
+
}
|
|
3605
|
+
|
|
3606
|
+
function decodeRaw (buffer) {
|
|
3607
|
+
var payload = buffer.slice(0, -4)
|
|
3608
|
+
var checksum = buffer.slice(-4)
|
|
3609
|
+
var newChecksum = checksumFn(payload)
|
|
3610
|
+
|
|
3611
|
+
if (checksum[0] ^ newChecksum[0] |
|
|
3612
|
+
checksum[1] ^ newChecksum[1] |
|
|
3613
|
+
checksum[2] ^ newChecksum[2] |
|
|
3614
|
+
checksum[3] ^ newChecksum[3]) return
|
|
3615
|
+
|
|
3616
|
+
return payload
|
|
3617
|
+
}
|
|
3618
|
+
|
|
3619
|
+
// Decode a base58-check encoded string to a buffer, no result if checksum is wrong
|
|
3620
|
+
function decodeUnsafe (string) {
|
|
3621
|
+
var buffer = base58.decodeUnsafe(string)
|
|
3622
|
+
if (!buffer) return
|
|
3623
|
+
|
|
3624
|
+
return decodeRaw(buffer)
|
|
3625
|
+
}
|
|
3626
|
+
|
|
3627
|
+
function decode (string) {
|
|
3628
|
+
var buffer = base58.decode(string)
|
|
3629
|
+
var payload = decodeRaw(buffer, checksumFn)
|
|
3630
|
+
if (!payload) throw new Error('Invalid checksum')
|
|
3631
|
+
return payload
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
return {
|
|
3635
|
+
encode: encode,
|
|
3636
|
+
decode: decode,
|
|
3637
|
+
decodeUnsafe: decodeUnsafe
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
|
|
3641
|
+
|
|
3642
|
+
/***/ }),
|
|
3643
|
+
|
|
3644
|
+
/***/ "./node_modules/bs58check/index.js":
|
|
3645
|
+
/*!*****************************************!*\
|
|
3646
|
+
!*** ./node_modules/bs58check/index.js ***!
|
|
3647
|
+
\*****************************************/
|
|
3648
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
3649
|
+
|
|
3650
|
+
"use strict";
|
|
3651
|
+
|
|
3652
|
+
|
|
3653
|
+
var { sha256 } = __webpack_require__(/*! @noble/hashes/sha256 */ "./node_modules/@noble/hashes/sha256.js")
|
|
3654
|
+
var bs58checkBase = __webpack_require__(/*! ./base */ "./node_modules/bs58check/base.js")
|
|
3655
|
+
|
|
3656
|
+
// SHA256(SHA256(buffer))
|
|
3657
|
+
function sha256x2 (buffer) {
|
|
3658
|
+
return sha256(sha256(buffer))
|
|
3659
|
+
}
|
|
3660
|
+
|
|
3661
|
+
module.exports = bs58checkBase(sha256x2)
|
|
3662
|
+
|
|
3663
|
+
|
|
2325
3664
|
/***/ }),
|
|
2326
3665
|
|
|
2327
3666
|
/***/ "./node_modules/buffer/index.js":
|
|
@@ -5249,44 +6588,783 @@ Object.defineProperty(exports, "Account", ({ enumerable: true, get: function ()
|
|
|
5249
6588
|
|
|
5250
6589
|
/***/ }),
|
|
5251
6590
|
|
|
5252
|
-
/***/ "./src/
|
|
5253
|
-
|
|
5254
|
-
!*** ./src/
|
|
5255
|
-
|
|
6591
|
+
/***/ "./src/bearbyWallet/BearbyAccount.ts":
|
|
6592
|
+
/*!*******************************************!*\
|
|
6593
|
+
!*** ./src/bearbyWallet/BearbyAccount.ts ***!
|
|
6594
|
+
\*******************************************/
|
|
5256
6595
|
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
5257
6596
|
|
|
5258
6597
|
"use strict";
|
|
5259
6598
|
|
|
5260
6599
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
5261
|
-
exports.
|
|
6600
|
+
exports.getBytesPublicKey = exports.BearbyAccount = exports.requestHeaders = exports.OperationTypeId = exports.OperationsType = exports.PUBLIC_NODE_RPC = void 0;
|
|
6601
|
+
const bearby_js_1 = __webpack_require__(/*! @hicaru/bearby.js */ "./node_modules/@hicaru/bearby.js/dist/index.js");
|
|
6602
|
+
const RequestHandler_1 = __webpack_require__(/*! ../massaStation/RequestHandler */ "./src/massaStation/RequestHandler.ts");
|
|
6603
|
+
const jsonRpcMethods_1 = __webpack_require__(/*! ./jsonRpcMethods */ "./src/bearbyWallet/jsonRpcMethods.ts");
|
|
6604
|
+
const axios_1 = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
|
|
6605
|
+
const BearbyProvider_1 = __webpack_require__(/*! ./BearbyProvider */ "./src/bearbyWallet/BearbyProvider.ts");
|
|
6606
|
+
const Xbqcrypto_1 = __webpack_require__(/*! ./Xbqcrypto */ "./src/bearbyWallet/Xbqcrypto.ts");
|
|
5262
6607
|
/**
|
|
5263
|
-
*
|
|
5264
|
-
* It is the tool that allows the 'provider' and 'account' objects to communicate with the web page script.
|
|
5265
|
-
*
|
|
5266
|
-
* @remarks
|
|
5267
|
-
* - If you are only looking to use our library, the connector object will not be useful to you.
|
|
5268
|
-
* - If you want to work on this repo, you will probably be interested in this object
|
|
5269
|
-
*
|
|
6608
|
+
* The maximum allowed gas for a read operation
|
|
5270
6609
|
*/
|
|
5271
|
-
const
|
|
5272
|
-
const __1 = __webpack_require__(/*! .. */ "./src/index.ts");
|
|
5273
|
-
const MassaStationDiscovery_1 = __webpack_require__(/*! ../massaStation/MassaStationDiscovery */ "./src/massaStation/MassaStationDiscovery.ts");
|
|
5274
|
-
const MassaStationProvider_1 = __webpack_require__(/*! ../massaStation/MassaStationProvider */ "./src/massaStation/MassaStationProvider.ts");
|
|
6610
|
+
const MAX_READ_BLOCK_GAS = BigInt(4294967295);
|
|
5275
6611
|
/**
|
|
5276
|
-
*
|
|
5277
|
-
* communication between the web page script and the content script.
|
|
6612
|
+
* The RPC we are using to query the node
|
|
5278
6613
|
*/
|
|
5279
|
-
exports.
|
|
6614
|
+
exports.PUBLIC_NODE_RPC = 'https://buildnet.massa.net/api/v2';
|
|
6615
|
+
var OperationsType;
|
|
6616
|
+
(function (OperationsType) {
|
|
6617
|
+
OperationsType[OperationsType["Payment"] = 0] = "Payment";
|
|
6618
|
+
OperationsType[OperationsType["RollBuy"] = 1] = "RollBuy";
|
|
6619
|
+
OperationsType[OperationsType["RollSell"] = 2] = "RollSell";
|
|
6620
|
+
OperationsType[OperationsType["ExecuteSC"] = 3] = "ExecuteSC";
|
|
6621
|
+
OperationsType[OperationsType["CallSC"] = 4] = "CallSC";
|
|
6622
|
+
})(OperationsType = exports.OperationsType || (exports.OperationsType = {}));
|
|
5280
6623
|
/**
|
|
5281
|
-
*
|
|
5282
|
-
* @remarks
|
|
5283
|
-
* - This class is used to send messages to the content script and to receive messages from the content script.
|
|
5284
|
-
* - It is used to send messages to the content script and to receive messages from the content script.
|
|
5285
|
-
*
|
|
6624
|
+
* Associates an operation type with a number.
|
|
5286
6625
|
*/
|
|
5287
|
-
|
|
5288
|
-
|
|
5289
|
-
|
|
6626
|
+
var OperationTypeId;
|
|
6627
|
+
(function (OperationTypeId) {
|
|
6628
|
+
OperationTypeId[OperationTypeId["Transaction"] = 0] = "Transaction";
|
|
6629
|
+
OperationTypeId[OperationTypeId["RollBuy"] = 1] = "RollBuy";
|
|
6630
|
+
OperationTypeId[OperationTypeId["RollSell"] = 2] = "RollSell";
|
|
6631
|
+
OperationTypeId[OperationTypeId["ExecuteSC"] = 3] = "ExecuteSC";
|
|
6632
|
+
OperationTypeId[OperationTypeId["CallSC"] = 4] = "CallSC";
|
|
6633
|
+
})(OperationTypeId = exports.OperationTypeId || (exports.OperationTypeId = {}));
|
|
6634
|
+
exports.requestHeaders = {
|
|
6635
|
+
Accept: 'application/json,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
6636
|
+
'Access-Control-Allow-Origin': '*',
|
|
6637
|
+
'Access-Control-Allow-Credentials': true,
|
|
6638
|
+
'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,PATCH,OPTIONS',
|
|
6639
|
+
};
|
|
6640
|
+
class BearbyAccount {
|
|
6641
|
+
constructor({ address, name }, providerName) {
|
|
6642
|
+
this._nodeUrl = exports.PUBLIC_NODE_RPC;
|
|
6643
|
+
this._address = address;
|
|
6644
|
+
this._name = name ?? 'Bearby_account';
|
|
6645
|
+
this._providerName = providerName;
|
|
6646
|
+
}
|
|
6647
|
+
address() {
|
|
6648
|
+
return this._address;
|
|
6649
|
+
}
|
|
6650
|
+
name() {
|
|
6651
|
+
return this._name;
|
|
6652
|
+
}
|
|
6653
|
+
providerName() {
|
|
6654
|
+
return this._providerName;
|
|
6655
|
+
}
|
|
6656
|
+
// needs testing
|
|
6657
|
+
async balance() {
|
|
6658
|
+
// Not available on bearby. we have to manually call the api
|
|
6659
|
+
const body = {
|
|
6660
|
+
jsonrpc: '2.0',
|
|
6661
|
+
method: 'get_addresses',
|
|
6662
|
+
params: [[this._address]],
|
|
6663
|
+
id: 0,
|
|
6664
|
+
};
|
|
6665
|
+
const addressInfos = await (0, RequestHandler_1.postRequest)(exports.PUBLIC_NODE_RPC, body);
|
|
6666
|
+
if (addressInfos.isError || addressInfos.error) {
|
|
6667
|
+
throw addressInfos.error.message;
|
|
6668
|
+
}
|
|
6669
|
+
return {
|
|
6670
|
+
finalBalance: addressInfos.result.result[0].final_balance,
|
|
6671
|
+
candidateBalance: addressInfos.result.result[0].candidate_balance,
|
|
6672
|
+
};
|
|
6673
|
+
}
|
|
6674
|
+
// need testing
|
|
6675
|
+
async sign(data) {
|
|
6676
|
+
const encoder = new TextEncoder();
|
|
6677
|
+
if (typeof data === 'string') {
|
|
6678
|
+
const signature = await bearby_js_1.web3.wallet.signMessage(data);
|
|
6679
|
+
return {
|
|
6680
|
+
publicKey: signature.publicKey,
|
|
6681
|
+
signature: encoder.encode(signature.signature),
|
|
6682
|
+
};
|
|
6683
|
+
}
|
|
6684
|
+
const strData = new TextDecoder().decode(data);
|
|
6685
|
+
return {
|
|
6686
|
+
publicKey: (await bearby_js_1.web3.wallet.signMessage(strData)).publicKey,
|
|
6687
|
+
signature: encoder.encode((await bearby_js_1.web3.wallet.signMessage(strData)).signature),
|
|
6688
|
+
};
|
|
6689
|
+
}
|
|
6690
|
+
// need testing
|
|
6691
|
+
async buyRolls(amount, fee) {
|
|
6692
|
+
const signedTx = await bearby_js_1.web3.wallet.signTransaction({
|
|
6693
|
+
type: OperationsType.RollBuy,
|
|
6694
|
+
amount: amount.toString(),
|
|
6695
|
+
fee: fee.toString(),
|
|
6696
|
+
payload: '', // TODO: check how do we have to set it
|
|
6697
|
+
});
|
|
6698
|
+
// broadcast the transaction
|
|
6699
|
+
const provider = ''; // TODO: GET THE PROVIDER FROM BEARBY (if possible ..)
|
|
6700
|
+
throw new Error('Method not implemented.');
|
|
6701
|
+
}
|
|
6702
|
+
// need testing
|
|
6703
|
+
async sellRolls(amount, fee) {
|
|
6704
|
+
const signedTx = await bearby_js_1.web3.wallet.signTransaction({
|
|
6705
|
+
type: OperationsType.RollSell,
|
|
6706
|
+
amount: amount.toString(),
|
|
6707
|
+
fee: fee.toString(),
|
|
6708
|
+
payload: '', // TODO: check how do we have to set it
|
|
6709
|
+
});
|
|
6710
|
+
// broadcast the transaction
|
|
6711
|
+
const provider = ''; // TODO: GET THE PROVIDER FROM BEARBY
|
|
6712
|
+
throw new Error('Method not implemented.');
|
|
6713
|
+
}
|
|
6714
|
+
async sendTransaction(amount, recipientAddress, fee) {
|
|
6715
|
+
const signedTx = await bearby_js_1.web3.wallet.signTransaction({
|
|
6716
|
+
type: OperationsType.Payment,
|
|
6717
|
+
amount: amount.toString(),
|
|
6718
|
+
recipient: recipientAddress,
|
|
6719
|
+
fee: fee.toString(),
|
|
6720
|
+
payload: '', // TODO: check how do we have to set it
|
|
6721
|
+
});
|
|
6722
|
+
console.log(signedTx);
|
|
6723
|
+
return {
|
|
6724
|
+
operationId: '00',
|
|
6725
|
+
};
|
|
6726
|
+
}
|
|
6727
|
+
async callSC(contractAddress, functionName, parameter, amount, fee, maxGas, nonPersistentExecution = false) {
|
|
6728
|
+
if (nonPersistentExecution) {
|
|
6729
|
+
return this.nonPersistentCallSC(contractAddress, functionName, parameter, amount, fee, maxGas);
|
|
6730
|
+
}
|
|
6731
|
+
if (parameter instanceof Uint8Array) {
|
|
6732
|
+
throw new Error('Protobuf serialization is not supported by bearby wallet. To use it switch to MassaStation');
|
|
6733
|
+
}
|
|
6734
|
+
// setup the params from Args
|
|
6735
|
+
let params = [];
|
|
6736
|
+
try {
|
|
6737
|
+
params = parameter.getArgsList().map((arg) => {
|
|
6738
|
+
return {
|
|
6739
|
+
type: arg.type,
|
|
6740
|
+
value: arg.value,
|
|
6741
|
+
};
|
|
6742
|
+
});
|
|
6743
|
+
}
|
|
6744
|
+
catch (ex) {
|
|
6745
|
+
throw new Error(
|
|
6746
|
+
/* eslint-disable-next-line max-len */
|
|
6747
|
+
'Bearby wallet does not support Uint8Array, serializable and serializableObjectArray. To use them switch to MassaStation');
|
|
6748
|
+
}
|
|
6749
|
+
return await bearby_js_1.web3.contract.call({
|
|
6750
|
+
maxGas: Number(maxGas),
|
|
6751
|
+
coins: Number(amount),
|
|
6752
|
+
fee: Number(fee),
|
|
6753
|
+
targetAddress: contractAddress,
|
|
6754
|
+
functionName: functionName,
|
|
6755
|
+
parameters: params,
|
|
6756
|
+
});
|
|
6757
|
+
// // convert parameter to an array of numbers
|
|
6758
|
+
// let argumentArray: Array<number> = [];
|
|
6759
|
+
// if (parameter instanceof Uint8Array) {
|
|
6760
|
+
// argumentArray = Array.from(parameter);
|
|
6761
|
+
// } else {
|
|
6762
|
+
// argumentArray = Array.from(parameter.serialize());
|
|
6763
|
+
// }
|
|
6764
|
+
// const callData = {
|
|
6765
|
+
// fee: fee,
|
|
6766
|
+
// maxGas: maxGas,
|
|
6767
|
+
// coins: amount,
|
|
6768
|
+
// targetAddress: contractAddress,
|
|
6769
|
+
// functionName: functionName,
|
|
6770
|
+
// parameter: argumentArray,
|
|
6771
|
+
// } as ICallData;
|
|
6772
|
+
// // get next period info to set the expiry period
|
|
6773
|
+
// const nodeStatusInfo: NodeStatus = await this.getNodeStatus();
|
|
6774
|
+
// // 5 is the default value used in massa-web3 for expiry period
|
|
6775
|
+
// const expiryPeriod: number = nodeStatusInfo.next_slot.period + 5;
|
|
6776
|
+
// // bytes compaction
|
|
6777
|
+
// const bytesCompact: Buffer = compactBytesForOperation(
|
|
6778
|
+
// callData,
|
|
6779
|
+
// OperationTypeId.CallSC,
|
|
6780
|
+
// expiryPeriod,
|
|
6781
|
+
// );
|
|
6782
|
+
// // We need the public key but bearby doesn't allow us to get it directly.
|
|
6783
|
+
// // We have to sign a message and get the public key from the signature
|
|
6784
|
+
// const pubKey = (await this.sign('nothing')).publicKey;
|
|
6785
|
+
// // sign payload
|
|
6786
|
+
// const bytesPublicKey: Uint8Array = getBytesPublicKey(pubKey);
|
|
6787
|
+
// // get the signature and encode it to base58
|
|
6788
|
+
// const signatureUInt8Array = (
|
|
6789
|
+
// await this.sign(Buffer.concat([bytesPublicKey, bytesCompact]))
|
|
6790
|
+
// ).signature;
|
|
6791
|
+
// const signature = base58Encode(signatureUInt8Array);
|
|
6792
|
+
// // request data
|
|
6793
|
+
// const data = {
|
|
6794
|
+
// serialized_content: Array.prototype.slice.call(bytesCompact),
|
|
6795
|
+
// creator_public_key: pubKey,
|
|
6796
|
+
// signature: signature,
|
|
6797
|
+
// };
|
|
6798
|
+
// // returns operation ids
|
|
6799
|
+
// let opIds: Array<string> = [];
|
|
6800
|
+
// const jsonRpcRequestMethod = JSON_RPC_REQUEST_METHOD.SEND_OPERATIONS;
|
|
6801
|
+
// opIds = await this.sendJsonRPCRequest(jsonRpcRequestMethod, [[data]]);
|
|
6802
|
+
// if (opIds.length <= 0) {
|
|
6803
|
+
// throw new Error(
|
|
6804
|
+
// `Call smart contract operation bad response. No results array in json rpc response. Inspect smart contract`,
|
|
6805
|
+
// );
|
|
6806
|
+
// }
|
|
6807
|
+
// return opIds[0];
|
|
6808
|
+
}
|
|
6809
|
+
/**
|
|
6810
|
+
* Retrieves the node's status.
|
|
6811
|
+
*
|
|
6812
|
+
* @remarks
|
|
6813
|
+
* The returned information includes:
|
|
6814
|
+
* - Whether the node is reachable
|
|
6815
|
+
* - The number of connected peers
|
|
6816
|
+
* - The node's version
|
|
6817
|
+
* - The node's configuration parameters
|
|
6818
|
+
*
|
|
6819
|
+
* @returns A promise that resolves to the node's status information.
|
|
6820
|
+
*/
|
|
6821
|
+
async getNodeStatus() {
|
|
6822
|
+
const jsonRpcRequestMethod = jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STATUS;
|
|
6823
|
+
return await this.sendJsonRPCRequest(jsonRpcRequestMethod, []);
|
|
6824
|
+
}
|
|
6825
|
+
/**
|
|
6826
|
+
* Sends a post JSON rpc request to the node.
|
|
6827
|
+
*
|
|
6828
|
+
* @param resource - The rpc method to call.
|
|
6829
|
+
* @param params - The parameters to pass to the rpc method.
|
|
6830
|
+
*
|
|
6831
|
+
* @throws An error if the rpc method returns an error.
|
|
6832
|
+
*
|
|
6833
|
+
* @returns A promise that resolves as the result of the rpc method.
|
|
6834
|
+
*/
|
|
6835
|
+
async sendJsonRPCRequest(resource, params) {
|
|
6836
|
+
let resp = null;
|
|
6837
|
+
resp = await this.promisifyJsonRpcCall(resource, params);
|
|
6838
|
+
// in case of rpc error, rethrow the error.
|
|
6839
|
+
if (resp.isError || resp.error) {
|
|
6840
|
+
throw resp.error;
|
|
6841
|
+
}
|
|
6842
|
+
return resp.result;
|
|
6843
|
+
}
|
|
6844
|
+
/**
|
|
6845
|
+
* Converts a json rpc call to a promise that resolves as a JsonRpcResponseData
|
|
6846
|
+
*
|
|
6847
|
+
* @privateRemarks
|
|
6848
|
+
* If there is an error while sending the request, the function catches the error, the isError
|
|
6849
|
+
* property is set to true, the result property set to null, and the error property set to a
|
|
6850
|
+
* new Error object with a message indicating that there was an error.
|
|
6851
|
+
*
|
|
6852
|
+
* @param resource - The rpc method to call.
|
|
6853
|
+
* @param params - The parameters to pass to the rpc method.
|
|
6854
|
+
*
|
|
6855
|
+
* @returns A promise that resolves as a JsonRpcResponseData.
|
|
6856
|
+
*/
|
|
6857
|
+
async promisifyJsonRpcCall(resource, params) {
|
|
6858
|
+
let resp = null;
|
|
6859
|
+
const body = {
|
|
6860
|
+
jsonrpc: '2.0',
|
|
6861
|
+
method: resource,
|
|
6862
|
+
params: params,
|
|
6863
|
+
id: 0,
|
|
6864
|
+
};
|
|
6865
|
+
try {
|
|
6866
|
+
resp = await axios_1.default.post(this._nodeUrl, body, exports.requestHeaders);
|
|
6867
|
+
}
|
|
6868
|
+
catch (ex) {
|
|
6869
|
+
return {
|
|
6870
|
+
isError: true,
|
|
6871
|
+
result: null,
|
|
6872
|
+
error: new Error('JSON.parse error: ' + String(ex)),
|
|
6873
|
+
};
|
|
6874
|
+
}
|
|
6875
|
+
const responseData = resp.data;
|
|
6876
|
+
if (responseData.error) {
|
|
6877
|
+
return {
|
|
6878
|
+
isError: true,
|
|
6879
|
+
result: null,
|
|
6880
|
+
error: new Error(responseData.error.message),
|
|
6881
|
+
};
|
|
6882
|
+
}
|
|
6883
|
+
return {
|
|
6884
|
+
isError: false,
|
|
6885
|
+
result: responseData.result,
|
|
6886
|
+
error: null,
|
|
6887
|
+
};
|
|
6888
|
+
}
|
|
6889
|
+
/**
|
|
6890
|
+
* Find provider for a concrete rpc method
|
|
6891
|
+
*
|
|
6892
|
+
* @remarks
|
|
6893
|
+
* This method chooses the provider to use for a given rpc method.
|
|
6894
|
+
* - If the rpc method is about getting or sending data to the blockchain,
|
|
6895
|
+
* it will choose a public provider.
|
|
6896
|
+
* - If the rpc method is meant to be used by the node itself, it will choose a private provider.
|
|
6897
|
+
* - An error is thrown if no provider is found for the rpc method.
|
|
6898
|
+
*
|
|
6899
|
+
* @param requestMethod - The rpc method to find the provider for.
|
|
6900
|
+
*
|
|
6901
|
+
* @returns The provider for the rpc method.
|
|
6902
|
+
*/
|
|
6903
|
+
getProviderForRpcMethod(requestMethod) {
|
|
6904
|
+
switch (requestMethod) {
|
|
6905
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_ADDRESSES:
|
|
6906
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STATUS:
|
|
6907
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.SEND_OPERATIONS:
|
|
6908
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_OPERATIONS:
|
|
6909
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_BLOCKS:
|
|
6910
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_ENDORSEMENTS:
|
|
6911
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_CLIQUES:
|
|
6912
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STAKERS:
|
|
6913
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_FILTERED_SC_OUTPUT_EVENT:
|
|
6914
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.EXECUTE_READ_ONLY_BYTECODE:
|
|
6915
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.EXECUTE_READ_ONLY_CALL:
|
|
6916
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_DATASTORE_ENTRIES:
|
|
6917
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_BLOCKCLIQUE_BLOCK_BY_SLOT:
|
|
6918
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_GRAPH_INTERVAL: {
|
|
6919
|
+
return new BearbyProvider_1.BearbyProvider('Bearby');
|
|
6920
|
+
}
|
|
6921
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.STOP_NODE:
|
|
6922
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_BAN_BY_ID:
|
|
6923
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_BAN_BY_IP:
|
|
6924
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_UNBAN_BY_ID:
|
|
6925
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_UNBAN_BY_IP:
|
|
6926
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.GET_STAKING_ADDRESSES:
|
|
6927
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.REMOVE_STAKING_ADDRESSES:
|
|
6928
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.ADD_STAKING_PRIVATE_KEYS:
|
|
6929
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_SIGN_MESSAGE:
|
|
6930
|
+
case jsonRpcMethods_1.JSON_RPC_REQUEST_METHOD.NODE_REMOVE_FROM_WHITELIST: {
|
|
6931
|
+
return new BearbyProvider_1.BearbyProvider('Bearby');
|
|
6932
|
+
}
|
|
6933
|
+
default:
|
|
6934
|
+
throw new Error(`Unknown Json rpc method: ${requestMethod}`);
|
|
6935
|
+
}
|
|
6936
|
+
}
|
|
6937
|
+
async nonPersistentCallSC(contractAddress, functionName, parameter, amount, fee, maxGas) {
|
|
6938
|
+
// not clean but bearby doesn't allow us to get its node urls
|
|
6939
|
+
const node = exports.PUBLIC_NODE_RPC;
|
|
6940
|
+
// Gas amount check
|
|
6941
|
+
if (maxGas > MAX_READ_BLOCK_GAS) {
|
|
6942
|
+
throw new Error(`
|
|
6943
|
+
The gas submitted ${maxGas.toString()} exceeds the max. allowed block gas of
|
|
6944
|
+
${MAX_READ_BLOCK_GAS.toString()}
|
|
6945
|
+
`);
|
|
6946
|
+
}
|
|
6947
|
+
// convert parameter to an array of numbers
|
|
6948
|
+
let argumentArray = [];
|
|
6949
|
+
if (parameter instanceof Uint8Array) {
|
|
6950
|
+
argumentArray = Array.from(parameter);
|
|
6951
|
+
}
|
|
6952
|
+
else {
|
|
6953
|
+
argumentArray = Array.from(parameter.serialize());
|
|
6954
|
+
}
|
|
6955
|
+
// setup the request body
|
|
6956
|
+
const data = {
|
|
6957
|
+
max_gas: Number(maxGas),
|
|
6958
|
+
target_address: contractAddress,
|
|
6959
|
+
target_function: functionName,
|
|
6960
|
+
parameter: argumentArray,
|
|
6961
|
+
caller_address: this._address,
|
|
6962
|
+
coins: Number(amount),
|
|
6963
|
+
fee: Number(fee),
|
|
6964
|
+
};
|
|
6965
|
+
const body = [
|
|
6966
|
+
{
|
|
6967
|
+
jsonrpc: '2.0',
|
|
6968
|
+
method: 'execute_read_only_call',
|
|
6969
|
+
params: [[data]],
|
|
6970
|
+
id: 0,
|
|
6971
|
+
},
|
|
6972
|
+
];
|
|
6973
|
+
// returns operation ids
|
|
6974
|
+
let jsonRpcCallResult = [];
|
|
6975
|
+
try {
|
|
6976
|
+
let resp = await (0, RequestHandler_1.postRequest)(node, body);
|
|
6977
|
+
if (resp.isError || resp.error) {
|
|
6978
|
+
throw resp.error.message;
|
|
6979
|
+
}
|
|
6980
|
+
jsonRpcCallResult = resp.result;
|
|
6981
|
+
}
|
|
6982
|
+
catch (ex) {
|
|
6983
|
+
throw new Error(`MassaStation account: error while interacting with smart contract: ${ex}`);
|
|
6984
|
+
}
|
|
6985
|
+
if (jsonRpcCallResult.length <= 0) {
|
|
6986
|
+
throw new Error(`Read operation bad response. No results array in json rpc response. Inspect smart contract`);
|
|
6987
|
+
}
|
|
6988
|
+
if (jsonRpcCallResult[0].result.Error) {
|
|
6989
|
+
throw new Error(jsonRpcCallResult[0].result.Error);
|
|
6990
|
+
}
|
|
6991
|
+
return {
|
|
6992
|
+
returnValue: new Uint8Array(jsonRpcCallResult[0].result[0].result.Ok),
|
|
6993
|
+
info: jsonRpcCallResult[0],
|
|
6994
|
+
};
|
|
6995
|
+
}
|
|
6996
|
+
}
|
|
6997
|
+
exports.BearbyAccount = BearbyAccount;
|
|
6998
|
+
const PUBLIC_KEY_PREFIX = 'P';
|
|
6999
|
+
/**
|
|
7000
|
+
* Retrieves the byte representation of a given public key.
|
|
7001
|
+
*
|
|
7002
|
+
* @param publicKey - The public key to obtain the bytes from.
|
|
7003
|
+
*
|
|
7004
|
+
* @throws If the public key has an incorrect {@link PUBLIC_KEY_PREFIX}.
|
|
7005
|
+
*
|
|
7006
|
+
* @returns A Uint8Array containing the bytes of the public key.
|
|
7007
|
+
*/
|
|
7008
|
+
function getBytesPublicKey(publicKey) {
|
|
7009
|
+
if (!(publicKey[0] == PUBLIC_KEY_PREFIX)) {
|
|
7010
|
+
throw new Error(`Invalid public key prefix: ${publicKey[0]} should be ${PUBLIC_KEY_PREFIX}`);
|
|
7011
|
+
}
|
|
7012
|
+
const publicKeyBase58Decoded = (0, Xbqcrypto_1.base58Decode)(publicKey.slice(1));
|
|
7013
|
+
return publicKeyBase58Decoded;
|
|
7014
|
+
}
|
|
7015
|
+
exports.getBytesPublicKey = getBytesPublicKey;
|
|
7016
|
+
|
|
7017
|
+
|
|
7018
|
+
/***/ }),
|
|
7019
|
+
|
|
7020
|
+
/***/ "./src/bearbyWallet/BearbyConnect.ts":
|
|
7021
|
+
/*!*******************************************!*\
|
|
7022
|
+
!*** ./src/bearbyWallet/BearbyConnect.ts ***!
|
|
7023
|
+
\*******************************************/
|
|
7024
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7025
|
+
|
|
7026
|
+
"use strict";
|
|
7027
|
+
|
|
7028
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7029
|
+
exports.disconnectBearby = exports.connectBearby = exports.detectBearby = void 0;
|
|
7030
|
+
const bearby_js_1 = __webpack_require__(/*! @hicaru/bearby.js */ "./node_modules/@hicaru/bearby.js/dist/index.js");
|
|
7031
|
+
async function detectBearby() {
|
|
7032
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7033
|
+
if (globalThis.window && globalThis.window['bearby']) {
|
|
7034
|
+
return true;
|
|
7035
|
+
}
|
|
7036
|
+
return false;
|
|
7037
|
+
}
|
|
7038
|
+
exports.detectBearby = detectBearby;
|
|
7039
|
+
async function connectBearby() {
|
|
7040
|
+
try {
|
|
7041
|
+
await bearby_js_1.web3.wallet.connect();
|
|
7042
|
+
}
|
|
7043
|
+
catch (ex) {
|
|
7044
|
+
console.log(ex);
|
|
7045
|
+
}
|
|
7046
|
+
}
|
|
7047
|
+
exports.connectBearby = connectBearby;
|
|
7048
|
+
async function disconnectBearby() {
|
|
7049
|
+
await bearby_js_1.web3.wallet.diconnect(); // diconnect is a typo in the library
|
|
7050
|
+
console.log('Bearby disconnected');
|
|
7051
|
+
}
|
|
7052
|
+
exports.disconnectBearby = disconnectBearby;
|
|
7053
|
+
|
|
7054
|
+
|
|
7055
|
+
/***/ }),
|
|
7056
|
+
|
|
7057
|
+
/***/ "./src/bearbyWallet/BearbyProvider.ts":
|
|
7058
|
+
/*!********************************************!*\
|
|
7059
|
+
!*** ./src/bearbyWallet/BearbyProvider.ts ***!
|
|
7060
|
+
\********************************************/
|
|
7061
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7062
|
+
|
|
7063
|
+
"use strict";
|
|
7064
|
+
|
|
7065
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7066
|
+
exports.BearbyProvider = void 0;
|
|
7067
|
+
const bearby_js_1 = __webpack_require__(/*! @hicaru/bearby.js */ "./node_modules/@hicaru/bearby.js/dist/index.js");
|
|
7068
|
+
const BearbyAccount_1 = __webpack_require__(/*! ./BearbyAccount */ "./src/bearbyWallet/BearbyAccount.ts");
|
|
7069
|
+
class BearbyProvider {
|
|
7070
|
+
/**
|
|
7071
|
+
* Provider constructor
|
|
7072
|
+
*
|
|
7073
|
+
* @param providerName - The name of the provider.
|
|
7074
|
+
* @returns An instance of the Provider class.
|
|
7075
|
+
*/
|
|
7076
|
+
constructor(providerName) {
|
|
7077
|
+
this.providerName = providerName;
|
|
7078
|
+
}
|
|
7079
|
+
name() {
|
|
7080
|
+
return this.providerName;
|
|
7081
|
+
}
|
|
7082
|
+
async accounts() {
|
|
7083
|
+
// check if bearby is unlocked
|
|
7084
|
+
if (!bearby_js_1.web3.wallet.enabled) {
|
|
7085
|
+
await bearby_js_1.web3.wallet.connect();
|
|
7086
|
+
}
|
|
7087
|
+
const account = {
|
|
7088
|
+
address: await bearby_js_1.web3.wallet.account.base58,
|
|
7089
|
+
name: 'Bearby',
|
|
7090
|
+
};
|
|
7091
|
+
return [new BearbyAccount_1.BearbyAccount(account, this.providerName)];
|
|
7092
|
+
}
|
|
7093
|
+
async importAccount(publicKey, privateKey) {
|
|
7094
|
+
throw new Error('Method not implemented.');
|
|
7095
|
+
}
|
|
7096
|
+
async deleteAccount(address) {
|
|
7097
|
+
throw new Error('Method not implemented.');
|
|
7098
|
+
}
|
|
7099
|
+
async getNodesUrls() {
|
|
7100
|
+
return ['https://buildnet.massa.net/api/v2'];
|
|
7101
|
+
}
|
|
7102
|
+
async generateNewAccount(name) {
|
|
7103
|
+
throw new Error('Method not implemented.');
|
|
7104
|
+
}
|
|
7105
|
+
}
|
|
7106
|
+
exports.BearbyProvider = BearbyProvider;
|
|
7107
|
+
|
|
7108
|
+
|
|
7109
|
+
/***/ }),
|
|
7110
|
+
|
|
7111
|
+
/***/ "./src/bearbyWallet/Xbqcrypto.ts":
|
|
7112
|
+
/*!***************************************!*\
|
|
7113
|
+
!*** ./src/bearbyWallet/Xbqcrypto.ts ***!
|
|
7114
|
+
\***************************************/
|
|
7115
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7116
|
+
|
|
7117
|
+
"use strict";
|
|
7118
|
+
|
|
7119
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7120
|
+
exports.varintDecode = exports.varintEncode = exports.base58Decode = exports.base58Encode = exports.hashBlake3 = void 0;
|
|
7121
|
+
const varint = __webpack_require__(/*! varint */ "./node_modules/varint/index.js");
|
|
7122
|
+
const blake3_1 = __webpack_require__(/*! @noble/hashes/blake3 */ "./node_modules/@noble/hashes/blake3.js");
|
|
7123
|
+
/**
|
|
7124
|
+
* A collection of utility functions for working with various data encoding and hashing formats.
|
|
7125
|
+
*
|
|
7126
|
+
* This module provides several functions for encoding and decoding data in various formats, including
|
|
7127
|
+
* `base58`, `varint`, and `blake3 hashes`.
|
|
7128
|
+
*
|
|
7129
|
+
*/
|
|
7130
|
+
const unsignedBigIntUtils = __webpack_require__(/*! ./unsignedBigIntUtils */ "./src/bearbyWallet/unsignedBigIntUtils.ts");
|
|
7131
|
+
const bs58check_1 = __webpack_require__(/*! bs58check */ "./node_modules/bs58check/index.js");
|
|
7132
|
+
/**
|
|
7133
|
+
* Hashes data with blake3
|
|
7134
|
+
*
|
|
7135
|
+
* @param data - The data to hash
|
|
7136
|
+
*
|
|
7137
|
+
* @returns The hash of the data with blake3
|
|
7138
|
+
*/
|
|
7139
|
+
function hashBlake3(data) {
|
|
7140
|
+
return (0, blake3_1.blake3)(data);
|
|
7141
|
+
}
|
|
7142
|
+
exports.hashBlake3 = hashBlake3;
|
|
7143
|
+
/**
|
|
7144
|
+
* Encodes a buffer or an Uint8Array to base58
|
|
7145
|
+
*
|
|
7146
|
+
* @param data - The data to encode
|
|
7147
|
+
*
|
|
7148
|
+
* @returns The base58 encoded data as a string
|
|
7149
|
+
*/
|
|
7150
|
+
function base58Encode(data) {
|
|
7151
|
+
return (0, bs58check_1.encode)(data);
|
|
7152
|
+
}
|
|
7153
|
+
exports.base58Encode = base58Encode;
|
|
7154
|
+
/**
|
|
7155
|
+
* Decode a base58 encoded string to a buffer
|
|
7156
|
+
*
|
|
7157
|
+
* @param data - The base58 encoded string
|
|
7158
|
+
*
|
|
7159
|
+
* @returns The decoded buffer
|
|
7160
|
+
*/
|
|
7161
|
+
function base58Decode(data) {
|
|
7162
|
+
const decoded = (0, bs58check_1.decode)(data);
|
|
7163
|
+
return Buffer.from(decoded);
|
|
7164
|
+
}
|
|
7165
|
+
exports.base58Decode = base58Decode;
|
|
7166
|
+
/**
|
|
7167
|
+
* Encodes a number or bigint to a varint encoded Uint8Array.
|
|
7168
|
+
*
|
|
7169
|
+
* @param data - The data to encode
|
|
7170
|
+
*
|
|
7171
|
+
* @returns The varint encoded data as a Uint8Array
|
|
7172
|
+
*/
|
|
7173
|
+
function varintEncode(data) {
|
|
7174
|
+
if (typeof data === 'bigint') {
|
|
7175
|
+
return unsignedBigIntUtils.encode(data);
|
|
7176
|
+
}
|
|
7177
|
+
return varint.encode(data);
|
|
7178
|
+
}
|
|
7179
|
+
exports.varintEncode = varintEncode;
|
|
7180
|
+
/**
|
|
7181
|
+
* Decodes a varint encoded Uint8Array to a number
|
|
7182
|
+
*
|
|
7183
|
+
* @param data - The varint encoded Uint8Array
|
|
7184
|
+
*
|
|
7185
|
+
* @returns The decoded number and the number of bytes read
|
|
7186
|
+
*/
|
|
7187
|
+
function varintDecode(data) {
|
|
7188
|
+
const value = varint.decode(data);
|
|
7189
|
+
const bytes = varint.decode.bytes;
|
|
7190
|
+
return { value, bytes };
|
|
7191
|
+
}
|
|
7192
|
+
exports.varintDecode = varintDecode;
|
|
7193
|
+
|
|
7194
|
+
|
|
7195
|
+
/***/ }),
|
|
7196
|
+
|
|
7197
|
+
/***/ "./src/bearbyWallet/jsonRpcMethods.ts":
|
|
7198
|
+
/*!********************************************!*\
|
|
7199
|
+
!*** ./src/bearbyWallet/jsonRpcMethods.ts ***!
|
|
7200
|
+
\********************************************/
|
|
7201
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
7202
|
+
|
|
7203
|
+
"use strict";
|
|
7204
|
+
|
|
7205
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7206
|
+
exports.JSON_RPC_REQUEST_METHOD = void 0;
|
|
7207
|
+
/**
|
|
7208
|
+
* Lists all JSON RPC Request Methods.
|
|
7209
|
+
*/
|
|
7210
|
+
var JSON_RPC_REQUEST_METHOD;
|
|
7211
|
+
(function (JSON_RPC_REQUEST_METHOD) {
|
|
7212
|
+
// public Api
|
|
7213
|
+
JSON_RPC_REQUEST_METHOD["GET_STATUS"] = "get_status";
|
|
7214
|
+
JSON_RPC_REQUEST_METHOD["GET_ADDRESSES"] = "get_addresses";
|
|
7215
|
+
JSON_RPC_REQUEST_METHOD["SEND_OPERATIONS"] = "send_operations";
|
|
7216
|
+
JSON_RPC_REQUEST_METHOD["GET_BLOCKS"] = "get_blocks";
|
|
7217
|
+
JSON_RPC_REQUEST_METHOD["GET_ENDORSEMENTS"] = "get_endorsements";
|
|
7218
|
+
JSON_RPC_REQUEST_METHOD["GET_OPERATIONS"] = "get_operations";
|
|
7219
|
+
JSON_RPC_REQUEST_METHOD["GET_CLIQUES"] = "get_cliques";
|
|
7220
|
+
JSON_RPC_REQUEST_METHOD["GET_STAKERS"] = "get_stakers";
|
|
7221
|
+
JSON_RPC_REQUEST_METHOD["GET_FILTERED_SC_OUTPUT_EVENT"] = "get_filtered_sc_output_event";
|
|
7222
|
+
JSON_RPC_REQUEST_METHOD["EXECUTE_READ_ONLY_BYTECODE"] = "execute_read_only_bytecode";
|
|
7223
|
+
JSON_RPC_REQUEST_METHOD["EXECUTE_READ_ONLY_CALL"] = "execute_read_only_call";
|
|
7224
|
+
JSON_RPC_REQUEST_METHOD["GET_DATASTORE_ENTRIES"] = "get_datastore_entries";
|
|
7225
|
+
JSON_RPC_REQUEST_METHOD["GET_BLOCKCLIQUE_BLOCK_BY_SLOT"] = "get_blockclique_block_by_slot";
|
|
7226
|
+
JSON_RPC_REQUEST_METHOD["GET_GRAPH_INTERVAL"] = "get_graph_interval";
|
|
7227
|
+
// private Api
|
|
7228
|
+
JSON_RPC_REQUEST_METHOD["STOP_NODE"] = "stop_node";
|
|
7229
|
+
JSON_RPC_REQUEST_METHOD["NODE_BAN_BY_IP"] = "node_ban_by_ip";
|
|
7230
|
+
JSON_RPC_REQUEST_METHOD["NODE_BAN_BY_ID"] = "node_ban_by_id";
|
|
7231
|
+
JSON_RPC_REQUEST_METHOD["NODE_UNBAN_BY_IP"] = "node_unban_by_ip";
|
|
7232
|
+
JSON_RPC_REQUEST_METHOD["NODE_UNBAN_BY_ID"] = "node_unban_by_id";
|
|
7233
|
+
JSON_RPC_REQUEST_METHOD["GET_STAKING_ADDRESSES"] = "get_staking_addresses";
|
|
7234
|
+
JSON_RPC_REQUEST_METHOD["REMOVE_STAKING_ADDRESSES"] = "remove_staking_addresses";
|
|
7235
|
+
JSON_RPC_REQUEST_METHOD["ADD_STAKING_PRIVATE_KEYS"] = "add_staking_private_keys";
|
|
7236
|
+
JSON_RPC_REQUEST_METHOD["NODE_SIGN_MESSAGE"] = "node_sign_message";
|
|
7237
|
+
JSON_RPC_REQUEST_METHOD["NODE_REMOVE_FROM_WHITELIST"] = "node_remove_from_whitelist";
|
|
7238
|
+
JSON_RPC_REQUEST_METHOD["NODE_ADD_TO_PEERS_WHITELIST"] = "node_add_to_peers_whitelist";
|
|
7239
|
+
})(JSON_RPC_REQUEST_METHOD = exports.JSON_RPC_REQUEST_METHOD || (exports.JSON_RPC_REQUEST_METHOD = {}));
|
|
7240
|
+
|
|
7241
|
+
|
|
7242
|
+
/***/ }),
|
|
7243
|
+
|
|
7244
|
+
/***/ "./src/bearbyWallet/unsignedBigIntUtils.ts":
|
|
7245
|
+
/*!*************************************************!*\
|
|
7246
|
+
!*** ./src/bearbyWallet/unsignedBigIntUtils.ts ***!
|
|
7247
|
+
\*************************************************/
|
|
7248
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
7249
|
+
|
|
7250
|
+
"use strict";
|
|
7251
|
+
|
|
7252
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7253
|
+
exports.decode = exports.encode = exports.encodingLength = void 0;
|
|
7254
|
+
const LIMIT = BigInt(0x7f);
|
|
7255
|
+
const zeroBI = BigInt(0);
|
|
7256
|
+
const sevenBI = BigInt(7);
|
|
7257
|
+
/**
|
|
7258
|
+
*
|
|
7259
|
+
* This module provides functions to encode and decode unsigned integers,
|
|
7260
|
+
* using Varint which is a more compact binary representation of them.
|
|
7261
|
+
*/
|
|
7262
|
+
/**
|
|
7263
|
+
* Returns the number of bytes required to store the number in a varint.
|
|
7264
|
+
*
|
|
7265
|
+
* @param value - The number to encode.
|
|
7266
|
+
* @returns The number of bytes required to store the number.
|
|
7267
|
+
*/
|
|
7268
|
+
function encodingLength(value) {
|
|
7269
|
+
let i = 0;
|
|
7270
|
+
for (; value >= BigInt(0x80); i++) {
|
|
7271
|
+
value >>= sevenBI;
|
|
7272
|
+
}
|
|
7273
|
+
return i + 1;
|
|
7274
|
+
}
|
|
7275
|
+
exports.encodingLength = encodingLength;
|
|
7276
|
+
/**
|
|
7277
|
+
* Encodes a big number as a varint.
|
|
7278
|
+
*
|
|
7279
|
+
* @param i - The big number to encode.
|
|
7280
|
+
* @param buffer - The buffer to write the varint to (optional).
|
|
7281
|
+
* @param byteOffset - The offset in the buffer to start writing at (optional) (default: 0).
|
|
7282
|
+
* @returns The buffer that was written to.
|
|
7283
|
+
*/
|
|
7284
|
+
function encode(i, buffer, byteOffset) {
|
|
7285
|
+
if (i < zeroBI) {
|
|
7286
|
+
throw new RangeError('value must be unsigned');
|
|
7287
|
+
}
|
|
7288
|
+
const byteLength = encodingLength(i);
|
|
7289
|
+
buffer = buffer || new ArrayBuffer(byteLength);
|
|
7290
|
+
byteOffset = byteOffset || 0;
|
|
7291
|
+
if (buffer.byteLength < byteOffset + byteLength) {
|
|
7292
|
+
throw new RangeError('the buffer is too small to encode the number at the offset');
|
|
7293
|
+
}
|
|
7294
|
+
const array = new Uint8Array(buffer, byteOffset);
|
|
7295
|
+
let offset = 0;
|
|
7296
|
+
while (LIMIT < i) {
|
|
7297
|
+
array[offset++] = Number(i & LIMIT) | 0x80;
|
|
7298
|
+
i >>= sevenBI;
|
|
7299
|
+
}
|
|
7300
|
+
array[offset] = Number(i);
|
|
7301
|
+
return array;
|
|
7302
|
+
}
|
|
7303
|
+
exports.encode = encode;
|
|
7304
|
+
/**
|
|
7305
|
+
* Decodes a varint as a big number.
|
|
7306
|
+
*
|
|
7307
|
+
* @param data - The data to decode.
|
|
7308
|
+
* @param offset - The offset in the data to start reading at (optional) (default: 0).
|
|
7309
|
+
* @returns The decoded big number.
|
|
7310
|
+
*/
|
|
7311
|
+
function decode(data, offset = 0) {
|
|
7312
|
+
let i = zeroBI;
|
|
7313
|
+
let n = 0;
|
|
7314
|
+
let b;
|
|
7315
|
+
do {
|
|
7316
|
+
b = data[offset + n];
|
|
7317
|
+
if (b === undefined) {
|
|
7318
|
+
throw new RangeError('offset out of range');
|
|
7319
|
+
}
|
|
7320
|
+
i += BigInt(b & 0x7f) << BigInt(n * 7);
|
|
7321
|
+
n++;
|
|
7322
|
+
} while (0x80 <= b);
|
|
7323
|
+
return i;
|
|
7324
|
+
}
|
|
7325
|
+
exports.decode = decode;
|
|
7326
|
+
|
|
7327
|
+
|
|
7328
|
+
/***/ }),
|
|
7329
|
+
|
|
7330
|
+
/***/ "./src/connector/Connector.ts":
|
|
7331
|
+
/*!************************************!*\
|
|
7332
|
+
!*** ./src/connector/Connector.ts ***!
|
|
7333
|
+
\************************************/
|
|
7334
|
+
/***/ ((__unused_webpack_module, exports, __webpack_require__) => {
|
|
7335
|
+
|
|
7336
|
+
"use strict";
|
|
7337
|
+
|
|
7338
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
7339
|
+
exports.connector = exports.MASSA_WINDOW_OBJECT = void 0;
|
|
7340
|
+
/**
|
|
7341
|
+
* This file defines a TypeScript module named connector.
|
|
7342
|
+
* It is the tool that allows the 'provider' and 'account' objects to communicate with the web page script.
|
|
7343
|
+
*
|
|
7344
|
+
* @remarks
|
|
7345
|
+
* - If you are only looking to use our library, the connector object will not be useful to you.
|
|
7346
|
+
* - If you want to work on this repo, you will probably be interested in this object
|
|
7347
|
+
*
|
|
7348
|
+
*/
|
|
7349
|
+
const uid_1 = __webpack_require__(/*! uid */ "./node_modules/uid/dist/index.js");
|
|
7350
|
+
const __1 = __webpack_require__(/*! .. */ "./src/index.ts");
|
|
7351
|
+
const MassaStationDiscovery_1 = __webpack_require__(/*! ../massaStation/MassaStationDiscovery */ "./src/massaStation/MassaStationDiscovery.ts");
|
|
7352
|
+
const MassaStationProvider_1 = __webpack_require__(/*! ../massaStation/MassaStationProvider */ "./src/massaStation/MassaStationProvider.ts");
|
|
7353
|
+
/**
|
|
7354
|
+
* A constant string that is used to identify the HTML element that is used for
|
|
7355
|
+
* communication between the web page script and the content script.
|
|
7356
|
+
*/
|
|
7357
|
+
exports.MASSA_WINDOW_OBJECT = 'massaWalletProvider';
|
|
7358
|
+
/**
|
|
7359
|
+
* This class enables communication with the content script by sending and receiving messages.
|
|
7360
|
+
* @remarks
|
|
7361
|
+
* - This class is used to send messages to the content script and to receive messages from the content script.
|
|
7362
|
+
* - It is used to send messages to the content script and to receive messages from the content script.
|
|
7363
|
+
*
|
|
7364
|
+
*/
|
|
7365
|
+
class Connector {
|
|
7366
|
+
/**
|
|
7367
|
+
* Connector constructor
|
|
5290
7368
|
*
|
|
5291
7369
|
* @remarks
|
|
5292
7370
|
* - The Connector constructor takes no arguments.
|
|
@@ -5353,6 +7431,7 @@ class Connector {
|
|
|
5353
7431
|
catch (e) {
|
|
5354
7432
|
console.log('MassaStation is not detected');
|
|
5355
7433
|
}
|
|
7434
|
+
// check if bearby is installed
|
|
5356
7435
|
}
|
|
5357
7436
|
/**
|
|
5358
7437
|
* This method sends a message from the webpage script to the content script.
|
|
@@ -5451,6 +7530,8 @@ if (typeof window !== 'undefined') {
|
|
|
5451
7530
|
const Connector_1 = __webpack_require__(/*! ./connector/Connector */ "./src/connector/Connector.ts");
|
|
5452
7531
|
const Provider_1 = __webpack_require__(/*! ./provider/Provider */ "./src/provider/Provider.ts");
|
|
5453
7532
|
const MassaStationProvider_1 = __webpack_require__(/*! ./massaStation/MassaStationProvider */ "./src/massaStation/MassaStationProvider.ts");
|
|
7533
|
+
const BearbyConnect_1 = __webpack_require__(/*! ./bearbyWallet/BearbyConnect */ "./src/bearbyWallet/BearbyConnect.ts");
|
|
7534
|
+
const BearbyProvider_1 = __webpack_require__(/*! ./bearbyWallet/BearbyProvider */ "./src/bearbyWallet/BearbyProvider.ts");
|
|
5454
7535
|
var AvailableCommands;
|
|
5455
7536
|
(function (AvailableCommands) {
|
|
5456
7537
|
AvailableCommands["ProviderListAccounts"] = "LIST_ACCOUNTS";
|
|
@@ -5479,6 +7560,11 @@ async function providers(retry = true, timeout = 3000, pollInterval = 500) {
|
|
|
5479
7560
|
return [];
|
|
5480
7561
|
}
|
|
5481
7562
|
await Connector_1.connector.startMassaStationDiscovery();
|
|
7563
|
+
// Look for Bearby
|
|
7564
|
+
let p;
|
|
7565
|
+
if ((0, BearbyConnect_1.detectBearby)()) {
|
|
7566
|
+
const p = new BearbyProvider_1.BearbyProvider('Bearby');
|
|
7567
|
+
}
|
|
5482
7568
|
return new Promise((resolve) => {
|
|
5483
7569
|
let provider = [];
|
|
5484
7570
|
for (const providerName of Object.keys(Connector_1.connector.getWalletProviders())) {
|
|
@@ -5491,6 +7577,10 @@ async function providers(retry = true, timeout = 3000, pollInterval = 500) {
|
|
|
5491
7577
|
provider.push(p);
|
|
5492
7578
|
}
|
|
5493
7579
|
}
|
|
7580
|
+
// Look for Bearby
|
|
7581
|
+
if (p) {
|
|
7582
|
+
provider.push(p);
|
|
7583
|
+
}
|
|
5494
7584
|
// If no providers are available, wait and try again
|
|
5495
7585
|
if (retry && provider.length === 0) {
|
|
5496
7586
|
setTimeout(() => {
|
|
@@ -6550,6 +8640,1003 @@ function uid(len) {
|
|
|
6550
8640
|
|
|
6551
8641
|
exports.uid = uid;
|
|
6552
8642
|
|
|
8643
|
+
/***/ }),
|
|
8644
|
+
|
|
8645
|
+
/***/ "./node_modules/varint/decode.js":
|
|
8646
|
+
/*!***************************************!*\
|
|
8647
|
+
!*** ./node_modules/varint/decode.js ***!
|
|
8648
|
+
\***************************************/
|
|
8649
|
+
/***/ ((module) => {
|
|
8650
|
+
|
|
8651
|
+
module.exports = read
|
|
8652
|
+
|
|
8653
|
+
var MSB = 0x80
|
|
8654
|
+
, REST = 0x7F
|
|
8655
|
+
|
|
8656
|
+
function read(buf, offset) {
|
|
8657
|
+
var res = 0
|
|
8658
|
+
, offset = offset || 0
|
|
8659
|
+
, shift = 0
|
|
8660
|
+
, counter = offset
|
|
8661
|
+
, b
|
|
8662
|
+
, l = buf.length
|
|
8663
|
+
|
|
8664
|
+
do {
|
|
8665
|
+
if (counter >= l || shift > 49) {
|
|
8666
|
+
read.bytes = 0
|
|
8667
|
+
throw new RangeError('Could not decode varint')
|
|
8668
|
+
}
|
|
8669
|
+
b = buf[counter++]
|
|
8670
|
+
res += shift < 28
|
|
8671
|
+
? (b & REST) << shift
|
|
8672
|
+
: (b & REST) * Math.pow(2, shift)
|
|
8673
|
+
shift += 7
|
|
8674
|
+
} while (b >= MSB)
|
|
8675
|
+
|
|
8676
|
+
read.bytes = counter - offset
|
|
8677
|
+
|
|
8678
|
+
return res
|
|
8679
|
+
}
|
|
8680
|
+
|
|
8681
|
+
|
|
8682
|
+
/***/ }),
|
|
8683
|
+
|
|
8684
|
+
/***/ "./node_modules/varint/encode.js":
|
|
8685
|
+
/*!***************************************!*\
|
|
8686
|
+
!*** ./node_modules/varint/encode.js ***!
|
|
8687
|
+
\***************************************/
|
|
8688
|
+
/***/ ((module) => {
|
|
8689
|
+
|
|
8690
|
+
module.exports = encode
|
|
8691
|
+
|
|
8692
|
+
var MSB = 0x80
|
|
8693
|
+
, REST = 0x7F
|
|
8694
|
+
, MSBALL = ~REST
|
|
8695
|
+
, INT = Math.pow(2, 31)
|
|
8696
|
+
|
|
8697
|
+
function encode(num, out, offset) {
|
|
8698
|
+
if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
|
|
8699
|
+
encode.bytes = 0
|
|
8700
|
+
throw new RangeError('Could not encode varint')
|
|
8701
|
+
}
|
|
8702
|
+
out = out || []
|
|
8703
|
+
offset = offset || 0
|
|
8704
|
+
var oldOffset = offset
|
|
8705
|
+
|
|
8706
|
+
while(num >= INT) {
|
|
8707
|
+
out[offset++] = (num & 0xFF) | MSB
|
|
8708
|
+
num /= 128
|
|
8709
|
+
}
|
|
8710
|
+
while(num & MSBALL) {
|
|
8711
|
+
out[offset++] = (num & 0xFF) | MSB
|
|
8712
|
+
num >>>= 7
|
|
8713
|
+
}
|
|
8714
|
+
out[offset] = num | 0
|
|
8715
|
+
|
|
8716
|
+
encode.bytes = offset - oldOffset + 1
|
|
8717
|
+
|
|
8718
|
+
return out
|
|
8719
|
+
}
|
|
8720
|
+
|
|
8721
|
+
|
|
8722
|
+
/***/ }),
|
|
8723
|
+
|
|
8724
|
+
/***/ "./node_modules/varint/index.js":
|
|
8725
|
+
/*!**************************************!*\
|
|
8726
|
+
!*** ./node_modules/varint/index.js ***!
|
|
8727
|
+
\**************************************/
|
|
8728
|
+
/***/ ((module, __unused_webpack_exports, __webpack_require__) => {
|
|
8729
|
+
|
|
8730
|
+
module.exports = {
|
|
8731
|
+
encode: __webpack_require__(/*! ./encode.js */ "./node_modules/varint/encode.js")
|
|
8732
|
+
, decode: __webpack_require__(/*! ./decode.js */ "./node_modules/varint/decode.js")
|
|
8733
|
+
, encodingLength: __webpack_require__(/*! ./length.js */ "./node_modules/varint/length.js")
|
|
8734
|
+
}
|
|
8735
|
+
|
|
8736
|
+
|
|
8737
|
+
/***/ }),
|
|
8738
|
+
|
|
8739
|
+
/***/ "./node_modules/varint/length.js":
|
|
8740
|
+
/*!***************************************!*\
|
|
8741
|
+
!*** ./node_modules/varint/length.js ***!
|
|
8742
|
+
\***************************************/
|
|
8743
|
+
/***/ ((module) => {
|
|
8744
|
+
|
|
8745
|
+
|
|
8746
|
+
var N1 = Math.pow(2, 7)
|
|
8747
|
+
var N2 = Math.pow(2, 14)
|
|
8748
|
+
var N3 = Math.pow(2, 21)
|
|
8749
|
+
var N4 = Math.pow(2, 28)
|
|
8750
|
+
var N5 = Math.pow(2, 35)
|
|
8751
|
+
var N6 = Math.pow(2, 42)
|
|
8752
|
+
var N7 = Math.pow(2, 49)
|
|
8753
|
+
var N8 = Math.pow(2, 56)
|
|
8754
|
+
var N9 = Math.pow(2, 63)
|
|
8755
|
+
|
|
8756
|
+
module.exports = function (value) {
|
|
8757
|
+
return (
|
|
8758
|
+
value < N1 ? 1
|
|
8759
|
+
: value < N2 ? 2
|
|
8760
|
+
: value < N3 ? 3
|
|
8761
|
+
: value < N4 ? 4
|
|
8762
|
+
: value < N5 ? 5
|
|
8763
|
+
: value < N6 ? 6
|
|
8764
|
+
: value < N7 ? 7
|
|
8765
|
+
: value < N8 ? 8
|
|
8766
|
+
: value < N9 ? 9
|
|
8767
|
+
: 10
|
|
8768
|
+
)
|
|
8769
|
+
}
|
|
8770
|
+
|
|
8771
|
+
|
|
8772
|
+
/***/ }),
|
|
8773
|
+
|
|
8774
|
+
/***/ "./node_modules/@hicaru/bearby.js/dist/index.js":
|
|
8775
|
+
/*!******************************************************!*\
|
|
8776
|
+
!*** ./node_modules/@hicaru/bearby.js/dist/index.js ***!
|
|
8777
|
+
\******************************************************/
|
|
8778
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
8779
|
+
|
|
8780
|
+
"use strict";
|
|
8781
|
+
__webpack_require__.r(__webpack_exports__);
|
|
8782
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
8783
|
+
/* harmony export */ ArgTypes: () => (/* binding */ ArgTypes),
|
|
8784
|
+
/* harmony export */ ContentProvider: () => (/* binding */ ContentProvider),
|
|
8785
|
+
/* harmony export */ Contract: () => (/* binding */ Contract),
|
|
8786
|
+
/* harmony export */ Massa: () => (/* binding */ Massa),
|
|
8787
|
+
/* harmony export */ Wallet: () => (/* binding */ Wallet),
|
|
8788
|
+
/* harmony export */ Web3: () => (/* binding */ Web3),
|
|
8789
|
+
/* harmony export */ web3: () => (/* binding */ web3)
|
|
8790
|
+
/* harmony export */ });
|
|
8791
|
+
/******************************************************************************
|
|
8792
|
+
Copyright (c) Microsoft Corporation.
|
|
8793
|
+
|
|
8794
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
8795
|
+
purpose with or without fee is hereby granted.
|
|
8796
|
+
|
|
8797
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8798
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
8799
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
8800
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
8801
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
8802
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
8803
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
8804
|
+
***************************************************************************** */
|
|
8805
|
+
|
|
8806
|
+
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
8807
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
8808
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
8809
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
8810
|
+
}
|
|
8811
|
+
|
|
8812
|
+
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
8813
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8814
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
8815
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
8816
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
8817
|
+
}
|
|
8818
|
+
|
|
8819
|
+
const FAVICON_REQUIRED = 'website favicon is required';
|
|
8820
|
+
const WALLET_IS_NOT_CONNECTED = 'Wallet is not connected';
|
|
8821
|
+
const INVALID_SIGN_PARAMS = 'Invalid sign params';
|
|
8822
|
+
const TIME_OUT = 'Request failed by timeout';
|
|
8823
|
+
const AVAILABLE_ONLY_BROWSER = 'bearby-web3 available only browser';
|
|
8824
|
+
const WEB3_INSTANCE_CREATED = 'bearby Web3 instance already created!';
|
|
8825
|
+
const CALLBACK_ERROR = 'Missing callback arg. use subscribe(cb => /do something/)';
|
|
8826
|
+
|
|
8827
|
+
class Transaction {
|
|
8828
|
+
get payload() {
|
|
8829
|
+
return JSON.parse(JSON.stringify({
|
|
8830
|
+
type: this.type,
|
|
8831
|
+
amount: this.amount,
|
|
8832
|
+
fee: this.fee,
|
|
8833
|
+
gasPrice: this.gasPrice,
|
|
8834
|
+
gasLimit: this.gasLimit,
|
|
8835
|
+
coins: this.coins,
|
|
8836
|
+
maxCoins: this.maxCoins,
|
|
8837
|
+
code: this.contract,
|
|
8838
|
+
func: this.functionName,
|
|
8839
|
+
params: this.parameters,
|
|
8840
|
+
toAddr: this.recipient || this.contract,
|
|
8841
|
+
deployer: this.deployer
|
|
8842
|
+
}));
|
|
8843
|
+
}
|
|
8844
|
+
constructor(type, amount, recipient, parameters, contract, functionName) {
|
|
8845
|
+
this.type = type;
|
|
8846
|
+
this.amount = String(amount);
|
|
8847
|
+
this.recipient = recipient;
|
|
8848
|
+
this.parameters = parameters || [];
|
|
8849
|
+
this.contract = contract;
|
|
8850
|
+
this.functionName = functionName;
|
|
8851
|
+
}
|
|
8852
|
+
}
|
|
8853
|
+
|
|
8854
|
+
var OperationsType;
|
|
8855
|
+
(function (OperationsType) {
|
|
8856
|
+
OperationsType[OperationsType["Payment"] = 0] = "Payment";
|
|
8857
|
+
OperationsType[OperationsType["RollBuy"] = 1] = "RollBuy";
|
|
8858
|
+
OperationsType[OperationsType["RollSell"] = 2] = "RollSell";
|
|
8859
|
+
OperationsType[OperationsType["ExecuteSC"] = 3] = "ExecuteSC";
|
|
8860
|
+
OperationsType[OperationsType["CallSC"] = 4] = "CallSC";
|
|
8861
|
+
})(OperationsType || (OperationsType = {}));
|
|
8862
|
+
|
|
8863
|
+
var JsonRPCRequestMethods;
|
|
8864
|
+
(function (JsonRPCRequestMethods) {
|
|
8865
|
+
JsonRPCRequestMethods["GET_STATUS"] = "get_status";
|
|
8866
|
+
JsonRPCRequestMethods["GET_ADDRESSES"] = "get_addresses";
|
|
8867
|
+
// SEND_OPERATIONS = 'send_operations',
|
|
8868
|
+
JsonRPCRequestMethods["GET_GRAPH_INTERVAL"] = "get_graph_interval";
|
|
8869
|
+
JsonRPCRequestMethods["GET_BLOCKS"] = "get_blocks";
|
|
8870
|
+
JsonRPCRequestMethods["GET_ENDORSEMENTS"] = "get_endorsements";
|
|
8871
|
+
JsonRPCRequestMethods["GET_OPERATIONS"] = "get_operations";
|
|
8872
|
+
JsonRPCRequestMethods["GET_CLIQUES"] = "get_cliques";
|
|
8873
|
+
JsonRPCRequestMethods["GET_STAKERS"] = "get_stakers";
|
|
8874
|
+
JsonRPCRequestMethods["GET_FILTERED_SC_OUTPUT_EVENT"] = "get_filtered_sc_output_event";
|
|
8875
|
+
JsonRPCRequestMethods["EXECUTE_READ_ONLY_BYTECODE"] = "execute_read_only_bytecode";
|
|
8876
|
+
JsonRPCRequestMethods["EXECUTE_READ_ONLY_CALL"] = "execute_read_only_call";
|
|
8877
|
+
JsonRPCRequestMethods["GET_DATASTORE_ENTRIES"] = "get_datastore_entries";
|
|
8878
|
+
})(JsonRPCRequestMethods || (JsonRPCRequestMethods = {}));
|
|
8879
|
+
|
|
8880
|
+
function utf8ToBytes(str) {
|
|
8881
|
+
let binaryArray = new Uint8Array(str.length);
|
|
8882
|
+
Array.prototype.forEach.call(binaryArray, (_, idx, arr) => {
|
|
8883
|
+
arr[idx] = str.charCodeAt(idx);
|
|
8884
|
+
});
|
|
8885
|
+
return binaryArray;
|
|
8886
|
+
}
|
|
8887
|
+
|
|
8888
|
+
var ArgTypes;
|
|
8889
|
+
(function (ArgTypes) {
|
|
8890
|
+
ArgTypes[ArgTypes["STRING"] = 0] = "STRING";
|
|
8891
|
+
ArgTypes[ArgTypes["BOOL"] = 1] = "BOOL";
|
|
8892
|
+
ArgTypes[ArgTypes["U8"] = 2] = "U8";
|
|
8893
|
+
ArgTypes[ArgTypes["U32"] = 3] = "U32";
|
|
8894
|
+
ArgTypes[ArgTypes["U64"] = 4] = "U64";
|
|
8895
|
+
ArgTypes[ArgTypes["U128"] = 5] = "U128";
|
|
8896
|
+
ArgTypes[ArgTypes["U256"] = 6] = "U256";
|
|
8897
|
+
ArgTypes[ArgTypes["I32"] = 7] = "I32";
|
|
8898
|
+
ArgTypes[ArgTypes["I64"] = 8] = "I64";
|
|
8899
|
+
ArgTypes[ArgTypes["F32"] = 9] = "F32";
|
|
8900
|
+
ArgTypes[ArgTypes["F64"] = 10] = "F64";
|
|
8901
|
+
})(ArgTypes || (ArgTypes = {}));
|
|
8902
|
+
|
|
8903
|
+
var _Contract_provider, _Contract_wallet;
|
|
8904
|
+
class Contract {
|
|
8905
|
+
constructor(provider, wallet) {
|
|
8906
|
+
_Contract_provider.set(this, void 0);
|
|
8907
|
+
_Contract_wallet.set(this, void 0);
|
|
8908
|
+
this.types = ArgTypes;
|
|
8909
|
+
__classPrivateFieldSet(this, _Contract_provider, provider, "f");
|
|
8910
|
+
__classPrivateFieldSet(this, _Contract_wallet, wallet, "f");
|
|
8911
|
+
}
|
|
8912
|
+
async deploy(params) {
|
|
8913
|
+
const transaction = new Transaction(OperationsType.ExecuteSC, '0', undefined, params.parameters, params.contractDataBase64, undefined);
|
|
8914
|
+
transaction.deployer = params.deployerBase64;
|
|
8915
|
+
transaction.fee = String(params.fee);
|
|
8916
|
+
transaction.gasLimit = String(params.maxGas);
|
|
8917
|
+
transaction.gasPrice = String(params.gasPrice);
|
|
8918
|
+
transaction.maxCoins = String(params.maxCoins);
|
|
8919
|
+
transaction.coins = String(params.coins);
|
|
8920
|
+
return __classPrivateFieldGet(this, _Contract_wallet, "f").signTransaction(transaction);
|
|
8921
|
+
}
|
|
8922
|
+
async call(params) {
|
|
8923
|
+
const transaction = new Transaction(OperationsType.CallSC, '0', undefined, params.parameters, params.targetAddress, params.functionName);
|
|
8924
|
+
transaction.fee = String(params.fee);
|
|
8925
|
+
transaction.gasLimit = String(params.maxGas);
|
|
8926
|
+
transaction.coins = String(params.coins || 0);
|
|
8927
|
+
return __classPrivateFieldGet(this, _Contract_wallet, "f").signTransaction(transaction);
|
|
8928
|
+
}
|
|
8929
|
+
async getFilteredSCOutputEvent(...filters) {
|
|
8930
|
+
const method = JsonRPCRequestMethods.GET_FILTERED_SC_OUTPUT_EVENT;
|
|
8931
|
+
const responses = await __classPrivateFieldGet(this, _Contract_provider, "f").send(filters.map((filter) => ({
|
|
8932
|
+
method,
|
|
8933
|
+
params: [filter]
|
|
8934
|
+
})));
|
|
8935
|
+
if (filters.length === 1) {
|
|
8936
|
+
return responses[0];
|
|
8937
|
+
}
|
|
8938
|
+
return responses;
|
|
8939
|
+
}
|
|
8940
|
+
async getDatastoreEntries(...params) {
|
|
8941
|
+
const method = JsonRPCRequestMethods.GET_DATASTORE_ENTRIES;
|
|
8942
|
+
const data = [];
|
|
8943
|
+
for (const { key, address } of params) {
|
|
8944
|
+
data.push({
|
|
8945
|
+
address,
|
|
8946
|
+
key: Array.from(utf8ToBytes(key))
|
|
8947
|
+
});
|
|
8948
|
+
}
|
|
8949
|
+
return await __classPrivateFieldGet(this, _Contract_provider, "f").send([{
|
|
8950
|
+
method,
|
|
8951
|
+
params: [data]
|
|
8952
|
+
}]);
|
|
8953
|
+
}
|
|
8954
|
+
async executeReadOlyBytecode(params) {
|
|
8955
|
+
const method = JsonRPCRequestMethods.EXECUTE_READ_ONLY_BYTECODE;
|
|
8956
|
+
return __classPrivateFieldGet(this, _Contract_provider, "f").send([{
|
|
8957
|
+
method,
|
|
8958
|
+
params: [params]
|
|
8959
|
+
}]);
|
|
8960
|
+
}
|
|
8961
|
+
async readSmartContract(...params) {
|
|
8962
|
+
const method = JsonRPCRequestMethods.EXECUTE_READ_ONLY_CALL;
|
|
8963
|
+
const responses = await __classPrivateFieldGet(this, _Contract_provider, "f").send([{
|
|
8964
|
+
method,
|
|
8965
|
+
params: [params.map((v) => ({
|
|
8966
|
+
max_gas: v.maxGas,
|
|
8967
|
+
simulated_gas_price: String(v.simulatedGasPrice),
|
|
8968
|
+
target_address: v.targetAddress,
|
|
8969
|
+
target_function: v.targetFunction,
|
|
8970
|
+
parameters: v.parameters,
|
|
8971
|
+
caller_address: v.callerAddress || __classPrivateFieldGet(this, _Contract_wallet, "f").account.base58
|
|
8972
|
+
}))]
|
|
8973
|
+
}]);
|
|
8974
|
+
if (params.length === 1) {
|
|
8975
|
+
return responses[0];
|
|
8976
|
+
}
|
|
8977
|
+
return responses;
|
|
8978
|
+
}
|
|
8979
|
+
}
|
|
8980
|
+
_Contract_provider = new WeakMap(), _Contract_wallet = new WeakMap();
|
|
8981
|
+
|
|
8982
|
+
// This string need that sould did't have problem with conflicts.
|
|
8983
|
+
const app = 'BearBy';
|
|
8984
|
+
const MTypeTabContent = {
|
|
8985
|
+
CONTENT: `@/${app}/content-script`,
|
|
8986
|
+
INJECTED: `@/${app}/injected-script`
|
|
8987
|
+
};
|
|
8988
|
+
const MTypeTab = {
|
|
8989
|
+
GET_DATA: `@/${app}/get-wallet-data`,
|
|
8990
|
+
NEW_SLOT: `@/${app}/new-slot-emited`,
|
|
8991
|
+
ACCOUNT_CHANGED: `@/${app}/accounts-just-changed`,
|
|
8992
|
+
CONTENT_PROXY_MEHTOD: `@/${app}/proxy-method`,
|
|
8993
|
+
CONTENT_PROXY_RESULT: `@/${app}/response-from-content`,
|
|
8994
|
+
CONNECT_APP: `@/${app}/connect-app`,
|
|
8995
|
+
RESPONSE_CONNECT_APP: `@/${app}/respoonse-connect-app`,
|
|
8996
|
+
NETWORK_CHANGED: `@/${app}/network-just-changed`,
|
|
8997
|
+
DISCONNECT_APP: `@/${app}/disconnect_app`,
|
|
8998
|
+
DISCONNECT_APP_RESULT: `@/${app}/disconnect_app_result`,
|
|
8999
|
+
LOCKED: `@/${app}/guard-just-lock`,
|
|
9000
|
+
TX_TO_SEND: `@/${app}/add-tx-to-send`,
|
|
9001
|
+
TX_TO_SEND_RESULT: `@/${app}/response-tx-result`,
|
|
9002
|
+
CHECK_MASSA_ADDRESS: `@/${app}/check-massa-address`,
|
|
9003
|
+
CHECK_MASSA_ADDRESS_RES: `@/${app}/check-massa-address-response`,
|
|
9004
|
+
SIGN_MESSAGE: `@/${app}/sign-message-call`,
|
|
9005
|
+
SING_MESSAGE_RESULT: `@/${app}/sign-message-response`
|
|
9006
|
+
};
|
|
9007
|
+
|
|
9008
|
+
var _TabStream_instances, _TabStream_eventName, _TabStream_dispatch, _TabStream_getEventInit, _TabStream_getEvent;
|
|
9009
|
+
const { document } = globalThis;
|
|
9010
|
+
/**
|
|
9011
|
+
* Used for communication between a web page and an extension's content script.
|
|
9012
|
+
*/
|
|
9013
|
+
class TabStream {
|
|
9014
|
+
/**
|
|
9015
|
+
* Creates a new TabStream.
|
|
9016
|
+
* @param {String} eventName - Event type.
|
|
9017
|
+
*/
|
|
9018
|
+
constructor(eventName) {
|
|
9019
|
+
_TabStream_instances.add(this);
|
|
9020
|
+
_TabStream_eventName.set(this, void 0);
|
|
9021
|
+
__classPrivateFieldSet(this, _TabStream_eventName, eventName, "f");
|
|
9022
|
+
}
|
|
9023
|
+
/**
|
|
9024
|
+
* Message listener that returns decrypted messages when synced
|
|
9025
|
+
*/
|
|
9026
|
+
listen(cb) {
|
|
9027
|
+
document.addEventListener(__classPrivateFieldGet(this, _TabStream_eventName, "f"), (event) => {
|
|
9028
|
+
if (event && event.detail) {
|
|
9029
|
+
cb(JSON.parse(event.detail));
|
|
9030
|
+
}
|
|
9031
|
+
});
|
|
9032
|
+
}
|
|
9033
|
+
/**
|
|
9034
|
+
* Message sender which encrypts messages and adds the sender.
|
|
9035
|
+
* @param data - The payload to send.
|
|
9036
|
+
* @param to - The stream to send messages to.
|
|
9037
|
+
*/
|
|
9038
|
+
send(data, to) {
|
|
9039
|
+
data.from = __classPrivateFieldGet(this, _TabStream_eventName, "f");
|
|
9040
|
+
if (Object.values(MTypeTabContent).includes(to)) {
|
|
9041
|
+
__classPrivateFieldGet(this, _TabStream_instances, "m", _TabStream_dispatch).call(this, JSON.stringify(data), to);
|
|
9042
|
+
}
|
|
9043
|
+
}
|
|
9044
|
+
}
|
|
9045
|
+
_TabStream_eventName = new WeakMap(), _TabStream_instances = new WeakSet(), _TabStream_dispatch = function _TabStream_dispatch(data, to) {
|
|
9046
|
+
document.dispatchEvent(__classPrivateFieldGet(this, _TabStream_instances, "m", _TabStream_getEvent).call(this, data, to));
|
|
9047
|
+
}, _TabStream_getEventInit = function _TabStream_getEventInit(detail) {
|
|
9048
|
+
return {
|
|
9049
|
+
detail
|
|
9050
|
+
};
|
|
9051
|
+
}, _TabStream_getEvent = function _TabStream_getEvent(detail, to) {
|
|
9052
|
+
return new CustomEvent(to, __classPrivateFieldGet(this, _TabStream_instances, "m", _TabStream_getEventInit).call(this, detail));
|
|
9053
|
+
};
|
|
9054
|
+
|
|
9055
|
+
var _Subject_events;
|
|
9056
|
+
class Subject {
|
|
9057
|
+
constructor() {
|
|
9058
|
+
_Subject_events.set(this, []);
|
|
9059
|
+
}
|
|
9060
|
+
on(listener) {
|
|
9061
|
+
__classPrivateFieldGet(this, _Subject_events, "f").push(listener);
|
|
9062
|
+
return () => this.removeListener(listener);
|
|
9063
|
+
}
|
|
9064
|
+
removeListener(listener) {
|
|
9065
|
+
const idx = __classPrivateFieldGet(this, _Subject_events, "f").indexOf(listener);
|
|
9066
|
+
if (idx > -1)
|
|
9067
|
+
__classPrivateFieldGet(this, _Subject_events, "f").splice(idx, 1);
|
|
9068
|
+
}
|
|
9069
|
+
removeAllListeners() {
|
|
9070
|
+
__classPrivateFieldGet(this, _Subject_events, "f").splice(0, __classPrivateFieldGet(this, _Subject_events, "f").length);
|
|
9071
|
+
}
|
|
9072
|
+
emit(...args) {
|
|
9073
|
+
__classPrivateFieldGet(this, _Subject_events, "f").forEach(listener => listener.apply(this, args));
|
|
9074
|
+
}
|
|
9075
|
+
once(listener) {
|
|
9076
|
+
const remove = this.on((...args) => {
|
|
9077
|
+
remove();
|
|
9078
|
+
listener.apply(this, args);
|
|
9079
|
+
});
|
|
9080
|
+
}
|
|
9081
|
+
}
|
|
9082
|
+
_Subject_events = new WeakMap();
|
|
9083
|
+
|
|
9084
|
+
var _ContentMessage_body;
|
|
9085
|
+
class ContentMessage {
|
|
9086
|
+
get type() {
|
|
9087
|
+
return __classPrivateFieldGet(this, _ContentMessage_body, "f").type;
|
|
9088
|
+
}
|
|
9089
|
+
get payload() {
|
|
9090
|
+
return __classPrivateFieldGet(this, _ContentMessage_body, "f").payload;
|
|
9091
|
+
}
|
|
9092
|
+
constructor(msg) {
|
|
9093
|
+
_ContentMessage_body.set(this, void 0);
|
|
9094
|
+
__classPrivateFieldSet(this, _ContentMessage_body, msg, "f");
|
|
9095
|
+
}
|
|
9096
|
+
/**
|
|
9097
|
+
* Method for send message.
|
|
9098
|
+
*/
|
|
9099
|
+
send(stream, recipient) {
|
|
9100
|
+
const seralized = JSON.stringify(__classPrivateFieldGet(this, _ContentMessage_body, "f"));
|
|
9101
|
+
const deserialized = JSON.parse(seralized);
|
|
9102
|
+
stream.send(deserialized, recipient);
|
|
9103
|
+
}
|
|
9104
|
+
}
|
|
9105
|
+
_ContentMessage_body = new WeakMap();
|
|
9106
|
+
|
|
9107
|
+
class Handler {
|
|
9108
|
+
constructor() {
|
|
9109
|
+
this.stream = new TabStream(MTypeTabContent.INJECTED);
|
|
9110
|
+
this.subject = new Subject();
|
|
9111
|
+
if (globalThis.document) {
|
|
9112
|
+
// only not ssr
|
|
9113
|
+
this.stream.listen((msg) => {
|
|
9114
|
+
this.subject.emit(msg);
|
|
9115
|
+
});
|
|
9116
|
+
}
|
|
9117
|
+
}
|
|
9118
|
+
initialized() {
|
|
9119
|
+
const type = MTypeTab.GET_DATA;
|
|
9120
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9121
|
+
new ContentMessage({
|
|
9122
|
+
type,
|
|
9123
|
+
payload: {}
|
|
9124
|
+
}).send(this.stream, recipient);
|
|
9125
|
+
}
|
|
9126
|
+
}
|
|
9127
|
+
|
|
9128
|
+
function uuidv4() {
|
|
9129
|
+
const size = 20;
|
|
9130
|
+
return [...Array(size)].map(() => Math.floor(Math.random() * 16).toString(16)).join('');
|
|
9131
|
+
}
|
|
9132
|
+
|
|
9133
|
+
const TIME_OUT_SECONDS = 5000;
|
|
9134
|
+
|
|
9135
|
+
var _ContentProvider_stream, _ContentProvider_subject;
|
|
9136
|
+
class ContentProvider {
|
|
9137
|
+
constructor(stream, subject) {
|
|
9138
|
+
_ContentProvider_stream.set(this, void 0);
|
|
9139
|
+
_ContentProvider_subject.set(this, void 0);
|
|
9140
|
+
__classPrivateFieldSet(this, _ContentProvider_stream, stream, "f");
|
|
9141
|
+
__classPrivateFieldSet(this, _ContentProvider_subject, subject, "f");
|
|
9142
|
+
}
|
|
9143
|
+
async send(body) {
|
|
9144
|
+
const type = MTypeTab.CONTENT_PROXY_MEHTOD;
|
|
9145
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9146
|
+
const uuid = uuidv4();
|
|
9147
|
+
let sub;
|
|
9148
|
+
new ContentMessage({
|
|
9149
|
+
type,
|
|
9150
|
+
payload: {
|
|
9151
|
+
body,
|
|
9152
|
+
uuid
|
|
9153
|
+
}
|
|
9154
|
+
}).send(__classPrivateFieldGet(this, _ContentProvider_stream, "f"), recipient);
|
|
9155
|
+
const fulfilled = new Promise((resolve, reject) => {
|
|
9156
|
+
sub = __classPrivateFieldGet(this, _ContentProvider_subject, "f").on((msg) => {
|
|
9157
|
+
if (msg.type !== MTypeTab.CONTENT_PROXY_RESULT)
|
|
9158
|
+
return;
|
|
9159
|
+
if (!msg.payload || !msg.payload.uuid)
|
|
9160
|
+
return;
|
|
9161
|
+
if (msg.payload.uuid !== uuid)
|
|
9162
|
+
return;
|
|
9163
|
+
if (msg.payload && msg.payload.reject) {
|
|
9164
|
+
sub();
|
|
9165
|
+
return reject(new Error(msg.payload.reject));
|
|
9166
|
+
}
|
|
9167
|
+
delete msg.payload.uuid;
|
|
9168
|
+
sub();
|
|
9169
|
+
return resolve(msg.payload.resolve);
|
|
9170
|
+
});
|
|
9171
|
+
});
|
|
9172
|
+
const timeout = new Promise((_, reject) => {
|
|
9173
|
+
setTimeout(() => {
|
|
9174
|
+
if (sub)
|
|
9175
|
+
sub();
|
|
9176
|
+
reject(new Error(TIME_OUT));
|
|
9177
|
+
}, TIME_OUT_SECONDS);
|
|
9178
|
+
});
|
|
9179
|
+
return Promise.race([fulfilled, timeout]);
|
|
9180
|
+
}
|
|
9181
|
+
}
|
|
9182
|
+
_ContentProvider_stream = new WeakMap(), _ContentProvider_subject = new WeakMap();
|
|
9183
|
+
|
|
9184
|
+
var _Massa_provider, _Massa_wallet;
|
|
9185
|
+
class Massa {
|
|
9186
|
+
constructor(provider, wallet) {
|
|
9187
|
+
_Massa_provider.set(this, void 0);
|
|
9188
|
+
_Massa_wallet.set(this, void 0);
|
|
9189
|
+
__classPrivateFieldSet(this, _Massa_provider, provider, "f");
|
|
9190
|
+
__classPrivateFieldSet(this, _Massa_wallet, wallet, "f");
|
|
9191
|
+
}
|
|
9192
|
+
async getNodesStatus() {
|
|
9193
|
+
const method = JsonRPCRequestMethods.GET_STATUS;
|
|
9194
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9195
|
+
method,
|
|
9196
|
+
params: []
|
|
9197
|
+
}]);
|
|
9198
|
+
return res;
|
|
9199
|
+
}
|
|
9200
|
+
async getAddresses(...addresses) {
|
|
9201
|
+
const method = JsonRPCRequestMethods.GET_ADDRESSES;
|
|
9202
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9203
|
+
method,
|
|
9204
|
+
params: [addresses]
|
|
9205
|
+
}]);
|
|
9206
|
+
return res;
|
|
9207
|
+
}
|
|
9208
|
+
async getBlocks(...blocks) {
|
|
9209
|
+
const method = JsonRPCRequestMethods.GET_BLOCKS;
|
|
9210
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9211
|
+
method,
|
|
9212
|
+
params: [blocks]
|
|
9213
|
+
}]);
|
|
9214
|
+
return res;
|
|
9215
|
+
}
|
|
9216
|
+
async getGraphInterval(start, end) {
|
|
9217
|
+
const method = JsonRPCRequestMethods.GET_GRAPH_INTERVAL;
|
|
9218
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9219
|
+
method,
|
|
9220
|
+
params: [{
|
|
9221
|
+
start,
|
|
9222
|
+
end
|
|
9223
|
+
}]
|
|
9224
|
+
}]);
|
|
9225
|
+
return res;
|
|
9226
|
+
}
|
|
9227
|
+
async getOperations(...operations) {
|
|
9228
|
+
const method = JsonRPCRequestMethods.GET_OPERATIONS;
|
|
9229
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9230
|
+
method,
|
|
9231
|
+
params: [operations]
|
|
9232
|
+
}]);
|
|
9233
|
+
return res;
|
|
9234
|
+
}
|
|
9235
|
+
async getStakers() {
|
|
9236
|
+
const method = JsonRPCRequestMethods.GET_STAKERS;
|
|
9237
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9238
|
+
method,
|
|
9239
|
+
params: []
|
|
9240
|
+
}]);
|
|
9241
|
+
return res;
|
|
9242
|
+
}
|
|
9243
|
+
async getEndorsements(...Ids) {
|
|
9244
|
+
const method = JsonRPCRequestMethods.GET_ENDORSEMENTS;
|
|
9245
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9246
|
+
method,
|
|
9247
|
+
params: [Ids]
|
|
9248
|
+
}]);
|
|
9249
|
+
return res;
|
|
9250
|
+
}
|
|
9251
|
+
async getCliques() {
|
|
9252
|
+
const method = JsonRPCRequestMethods.GET_CLIQUES;
|
|
9253
|
+
const [res] = await __classPrivateFieldGet(this, _Massa_provider, "f").send([{
|
|
9254
|
+
method,
|
|
9255
|
+
params: []
|
|
9256
|
+
}]);
|
|
9257
|
+
return res;
|
|
9258
|
+
}
|
|
9259
|
+
async payment(amount, recipient) {
|
|
9260
|
+
const transaction = new Transaction(OperationsType.Payment, amount, recipient);
|
|
9261
|
+
return __classPrivateFieldGet(this, _Massa_wallet, "f").signTransaction(transaction);
|
|
9262
|
+
}
|
|
9263
|
+
async buyRolls(amount = '1') {
|
|
9264
|
+
const transaction = new Transaction(OperationsType.RollBuy, amount);
|
|
9265
|
+
return __classPrivateFieldGet(this, _Massa_wallet, "f").signTransaction(transaction);
|
|
9266
|
+
}
|
|
9267
|
+
async sellRolls(amount = '1') {
|
|
9268
|
+
const transaction = new Transaction(OperationsType.RollSell, amount);
|
|
9269
|
+
return __classPrivateFieldGet(this, _Massa_wallet, "f").signTransaction(transaction);
|
|
9270
|
+
}
|
|
9271
|
+
}
|
|
9272
|
+
_Massa_provider = new WeakMap(), _Massa_wallet = new WeakMap();
|
|
9273
|
+
|
|
9274
|
+
function assert(expressions, msg) {
|
|
9275
|
+
if (!expressions) {
|
|
9276
|
+
throw new Error(msg);
|
|
9277
|
+
}
|
|
9278
|
+
}
|
|
9279
|
+
|
|
9280
|
+
function getFavicon() {
|
|
9281
|
+
let ref = globalThis.document.querySelector('link[rel*=\'icon\']');
|
|
9282
|
+
if (!ref) {
|
|
9283
|
+
throw new Error(FAVICON_REQUIRED);
|
|
9284
|
+
}
|
|
9285
|
+
return ref.href;
|
|
9286
|
+
}
|
|
9287
|
+
|
|
9288
|
+
var _Account_subject;
|
|
9289
|
+
class Account {
|
|
9290
|
+
constructor(subject) {
|
|
9291
|
+
_Account_subject.set(this, void 0);
|
|
9292
|
+
__classPrivateFieldSet(this, _Account_subject, subject, "f");
|
|
9293
|
+
}
|
|
9294
|
+
subscribe(cb) {
|
|
9295
|
+
if (!cb) {
|
|
9296
|
+
throw new Error(CALLBACK_ERROR);
|
|
9297
|
+
}
|
|
9298
|
+
if (this.base58) {
|
|
9299
|
+
cb(this.base58);
|
|
9300
|
+
}
|
|
9301
|
+
const obs = __classPrivateFieldGet(this, _Account_subject, "f").on((msg) => {
|
|
9302
|
+
switch (msg.type) {
|
|
9303
|
+
case MTypeTab.DISCONNECT_APP_RESULT:
|
|
9304
|
+
this.base58 = undefined;
|
|
9305
|
+
break;
|
|
9306
|
+
case MTypeTab.ACCOUNT_CHANGED:
|
|
9307
|
+
this.base58 = msg.payload.base58;
|
|
9308
|
+
break;
|
|
9309
|
+
case MTypeTab.RESPONSE_CONNECT_APP:
|
|
9310
|
+
this.base58 = msg.payload.base58;
|
|
9311
|
+
break;
|
|
9312
|
+
case MTypeTab.GET_DATA:
|
|
9313
|
+
this.base58 = msg.payload.base58;
|
|
9314
|
+
break;
|
|
9315
|
+
default:
|
|
9316
|
+
return;
|
|
9317
|
+
}
|
|
9318
|
+
cb(this.base58);
|
|
9319
|
+
});
|
|
9320
|
+
return {
|
|
9321
|
+
unsubscribe: () => obs()
|
|
9322
|
+
};
|
|
9323
|
+
}
|
|
9324
|
+
}
|
|
9325
|
+
_Account_subject = new WeakMap();
|
|
9326
|
+
|
|
9327
|
+
var _Network_subject;
|
|
9328
|
+
class Network {
|
|
9329
|
+
constructor(subject) {
|
|
9330
|
+
_Network_subject.set(this, void 0);
|
|
9331
|
+
__classPrivateFieldSet(this, _Network_subject, subject, "f");
|
|
9332
|
+
}
|
|
9333
|
+
subscribe(cb) {
|
|
9334
|
+
cb(this.net);
|
|
9335
|
+
const obs = __classPrivateFieldGet(this, _Network_subject, "f").on((msg) => {
|
|
9336
|
+
switch (msg.type) {
|
|
9337
|
+
case MTypeTab.RESPONSE_CONNECT_APP:
|
|
9338
|
+
this.net = msg.payload.net;
|
|
9339
|
+
break;
|
|
9340
|
+
case MTypeTab.GET_DATA:
|
|
9341
|
+
this.net = msg.payload.net;
|
|
9342
|
+
break;
|
|
9343
|
+
case MTypeTab.NETWORK_CHANGED:
|
|
9344
|
+
this.net = msg.payload.net;
|
|
9345
|
+
break;
|
|
9346
|
+
default:
|
|
9347
|
+
return;
|
|
9348
|
+
}
|
|
9349
|
+
cb(this.net);
|
|
9350
|
+
});
|
|
9351
|
+
return {
|
|
9352
|
+
unsubscribe: () => obs()
|
|
9353
|
+
};
|
|
9354
|
+
}
|
|
9355
|
+
}
|
|
9356
|
+
_Network_subject = new WeakMap();
|
|
9357
|
+
|
|
9358
|
+
var _Blockchain_subject;
|
|
9359
|
+
class Blockchain {
|
|
9360
|
+
constructor(subject) {
|
|
9361
|
+
_Blockchain_subject.set(this, void 0);
|
|
9362
|
+
this.period = -1;
|
|
9363
|
+
__classPrivateFieldSet(this, _Blockchain_subject, subject, "f");
|
|
9364
|
+
}
|
|
9365
|
+
subscribe(cb) {
|
|
9366
|
+
const obs = __classPrivateFieldGet(this, _Blockchain_subject, "f").on((msg) => {
|
|
9367
|
+
switch (msg.type) {
|
|
9368
|
+
case MTypeTab.NEW_SLOT:
|
|
9369
|
+
this.period = msg.payload;
|
|
9370
|
+
cb(this.period);
|
|
9371
|
+
break;
|
|
9372
|
+
case MTypeTab.GET_DATA:
|
|
9373
|
+
this.period = msg.payload.period;
|
|
9374
|
+
cb(this.period);
|
|
9375
|
+
break;
|
|
9376
|
+
case MTypeTab.NETWORK_CHANGED:
|
|
9377
|
+
this.period = msg.payload.period;
|
|
9378
|
+
cb(this.period);
|
|
9379
|
+
break;
|
|
9380
|
+
}
|
|
9381
|
+
});
|
|
9382
|
+
return {
|
|
9383
|
+
unsubscribe: () => obs()
|
|
9384
|
+
};
|
|
9385
|
+
}
|
|
9386
|
+
}
|
|
9387
|
+
_Blockchain_subject = new WeakMap();
|
|
9388
|
+
|
|
9389
|
+
var _Wallet_instances, _Wallet_account, _Wallet_network, _Wallet_blockchain, _Wallet_stream, _Wallet_subject, _Wallet_connected, _Wallet_enabled, _Wallet_subscribe;
|
|
9390
|
+
class Wallet {
|
|
9391
|
+
get account() {
|
|
9392
|
+
return __classPrivateFieldGet(this, _Wallet_account, "f");
|
|
9393
|
+
}
|
|
9394
|
+
get network() {
|
|
9395
|
+
return __classPrivateFieldGet(this, _Wallet_network, "f");
|
|
9396
|
+
}
|
|
9397
|
+
get blockchain() {
|
|
9398
|
+
return __classPrivateFieldGet(this, _Wallet_blockchain, "f");
|
|
9399
|
+
}
|
|
9400
|
+
get connected() {
|
|
9401
|
+
return __classPrivateFieldGet(this, _Wallet_connected, "f");
|
|
9402
|
+
}
|
|
9403
|
+
get enabled() {
|
|
9404
|
+
return __classPrivateFieldGet(this, _Wallet_enabled, "f");
|
|
9405
|
+
}
|
|
9406
|
+
constructor(stream, subject) {
|
|
9407
|
+
_Wallet_instances.add(this);
|
|
9408
|
+
_Wallet_account.set(this, void 0);
|
|
9409
|
+
_Wallet_network.set(this, void 0);
|
|
9410
|
+
_Wallet_blockchain.set(this, void 0);
|
|
9411
|
+
_Wallet_stream.set(this, void 0);
|
|
9412
|
+
_Wallet_subject.set(this, void 0);
|
|
9413
|
+
_Wallet_connected.set(this, false);
|
|
9414
|
+
_Wallet_enabled.set(this, false);
|
|
9415
|
+
__classPrivateFieldSet(this, _Wallet_stream, stream, "f");
|
|
9416
|
+
__classPrivateFieldSet(this, _Wallet_subject, subject, "f");
|
|
9417
|
+
__classPrivateFieldSet(this, _Wallet_account, new Account(subject), "f");
|
|
9418
|
+
__classPrivateFieldSet(this, _Wallet_network, new Network(subject), "f");
|
|
9419
|
+
__classPrivateFieldSet(this, _Wallet_blockchain, new Blockchain(subject), "f");
|
|
9420
|
+
__classPrivateFieldGet(this, _Wallet_instances, "m", _Wallet_subscribe).call(this);
|
|
9421
|
+
}
|
|
9422
|
+
async diconnect() {
|
|
9423
|
+
const type = MTypeTab.DISCONNECT_APP;
|
|
9424
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9425
|
+
const title = window.document.title;
|
|
9426
|
+
const icon = getFavicon();
|
|
9427
|
+
const uuid = uuidv4();
|
|
9428
|
+
const payload = {
|
|
9429
|
+
title,
|
|
9430
|
+
icon,
|
|
9431
|
+
uuid
|
|
9432
|
+
};
|
|
9433
|
+
new ContentMessage({
|
|
9434
|
+
type,
|
|
9435
|
+
payload
|
|
9436
|
+
}).send(__classPrivateFieldGet(this, _Wallet_stream, "f"), recipient);
|
|
9437
|
+
return new Promise((resolve, reject) => {
|
|
9438
|
+
const obs = __classPrivateFieldGet(this, _Wallet_subject, "f").on((msg) => {
|
|
9439
|
+
if (msg.type !== MTypeTab.DISCONNECT_APP_RESULT)
|
|
9440
|
+
return;
|
|
9441
|
+
if (msg.payload.uuid !== uuid)
|
|
9442
|
+
return;
|
|
9443
|
+
if (msg.payload.reject) {
|
|
9444
|
+
obs();
|
|
9445
|
+
return reject(new Error(msg.payload.reject));
|
|
9446
|
+
}
|
|
9447
|
+
__classPrivateFieldSet(this, _Wallet_connected, false, "f");
|
|
9448
|
+
__classPrivateFieldGet(this, _Wallet_account, "f").base58 = undefined;
|
|
9449
|
+
__classPrivateFieldGet(this, _Wallet_network, "f").net = msg.payload.net;
|
|
9450
|
+
obs();
|
|
9451
|
+
return resolve(this.connected);
|
|
9452
|
+
});
|
|
9453
|
+
});
|
|
9454
|
+
}
|
|
9455
|
+
async isMassaAddress(addr) {
|
|
9456
|
+
const type = MTypeTab.CHECK_MASSA_ADDRESS;
|
|
9457
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9458
|
+
const uuid = uuidv4();
|
|
9459
|
+
const payload = {
|
|
9460
|
+
uuid,
|
|
9461
|
+
addr
|
|
9462
|
+
};
|
|
9463
|
+
new ContentMessage({
|
|
9464
|
+
type,
|
|
9465
|
+
payload
|
|
9466
|
+
}).send(__classPrivateFieldGet(this, _Wallet_stream, "f"), recipient);
|
|
9467
|
+
return new Promise((resolve) => {
|
|
9468
|
+
const obs = __classPrivateFieldGet(this, _Wallet_subject, "f").on((msg) => {
|
|
9469
|
+
if (msg.type !== MTypeTab.CHECK_MASSA_ADDRESS_RES)
|
|
9470
|
+
return;
|
|
9471
|
+
if (msg.payload.uuid !== uuid)
|
|
9472
|
+
return;
|
|
9473
|
+
obs();
|
|
9474
|
+
return resolve(msg.payload.resolve);
|
|
9475
|
+
});
|
|
9476
|
+
});
|
|
9477
|
+
}
|
|
9478
|
+
async connect() {
|
|
9479
|
+
const type = MTypeTab.CONNECT_APP;
|
|
9480
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9481
|
+
const uuid = uuidv4();
|
|
9482
|
+
const title = window.document.title;
|
|
9483
|
+
const icon = getFavicon();
|
|
9484
|
+
const payload = {
|
|
9485
|
+
title,
|
|
9486
|
+
icon,
|
|
9487
|
+
uuid
|
|
9488
|
+
};
|
|
9489
|
+
new ContentMessage({
|
|
9490
|
+
type,
|
|
9491
|
+
payload
|
|
9492
|
+
}).send(__classPrivateFieldGet(this, _Wallet_stream, "f"), recipient);
|
|
9493
|
+
return new Promise((resolve, reject) => {
|
|
9494
|
+
const obs = __classPrivateFieldGet(this, _Wallet_subject, "f").on((msg) => {
|
|
9495
|
+
if (msg.type !== MTypeTab.RESPONSE_CONNECT_APP)
|
|
9496
|
+
return;
|
|
9497
|
+
if (msg.payload.uuid !== uuid)
|
|
9498
|
+
return;
|
|
9499
|
+
if (msg.payload.reject) {
|
|
9500
|
+
obs();
|
|
9501
|
+
return reject(new Error(msg.payload.reject));
|
|
9502
|
+
}
|
|
9503
|
+
__classPrivateFieldSet(this, _Wallet_connected, Boolean(msg.payload.resolve), "f");
|
|
9504
|
+
__classPrivateFieldGet(this, _Wallet_account, "f").base58 = msg.payload.base58;
|
|
9505
|
+
__classPrivateFieldGet(this, _Wallet_network, "f").net = msg.payload.net;
|
|
9506
|
+
obs();
|
|
9507
|
+
return resolve(this.connected);
|
|
9508
|
+
});
|
|
9509
|
+
});
|
|
9510
|
+
}
|
|
9511
|
+
async signMessage(message) {
|
|
9512
|
+
assert(this.connected, WALLET_IS_NOT_CONNECTED);
|
|
9513
|
+
const type = MTypeTab.SIGN_MESSAGE;
|
|
9514
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9515
|
+
const uuid = uuidv4();
|
|
9516
|
+
const title = window.document.title;
|
|
9517
|
+
const icon = getFavicon();
|
|
9518
|
+
const payload = {
|
|
9519
|
+
message,
|
|
9520
|
+
uuid,
|
|
9521
|
+
title,
|
|
9522
|
+
icon
|
|
9523
|
+
};
|
|
9524
|
+
new ContentMessage({
|
|
9525
|
+
type,
|
|
9526
|
+
payload
|
|
9527
|
+
}).send(__classPrivateFieldGet(this, _Wallet_stream, "f"), recipient);
|
|
9528
|
+
return new Promise((resolve, reject) => {
|
|
9529
|
+
const obs = __classPrivateFieldGet(this, _Wallet_subject, "f").on((msg) => {
|
|
9530
|
+
if (msg.type !== MTypeTab.SING_MESSAGE_RESULT)
|
|
9531
|
+
return;
|
|
9532
|
+
if (msg.payload.uuid !== uuid)
|
|
9533
|
+
return;
|
|
9534
|
+
if (msg.payload && msg.payload.reject) {
|
|
9535
|
+
obs();
|
|
9536
|
+
return reject(new Error(msg.payload.reject));
|
|
9537
|
+
}
|
|
9538
|
+
obs();
|
|
9539
|
+
return resolve(msg.payload.resolve);
|
|
9540
|
+
});
|
|
9541
|
+
});
|
|
9542
|
+
}
|
|
9543
|
+
async signTransaction(tx) {
|
|
9544
|
+
assert(this.connected, WALLET_IS_NOT_CONNECTED);
|
|
9545
|
+
assert(tx instanceof Transaction, INVALID_SIGN_PARAMS);
|
|
9546
|
+
const type = MTypeTab.TX_TO_SEND;
|
|
9547
|
+
const recipient = MTypeTabContent.CONTENT;
|
|
9548
|
+
const uuid = uuidv4();
|
|
9549
|
+
const payload = {
|
|
9550
|
+
...tx.payload,
|
|
9551
|
+
uuid,
|
|
9552
|
+
title: window.document.title,
|
|
9553
|
+
icon: getFavicon()
|
|
9554
|
+
};
|
|
9555
|
+
new ContentMessage({
|
|
9556
|
+
type,
|
|
9557
|
+
payload
|
|
9558
|
+
}).send(__classPrivateFieldGet(this, _Wallet_stream, "f"), recipient);
|
|
9559
|
+
return new Promise((resolve, reject) => {
|
|
9560
|
+
const obs = __classPrivateFieldGet(this, _Wallet_subject, "f").on((msg) => {
|
|
9561
|
+
if (msg.type !== MTypeTab.TX_TO_SEND_RESULT)
|
|
9562
|
+
return;
|
|
9563
|
+
if (msg.payload.uuid !== uuid)
|
|
9564
|
+
return;
|
|
9565
|
+
if (msg.payload && msg.payload.reject) {
|
|
9566
|
+
obs();
|
|
9567
|
+
return reject(new Error(msg.payload.reject));
|
|
9568
|
+
}
|
|
9569
|
+
obs();
|
|
9570
|
+
return resolve(msg.payload.resolve);
|
|
9571
|
+
});
|
|
9572
|
+
});
|
|
9573
|
+
}
|
|
9574
|
+
}
|
|
9575
|
+
_Wallet_account = new WeakMap(), _Wallet_network = new WeakMap(), _Wallet_blockchain = new WeakMap(), _Wallet_stream = new WeakMap(), _Wallet_subject = new WeakMap(), _Wallet_connected = new WeakMap(), _Wallet_enabled = new WeakMap(), _Wallet_instances = new WeakSet(), _Wallet_subscribe = function _Wallet_subscribe() {
|
|
9576
|
+
if (!globalThis.window)
|
|
9577
|
+
return;
|
|
9578
|
+
__classPrivateFieldGet(this, _Wallet_subject, "f").on((msg) => {
|
|
9579
|
+
switch (msg.type) {
|
|
9580
|
+
case MTypeTab.NEW_SLOT:
|
|
9581
|
+
__classPrivateFieldGet(this, _Wallet_blockchain, "f").period = msg.payload;
|
|
9582
|
+
break;
|
|
9583
|
+
case MTypeTab.LOCKED:
|
|
9584
|
+
__classPrivateFieldSet(this, _Wallet_enabled, msg.payload.enabled, "f");
|
|
9585
|
+
break;
|
|
9586
|
+
case MTypeTab.ACCOUNT_CHANGED:
|
|
9587
|
+
__classPrivateFieldGet(this, _Wallet_account, "f").base58 = msg.payload.base58;
|
|
9588
|
+
break;
|
|
9589
|
+
case MTypeTab.GET_DATA:
|
|
9590
|
+
__classPrivateFieldGet(this, _Wallet_blockchain, "f").period = msg.payload.period;
|
|
9591
|
+
__classPrivateFieldGet(this, _Wallet_account, "f").base58 = msg.payload.base58;
|
|
9592
|
+
__classPrivateFieldSet(this, _Wallet_enabled, msg.payload.enabled, "f");
|
|
9593
|
+
__classPrivateFieldSet(this, _Wallet_connected, msg.payload.connected, "f");
|
|
9594
|
+
__classPrivateFieldGet(this, _Wallet_network, "f").net = msg.payload.net;
|
|
9595
|
+
break;
|
|
9596
|
+
case MTypeTab.NETWORK_CHANGED:
|
|
9597
|
+
__classPrivateFieldGet(this, _Wallet_network, "f").net = msg.payload.net;
|
|
9598
|
+
__classPrivateFieldGet(this, _Wallet_blockchain, "f").period = msg.payload.period;
|
|
9599
|
+
break;
|
|
9600
|
+
}
|
|
9601
|
+
});
|
|
9602
|
+
};
|
|
9603
|
+
|
|
9604
|
+
var _Web3_handler, _Web3_provider;
|
|
9605
|
+
class Web3 {
|
|
9606
|
+
constructor() {
|
|
9607
|
+
_Web3_handler.set(this, new Handler());
|
|
9608
|
+
_Web3_provider.set(this, new ContentProvider(__classPrivateFieldGet(this, _Web3_handler, "f").stream, __classPrivateFieldGet(this, _Web3_handler, "f").subject));
|
|
9609
|
+
this.wallet = new Wallet(__classPrivateFieldGet(this, _Web3_handler, "f").stream, __classPrivateFieldGet(this, _Web3_handler, "f").subject);
|
|
9610
|
+
this.contract = new Contract(__classPrivateFieldGet(this, _Web3_provider, "f"), this.wallet);
|
|
9611
|
+
this.massa = new Massa(__classPrivateFieldGet(this, _Web3_provider, "f"), this.wallet);
|
|
9612
|
+
if (globalThis.window) {
|
|
9613
|
+
if (globalThis.window['bearby']) {
|
|
9614
|
+
throw new Error(WEB3_INSTANCE_CREATED);
|
|
9615
|
+
}
|
|
9616
|
+
try {
|
|
9617
|
+
__classPrivateFieldGet(this, _Web3_handler, "f").initialized();
|
|
9618
|
+
globalThis.window['bearby'] = Object.freeze(this);
|
|
9619
|
+
}
|
|
9620
|
+
catch {
|
|
9621
|
+
console.debug(AVAILABLE_ONLY_BROWSER);
|
|
9622
|
+
}
|
|
9623
|
+
}
|
|
9624
|
+
}
|
|
9625
|
+
}
|
|
9626
|
+
_Web3_handler = new WeakMap(), _Web3_provider = new WeakMap();
|
|
9627
|
+
|
|
9628
|
+
function main() {
|
|
9629
|
+
if (globalThis.window && globalThis.window['bearby']) {
|
|
9630
|
+
return globalThis.window['bearby'];
|
|
9631
|
+
}
|
|
9632
|
+
return new Web3();
|
|
9633
|
+
}
|
|
9634
|
+
const web3 = main();
|
|
9635
|
+
|
|
9636
|
+
|
|
9637
|
+
//# sourceMappingURL=index.js.map
|
|
9638
|
+
|
|
9639
|
+
|
|
6553
9640
|
/***/ })
|
|
6554
9641
|
|
|
6555
9642
|
/******/ });
|
|
@@ -6579,6 +9666,35 @@ exports.uid = uid;
|
|
|
6579
9666
|
/******/ }
|
|
6580
9667
|
/******/
|
|
6581
9668
|
/************************************************************************/
|
|
9669
|
+
/******/ /* webpack/runtime/define property getters */
|
|
9670
|
+
/******/ (() => {
|
|
9671
|
+
/******/ // define getter functions for harmony exports
|
|
9672
|
+
/******/ __webpack_require__.d = (exports, definition) => {
|
|
9673
|
+
/******/ for(var key in definition) {
|
|
9674
|
+
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
9675
|
+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
9676
|
+
/******/ }
|
|
9677
|
+
/******/ }
|
|
9678
|
+
/******/ };
|
|
9679
|
+
/******/ })();
|
|
9680
|
+
/******/
|
|
9681
|
+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
9682
|
+
/******/ (() => {
|
|
9683
|
+
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
9684
|
+
/******/ })();
|
|
9685
|
+
/******/
|
|
9686
|
+
/******/ /* webpack/runtime/make namespace object */
|
|
9687
|
+
/******/ (() => {
|
|
9688
|
+
/******/ // define __esModule on exports
|
|
9689
|
+
/******/ __webpack_require__.r = (exports) => {
|
|
9690
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
9691
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
9692
|
+
/******/ }
|
|
9693
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
9694
|
+
/******/ };
|
|
9695
|
+
/******/ })();
|
|
9696
|
+
/******/
|
|
9697
|
+
/************************************************************************/
|
|
6582
9698
|
/******/
|
|
6583
9699
|
/******/ // startup
|
|
6584
9700
|
/******/ // Load entry module and return exports
|