1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.u8aWrapBytes = exports.u8aUnwrapBytes = exports.u8aIsWrapped = exports.U8A_WRAP_POSTFIX = exports.U8A_WRAP_PREFIX = exports.U8A_WRAP_ETHEREUM = void 0;
|
4 | const concat_js_1 = require("./concat.js");
|
5 | const eq_js_1 = require("./eq.js");
|
6 | const toU8a_js_1 = require("./toU8a.js");
|
7 |
|
8 | exports.U8A_WRAP_ETHEREUM = (0, toU8a_js_1.u8aToU8a)('\x19Ethereum Signed Message:\n');
|
9 |
|
10 | exports.U8A_WRAP_PREFIX = (0, toU8a_js_1.u8aToU8a)('<Bytes>');
|
11 |
|
12 | exports.U8A_WRAP_POSTFIX = (0, toU8a_js_1.u8aToU8a)('</Bytes>');
|
13 | const WRAP_LEN = exports.U8A_WRAP_PREFIX.length + exports.U8A_WRAP_POSTFIX.length;
|
14 |
|
15 | function u8aIsWrapped(u8a, withEthereum) {
|
16 | return ((u8a.length >= WRAP_LEN &&
|
17 | (0, eq_js_1.u8aEq)(u8a.subarray(0, exports.U8A_WRAP_PREFIX.length), exports.U8A_WRAP_PREFIX) &&
|
18 | (0, eq_js_1.u8aEq)(u8a.slice(-exports.U8A_WRAP_POSTFIX.length), exports.U8A_WRAP_POSTFIX)) ||
|
19 | (withEthereum &&
|
20 | u8a.length >= exports.U8A_WRAP_ETHEREUM.length &&
|
21 | (0, eq_js_1.u8aEq)(u8a.subarray(0, exports.U8A_WRAP_ETHEREUM.length), exports.U8A_WRAP_ETHEREUM)));
|
22 | }
|
23 | exports.u8aIsWrapped = u8aIsWrapped;
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | function u8aUnwrapBytes(bytes) {
|
29 | const u8a = (0, toU8a_js_1.u8aToU8a)(bytes);
|
30 |
|
31 | return u8aIsWrapped(u8a, false)
|
32 | ? u8a.subarray(exports.U8A_WRAP_PREFIX.length, u8a.length - exports.U8A_WRAP_POSTFIX.length)
|
33 | : u8a;
|
34 | }
|
35 | exports.u8aUnwrapBytes = u8aUnwrapBytes;
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 | function u8aWrapBytes(bytes) {
|
44 | const u8a = (0, toU8a_js_1.u8aToU8a)(bytes);
|
45 | return u8aIsWrapped(u8a, true)
|
46 | ? u8a
|
47 | : (0, concat_js_1.u8aConcatStrict)([exports.U8A_WRAP_PREFIX, u8a, exports.U8A_WRAP_POSTFIX]);
|
48 | }
|
49 | exports.u8aWrapBytes = u8aWrapBytes;
|