@aeternity/aepp-sdk 8.2.1 → 10.0.0
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/CHANGELOG.md +216 -337
- package/README.md +16 -9
- package/dist/aepp-sdk.browser-script.js +1 -1
- package/dist/aepp-sdk.browser-script.js.LICENSE.txt +0 -9
- package/dist/aepp-sdk.browser-script.js.map +1 -1
- package/dist/aepp-sdk.browser.js +1 -1
- package/dist/aepp-sdk.browser.js.map +1 -1
- package/dist/aepp-sdk.js +1 -1
- package/dist/aepp-sdk.js.map +1 -1
- package/es/account/base.js +36 -120
- package/es/account/base.js.map +1 -1
- package/es/account/memory.js +17 -19
- package/es/account/memory.js.map +1 -1
- package/es/account/multiple.js +79 -156
- package/es/account/multiple.js.map +1 -1
- package/es/ae/aens.js +205 -626
- package/es/ae/aens.js.map +1 -1
- package/es/ae/contract.js +114 -918
- package/es/ae/contract.js.map +1 -1
- package/es/ae/index.js +90 -250
- package/es/ae/index.js.map +1 -1
- package/es/ae/oracle.js +136 -504
- package/es/ae/oracle.js.map +1 -1
- package/es/ae/universal.js.map +1 -1
- package/es/chain/index.js +12 -27
- package/es/chain/index.js.map +1 -1
- package/es/chain/node.js +289 -1020
- package/es/chain/node.js.map +1 -1
- package/es/channel/handlers.js +597 -1086
- package/es/channel/handlers.js.map +1 -1
- package/es/channel/index.js +238 -465
- package/es/channel/index.js.map +1 -1
- package/es/channel/internal.js +129 -301
- package/es/channel/internal.js.map +1 -1
- package/es/contract/aci/index.js +328 -495
- package/es/contract/aci/index.js.map +1 -1
- package/es/contract/aci/transformation.js +35 -711
- package/es/contract/aci/transformation.js.map +1 -1
- package/es/contract/compiler.js +131 -203
- package/es/contract/compiler.js.map +1 -1
- package/es/contract/ga/helpers.js +17 -122
- package/es/contract/ga/helpers.js.map +1 -1
- package/es/contract/ga/index.js +108 -249
- package/es/contract/ga/index.js.map +1 -1
- package/es/contract/index.js +7 -3
- package/es/contract/index.js.map +1 -1
- package/es/index.js +3 -3
- package/es/index.js.map +1 -1
- package/es/node-pool/index.js +57 -74
- package/es/node-pool/index.js.map +1 -1
- package/es/node.js +65 -161
- package/es/node.js.map +1 -1
- package/es/other.d.ts +1 -1
- package/es/tx/builder/helpers.js +62 -115
- package/es/tx/builder/helpers.js.map +1 -1
- package/es/tx/builder/index.js +218 -309
- package/es/tx/builder/index.js.map +1 -1
- package/es/tx/builder/schema.js +586 -573
- package/es/tx/builder/schema.js.map +1 -1
- package/es/tx/index.js +102 -13
- package/es/tx/index.js.map +1 -1
- package/es/tx/tx-object.js +114 -138
- package/es/tx/tx-object.js.map +1 -1
- package/es/tx/tx.js +810 -1586
- package/es/tx/tx.js.map +1 -1
- package/es/tx/validator.js +191 -426
- package/es/tx/validator.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js +20 -23
- package/es/utils/aepp-wallet-communication/connection/browser-runtime.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js +53 -80
- package/es/utils/aepp-wallet-communication/connection/browser-window-message.js.map +1 -1
- package/es/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/es/utils/aepp-wallet-communication/connection/index.js.map +1 -1
- package/es/utils/aepp-wallet-communication/content-script-bridge.js +24 -19
- package/es/utils/aepp-wallet-communication/content-script-bridge.js.map +1 -1
- package/es/utils/aepp-wallet-communication/helpers.js +60 -105
- package/es/utils/aepp-wallet-communication/helpers.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js +191 -514
- package/es/utils/aepp-wallet-communication/rpc/aepp-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js +78 -93
- package/es/utils/aepp-wallet-communication/rpc/rpc-client.js.map +1 -1
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js +381 -613
- package/es/utils/aepp-wallet-communication/rpc/wallet-rpc.js.map +1 -1
- package/es/utils/aepp-wallet-communication/schema.js +43 -39
- package/es/utils/aepp-wallet-communication/schema.js.map +1 -1
- package/es/utils/aepp-wallet-communication/wallet-detector.js +32 -58
- package/es/utils/aepp-wallet-communication/wallet-detector.js.map +1 -1
- package/es/utils/amount-formatter.js +41 -61
- package/es/utils/amount-formatter.js.map +1 -1
- package/es/utils/async-init.js +28 -64
- package/es/utils/async-init.js.map +1 -1
- package/es/utils/bignumber.js +3 -11
- package/es/utils/bignumber.js.map +1 -1
- package/es/utils/bytes.js +5 -9
- package/es/utils/bytes.js.map +1 -1
- package/es/utils/crypto.js +41 -106
- package/es/utils/crypto.js.map +1 -1
- package/es/utils/hd-wallet.js +45 -81
- package/es/utils/hd-wallet.js.map +1 -1
- package/es/utils/json-big.js +16 -49
- package/es/utils/json-big.js.map +1 -1
- package/es/utils/keystore.js +81 -246
- package/es/utils/keystore.js.map +1 -1
- package/es/utils/mptree.js +88 -134
- package/es/utils/mptree.js.map +1 -1
- package/es/utils/other.js +10 -60
- package/es/utils/other.js.map +1 -1
- package/es/utils/semver-satisfies.js +9 -28
- package/es/utils/semver-satisfies.js.map +1 -1
- package/es/utils/string.js +4 -13
- package/es/utils/string.js.map +1 -1
- package/es/utils/swagger.js +87 -224
- package/es/utils/swagger.js.map +1 -1
- package/package.json +51 -44
- package/src/account/base.js +11 -10
- package/src/account/multiple.js +24 -18
- package/src/ae/aens.js +64 -61
- package/src/ae/contract.js +71 -248
- package/src/ae/index.js +34 -9
- package/src/ae/oracle.js +30 -22
- package/src/ae/universal.js +3 -1
- package/src/chain/index.js +10 -16
- package/src/chain/node.js +38 -38
- package/src/channel/handlers.js +10 -4
- package/src/channel/index.js +44 -20
- package/src/contract/aci/index.js +234 -112
- package/src/contract/aci/transformation.js +30 -422
- package/src/contract/compiler.js +50 -5
- package/src/contract/ga/helpers.js +6 -14
- package/src/contract/ga/index.js +28 -28
- package/src/contract/index.js +6 -2
- package/src/index.js +4 -4
- package/src/node-pool/index.js +24 -13
- package/src/node.js +29 -30
- package/src/tx/builder/helpers.js +31 -56
- package/src/tx/builder/index.js +67 -28
- package/src/tx/builder/schema.js +79 -121
- package/src/tx/index.js +101 -12
- package/src/tx/tx-object.js +25 -8
- package/src/tx/tx.js +229 -150
- package/src/tx/validator.js +134 -202
- package/src/utils/aepp-wallet-communication/connection/browser-runtime.js +3 -2
- package/src/utils/aepp-wallet-communication/connection/browser-window-message.js +25 -7
- package/src/utils/aepp-wallet-communication/connection/index.js +2 -1
- package/src/utils/aepp-wallet-communication/content-script-bridge.js +10 -4
- package/src/utils/aepp-wallet-communication/helpers.js +4 -2
- package/src/utils/aepp-wallet-communication/rpc/aepp-rpc.js +33 -12
- package/src/utils/aepp-wallet-communication/rpc/rpc-client.js +9 -5
- package/src/utils/aepp-wallet-communication/rpc/wallet-rpc.js +59 -29
- package/src/utils/aepp-wallet-communication/schema.js +1 -3
- package/src/utils/aepp-wallet-communication/wallet-detector.js +4 -1
- package/src/utils/amount-formatter.ts +1 -1
- package/src/utils/bignumber.ts +2 -1
- package/src/utils/crypto.js +4 -68
- package/src/utils/keystore.js +10 -2
- package/src/utils/other.ts +1 -1
- package/src/utils/semver-satisfies.ts +1 -1
- package/src/utils/swagger.js +22 -10
- package/src/contract/aci/helpers.js +0 -140
package/es/utils/mptree.js
CHANGED
|
@@ -1,15 +1,3 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
2
|
-
import _classCallCheck from "@babel/runtime-corejs3/helpers/classCallCheck";
|
|
3
|
-
import _createClass from "@babel/runtime-corejs3/helpers/createClass";
|
|
4
|
-
import _Object$fromEntries from "@babel/runtime-corejs3/core-js-stable/object/from-entries";
|
|
5
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
6
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
|
7
|
-
import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
|
|
8
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
9
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
10
|
-
import _parseInt from "@babel/runtime-corejs3/core-js-stable/parse-int";
|
|
11
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
12
|
-
|
|
13
1
|
/*
|
|
14
2
|
* ISC License (ISC)
|
|
15
3
|
* Copyright (c) 2021 aeternity developers
|
|
@@ -36,53 +24,41 @@ var NodeType;
|
|
|
36
24
|
NodeType[NodeType["Leaf"] = 2] = "Leaf";
|
|
37
25
|
})(NodeType || (NodeType = {}));
|
|
38
26
|
|
|
39
|
-
|
|
27
|
+
export default class MPTree {
|
|
28
|
+
static nodeHash(node) {
|
|
29
|
+
return Buffer.from(hash(rlpEncode(node))).toString('hex');
|
|
30
|
+
}
|
|
40
31
|
/**
|
|
41
32
|
* Deserialize Merkle Patricia Tree
|
|
42
33
|
* @rtype (binary: Array) => MPTree
|
|
43
34
|
* @param {Array} binary - Binary
|
|
44
35
|
* @return {MPTree} Merkle Patricia Tree
|
|
45
36
|
*/
|
|
46
|
-
function MPTree(binary) {
|
|
47
|
-
var _context,
|
|
48
|
-
_context2,
|
|
49
|
-
_this = this;
|
|
50
37
|
|
|
51
|
-
_classCallCheck(this, MPTree);
|
|
52
38
|
|
|
39
|
+
constructor(binary) {
|
|
53
40
|
this.rootHash = binary[0].toString('hex');
|
|
54
|
-
this.nodes =
|
|
55
|
-
return [node[0].toString('hex'), node[1]];
|
|
56
|
-
}));
|
|
41
|
+
this.nodes = Object.fromEntries(binary[1].map(node => [node[0].toString('hex'), node[1]]));
|
|
57
42
|
if (this.nodes[this.rootHash] === undefined) throw new Error('Can\'t find a node by root hash');
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var _context3, _context4;
|
|
61
|
-
|
|
62
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
63
|
-
key = _ref2[0],
|
|
64
|
-
node = _ref2[1];
|
|
65
|
-
|
|
43
|
+
Object.entries(this.nodes).forEach(_ref => {
|
|
44
|
+
let [key, node] = _ref;
|
|
66
45
|
if (MPTree.nodeHash(node) !== key) throw new Error('Node hash is not equal to provided one');
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
46
|
+
const {
|
|
47
|
+
type,
|
|
48
|
+
payload
|
|
49
|
+
} = MPTree.parseNode(node);
|
|
71
50
|
|
|
72
51
|
switch (type) {
|
|
73
52
|
case NodeType.Branch:
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
})).call(_context3, function (n) {
|
|
77
|
-
if (_this.nodes[n.toString('hex')] === undefined) {
|
|
53
|
+
payload.slice(0, 16).filter(n => n.length).forEach(n => {
|
|
54
|
+
if (this.nodes[n.toString('hex')] === undefined) {
|
|
78
55
|
throw new Error('Can\'t find a node by hash in branch node');
|
|
79
56
|
}
|
|
80
57
|
});
|
|
81
|
-
|
|
82
58
|
break;
|
|
83
59
|
|
|
84
60
|
case NodeType.Extension:
|
|
85
|
-
if (
|
|
61
|
+
if (this.nodes[payload[0].toString('hex')] === undefined) {
|
|
86
62
|
throw new Error('Can\'t find a node by hash in extension node');
|
|
87
63
|
}
|
|
88
64
|
|
|
@@ -90,109 +66,87 @@ var MPTree = /*#__PURE__*/function () {
|
|
|
90
66
|
});
|
|
91
67
|
}
|
|
92
68
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
return [Buffer.from(mptHash, 'hex'), value];
|
|
115
|
-
})];
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Retrieve value from Merkle Patricia Tree
|
|
119
|
-
* @rtype (key: String) => Buffer
|
|
120
|
-
* @param {String} key - The key of the element to retrieve
|
|
121
|
-
* @return {Buffer} Value associated to the specified key
|
|
122
|
-
*/
|
|
123
|
-
|
|
124
|
-
}, {
|
|
125
|
-
key: "get",
|
|
126
|
-
value: function get(key) {
|
|
127
|
-
var searchFrom = this.rootHash;
|
|
128
|
-
|
|
129
|
-
while (true) {
|
|
130
|
-
var _MPTree$parseNode2 = MPTree.parseNode(this.nodes[searchFrom]),
|
|
131
|
-
type = _MPTree$parseNode2.type,
|
|
132
|
-
payload = _MPTree$parseNode2.payload,
|
|
133
|
-
path = _MPTree$parseNode2.path;
|
|
134
|
-
|
|
135
|
-
switch (type) {
|
|
136
|
-
case NodeType.Branch:
|
|
137
|
-
if (key.length === 0) return payload[16];
|
|
138
|
-
searchFrom = payload[_parseInt(key[0], 16)].toString('hex');
|
|
139
|
-
key = key.substr(1);
|
|
140
|
-
break;
|
|
141
|
-
|
|
142
|
-
case NodeType.Extension:
|
|
143
|
-
if (key.substr(0, path === null || path === void 0 ? void 0 : path.length) !== path) return undefined;
|
|
144
|
-
searchFrom = payload[0].toString('hex');
|
|
145
|
-
key = key.substr(path.length);
|
|
146
|
-
break;
|
|
147
|
-
|
|
148
|
-
case NodeType.Leaf:
|
|
149
|
-
if (path !== key) return undefined;
|
|
150
|
-
return payload[0];
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}], [{
|
|
155
|
-
key: "nodeHash",
|
|
156
|
-
value: function nodeHash(node) {
|
|
157
|
-
return Buffer.from(hash(rlpEncode(node))).toString('hex');
|
|
158
|
-
}
|
|
159
|
-
}, {
|
|
160
|
-
key: "parseNode",
|
|
161
|
-
value: function parseNode(node) {
|
|
162
|
-
switch (node.length) {
|
|
163
|
-
case 17:
|
|
69
|
+
isEqual(tree) {
|
|
70
|
+
return this.rootHash === tree.rootHash;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static parseNode(node) {
|
|
74
|
+
switch (node.length) {
|
|
75
|
+
case 17:
|
|
76
|
+
return {
|
|
77
|
+
type: NodeType.Branch,
|
|
78
|
+
payload: node,
|
|
79
|
+
path: null
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
case 2:
|
|
83
|
+
{
|
|
84
|
+
const path = node[0].toString('hex');
|
|
85
|
+
const nibble = parseInt(path[0], 16);
|
|
86
|
+
if (nibble > 3) throw new Error(`Unknown path nibble: ${nibble}`);
|
|
87
|
+
const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
88
|
+
const slice = [0, 2].includes(nibble) ? 2 : 1;
|
|
164
89
|
return {
|
|
165
|
-
type
|
|
166
|
-
payload: node,
|
|
167
|
-
path:
|
|
90
|
+
type,
|
|
91
|
+
payload: [node[1]],
|
|
92
|
+
path: path.slice(slice)
|
|
168
93
|
};
|
|
94
|
+
}
|
|
169
95
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
96
|
+
default:
|
|
97
|
+
throw new Error(`Unknown node length: ${node.length}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Serialize Merkle Patricia Tree
|
|
102
|
+
* @rtype () => Array
|
|
103
|
+
* @return {Array} Binary
|
|
104
|
+
*/
|
|
173
105
|
|
|
174
|
-
var path = node[0].toString('hex');
|
|
175
106
|
|
|
176
|
-
|
|
107
|
+
serialize() {
|
|
108
|
+
return [Buffer.from(this.rootHash, 'hex'), Object.entries(this.nodes).map(_ref2 => {
|
|
109
|
+
let [mptHash, value] = _ref2;
|
|
110
|
+
return [Buffer.from(mptHash, 'hex'), value];
|
|
111
|
+
})];
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Retrieve value from Merkle Patricia Tree
|
|
115
|
+
* @rtype (key: String) => Buffer
|
|
116
|
+
* @param {String} key - The key of the element to retrieve
|
|
117
|
+
* @return {Buffer} Value associated to the specified key
|
|
118
|
+
*/
|
|
177
119
|
|
|
178
|
-
if (nibble > 3) throw new Error("Unknown path nibble: ".concat(nibble));
|
|
179
|
-
var type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf;
|
|
180
|
-
var slice = _includesInstanceProperty(_context6 = [0, 2]).call(_context6, nibble) ? 2 : 1;
|
|
181
|
-
return {
|
|
182
|
-
type: type,
|
|
183
|
-
payload: [node[1]],
|
|
184
|
-
path: _sliceInstanceProperty(path).call(path, slice)
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
120
|
|
|
188
|
-
|
|
189
|
-
|
|
121
|
+
get(key) {
|
|
122
|
+
let searchFrom = this.rootHash;
|
|
123
|
+
|
|
124
|
+
while (true) {
|
|
125
|
+
const {
|
|
126
|
+
type,
|
|
127
|
+
payload,
|
|
128
|
+
path
|
|
129
|
+
} = MPTree.parseNode(this.nodes[searchFrom]);
|
|
130
|
+
|
|
131
|
+
switch (type) {
|
|
132
|
+
case NodeType.Branch:
|
|
133
|
+
if (key.length === 0) return payload[16];
|
|
134
|
+
searchFrom = payload[parseInt(key[0], 16)].toString('hex');
|
|
135
|
+
key = key.substr(1);
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case NodeType.Extension:
|
|
139
|
+
if (key.substr(0, path === null || path === void 0 ? void 0 : path.length) !== path) return undefined;
|
|
140
|
+
searchFrom = payload[0].toString('hex');
|
|
141
|
+
key = key.substr(path.length);
|
|
142
|
+
break;
|
|
143
|
+
|
|
144
|
+
case NodeType.Leaf:
|
|
145
|
+
if (path !== key) return undefined;
|
|
146
|
+
return payload[0];
|
|
190
147
|
}
|
|
191
148
|
}
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
return MPTree;
|
|
195
|
-
}();
|
|
149
|
+
}
|
|
196
150
|
|
|
197
|
-
|
|
151
|
+
}
|
|
198
152
|
//# sourceMappingURL=mptree.js.map
|
package/es/utils/mptree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/mptree.ts"],"names":["encode","rlpEncode","hash","NodeType","MPTree","
|
|
1
|
+
{"version":3,"sources":["../../src/utils/mptree.ts"],"names":["encode","rlpEncode","hash","NodeType","MPTree","nodeHash","node","Buffer","from","toString","constructor","binary","rootHash","nodes","Object","fromEntries","map","undefined","Error","entries","forEach","key","type","payload","parseNode","Branch","slice","filter","n","length","Extension","isEqual","tree","path","nibble","parseInt","Leaf","includes","serialize","mptHash","value","get","searchFrom","substr"],"mappings":"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","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright (c) 2021 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\nimport { encode as rlpEncode } from 'rlp'\nimport type { Input } from 'rlp'\nimport { hash } from './crypto-ts'\n\nenum NodeType {\n Branch,\n Extension,\n Leaf\n}\n\nexport type MPTreeBinary = [Buffer, Array<[Buffer, Buffer[]]>]\n\nexport default class MPTree {\n private readonly rootHash: string\n private readonly nodes: { [key: string]: Buffer[] }\n\n private static nodeHash (node: Input): string {\n return Buffer.from(hash(rlpEncode(node))).toString('hex')\n }\n\n /**\n * Deserialize Merkle Patricia Tree\n * @rtype (binary: Array) => MPTree\n * @param {Array} binary - Binary\n * @return {MPTree} Merkle Patricia Tree\n */\n constructor (binary: MPTreeBinary) {\n this.rootHash = binary[0].toString('hex')\n this.nodes = Object.fromEntries(\n binary[1].map((node) => [node[0].toString('hex'), node[1]])\n )\n\n if (this.nodes[this.rootHash] === undefined) throw new Error('Can\\'t find a node by root hash')\n Object.entries(this.nodes).forEach(([key, node]) => {\n if (MPTree.nodeHash(node) !== key) throw new Error('Node hash is not equal to provided one')\n const { type, payload } = MPTree.parseNode(node)\n switch (type) {\n case NodeType.Branch:\n payload\n .slice(0, 16)\n .filter(n => n.length)\n .forEach((n) => {\n if (this.nodes[n.toString('hex')] === undefined) {\n throw new Error('Can\\'t find a node by hash in branch node')\n }\n })\n break\n case NodeType.Extension:\n if (this.nodes[payload[0].toString('hex')] === undefined) {\n throw new Error('Can\\'t find a node by hash in extension node')\n }\n }\n })\n }\n\n isEqual (tree: MPTree): boolean {\n return this.rootHash === tree.rootHash\n }\n\n private static parseNode (node: Buffer[]): { type: NodeType, payload: Buffer[], path: string | null } {\n switch (node.length) {\n case 17:\n return { type: NodeType.Branch, payload: node, path: null }\n case 2: {\n const path = node[0].toString('hex')\n const nibble = parseInt(path[0], 16)\n if (nibble > 3) throw new Error(`Unknown path nibble: ${nibble}`)\n const type = nibble <= 1 ? NodeType.Extension : NodeType.Leaf\n const slice = [0, 2].includes(nibble) ? 2 : 1\n return { type, payload: [node[1]], path: path.slice(slice) }\n }\n default:\n throw new Error(`Unknown node length: ${node.length}`)\n }\n }\n\n /**\n * Serialize Merkle Patricia Tree\n * @rtype () => Array\n * @return {Array} Binary\n */\n serialize (): MPTreeBinary {\n return [\n Buffer.from(this.rootHash, 'hex'),\n Object.entries(this.nodes).map(([mptHash, value]) => ([\n Buffer.from(mptHash, 'hex'),\n value\n ]))\n ]\n }\n\n /**\n * Retrieve value from Merkle Patricia Tree\n * @rtype (key: String) => Buffer\n * @param {String} key - The key of the element to retrieve\n * @return {Buffer} Value associated to the specified key\n */\n get (key: string): Buffer | undefined {\n let searchFrom = this.rootHash\n while (true) {\n const { type, payload, path } = MPTree.parseNode(this.nodes[searchFrom])\n switch (type) {\n case NodeType.Branch:\n if (key.length === 0) return payload[16]\n searchFrom = payload[parseInt(key[0], 16)].toString('hex')\n key = key.substr(1)\n break\n case NodeType.Extension:\n if (key.substr(0, path?.length) !== path) return undefined\n searchFrom = payload[0].toString('hex')\n key = key.substr(path.length)\n break\n case NodeType.Leaf:\n if (path !== key) return undefined\n return payload[0]\n }\n }\n }\n}\n"],"file":"mptree.js"}
|
package/es/utils/other.js
CHANGED
|
@@ -1,52 +1,7 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime-corejs3/helpers/slicedToArray";
|
|
2
|
-
import _typeof from "@babel/runtime-corejs3/helpers/typeof";
|
|
3
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
|
|
4
|
-
import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
|
|
5
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
|
6
|
-
import _setTimeout from "@babel/runtime-corejs3/core-js-stable/set-timeout";
|
|
7
|
-
import _Object$fromEntries from "@babel/runtime-corejs3/core-js-stable/object/from-entries";
|
|
8
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
9
|
-
import _Object$entries from "@babel/runtime-corejs3/core-js-stable/object/entries";
|
|
10
|
-
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
11
|
-
import _Array$isArray from "@babel/runtime-corejs3/core-js-stable/array/is-array";
|
|
12
|
-
import _bindInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/bind";
|
|
13
1
|
import { snakeToPascal, pascalToSnake } from './string';
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
while (1) {
|
|
18
|
-
switch (_context.prev = _context.next) {
|
|
19
|
-
case 0:
|
|
20
|
-
_context.next = 2;
|
|
21
|
-
return new _Promise(function (resolve) {
|
|
22
|
-
return _setTimeout(resolve, duration);
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
case 2:
|
|
26
|
-
return _context.abrupt("return", _context.sent);
|
|
27
|
-
|
|
28
|
-
case 3:
|
|
29
|
-
case "end":
|
|
30
|
-
return _context.stop();
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}, _callee);
|
|
34
|
-
}));
|
|
35
|
-
|
|
36
|
-
return function pause(_x) {
|
|
37
|
-
return _ref.apply(this, arguments);
|
|
38
|
-
};
|
|
39
|
-
}();
|
|
40
|
-
export var mapObject = function mapObject(object, fn) {
|
|
41
|
-
var _context2;
|
|
42
|
-
|
|
43
|
-
return _Object$fromEntries(_mapInstanceProperty(_context2 = _Object$entries(object)).call(_context2, fn));
|
|
44
|
-
};
|
|
45
|
-
export var filterObject = function filterObject(object, fn) {
|
|
46
|
-
var _context3;
|
|
47
|
-
|
|
48
|
-
return _Object$fromEntries(_filterInstanceProperty(_context3 = _Object$entries(object)).call(_context3, fn));
|
|
49
|
-
};
|
|
2
|
+
export const pause = async duration => await new Promise(resolve => setTimeout(resolve, duration));
|
|
3
|
+
export const mapObject = (object, fn) => Object.fromEntries(Object.entries(object).map(fn));
|
|
4
|
+
export const filterObject = (object, fn) => Object.fromEntries(Object.entries(object).filter(fn));
|
|
50
5
|
/**
|
|
51
6
|
* Key traversal metafunction
|
|
52
7
|
* @static
|
|
@@ -57,16 +12,11 @@ export var filterObject = function filterObject(object, fn) {
|
|
|
57
12
|
* @return {Object} Transformed object
|
|
58
13
|
*/
|
|
59
14
|
|
|
60
|
-
export
|
|
61
|
-
if (
|
|
62
|
-
if (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return mapObject(object, function (_ref2) {
|
|
66
|
-
var _ref3 = _slicedToArray(_ref2, 2),
|
|
67
|
-
key = _ref3[0],
|
|
68
|
-
value = _ref3[1];
|
|
69
|
-
|
|
15
|
+
export const traverseKeys = (fn, object) => {
|
|
16
|
+
if (typeof object !== 'object' || object === null) return object;
|
|
17
|
+
if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i));
|
|
18
|
+
return mapObject(object, _ref => {
|
|
19
|
+
let [key, value] = _ref;
|
|
70
20
|
return [fn(key), traverseKeys(fn, value)];
|
|
71
21
|
});
|
|
72
22
|
};
|
|
@@ -79,7 +29,7 @@ export var traverseKeys = function traverseKeys(fn, object) {
|
|
|
79
29
|
* @see pascalToSnake
|
|
80
30
|
*/
|
|
81
31
|
|
|
82
|
-
export
|
|
32
|
+
export const snakizeKeys = traverseKeys.bind(null, pascalToSnake);
|
|
83
33
|
/**
|
|
84
34
|
* PascalCase key traversal
|
|
85
35
|
* @static
|
|
@@ -89,5 +39,5 @@ export var snakizeKeys = _bindInstanceProperty(traverseKeys).call(traverseKeys,
|
|
|
89
39
|
* @see snakeToPascal
|
|
90
40
|
*/
|
|
91
41
|
|
|
92
|
-
export
|
|
42
|
+
export const pascalizeKeys = traverseKeys.bind(null, snakeToPascal);
|
|
93
43
|
//# sourceMappingURL=other.js.map
|
package/es/utils/other.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/other.ts"],"names":["snakeToPascal","pascalToSnake","pause","duration","resolve","mapObject","object","fn","filterObject","traverseKeys","i","key","value","snakizeKeys","pascalizeKeys"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/utils/other.ts"],"names":["snakeToPascal","pascalToSnake","pause","duration","Promise","resolve","setTimeout","mapObject","object","fn","Object","fromEntries","entries","map","filterObject","filter","traverseKeys","Array","isArray","i","key","value","snakizeKeys","bind","pascalizeKeys"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,aAAxB,QAA6C,UAA7C;AAEA,OAAO,MAAMC,KAAK,GAAG,MAAOC,QAAP,IACnB,MAAM,IAAIC,OAAJ,CAAYC,OAAO,IAAIC,UAAU,CAACD,OAAD,EAAUF,QAAV,CAAjC,CADD;AAGP,OAAO,MAAMI,SAAS,GAAG,CACvBC,MADuB,EAEvBC,EAFuB,KAGZC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeJ,MAAf,EAAuBK,GAAvB,CAA2BJ,EAA3B,CAAnB,CAHN;AAKP,OAAO,MAAMK,YAAY,GAAG,CAC1BN,MAD0B,EAE1BC,EAF0B,KAGfC,MAAM,CAACC,WAAP,CAAmBD,MAAM,CAACE,OAAP,CAAeJ,MAAf,EAAuBO,MAAvB,CAA8BN,EAA9B,CAAnB,CAHN;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMO,YAAY,GAAG,CAACP,EAAD,EAAeD,MAAf,KAAoC;AAC9D,MAAI,OAAOA,MAAP,KAAkB,QAAlB,IAA8BA,MAAM,KAAK,IAA7C,EAAmD,OAAOA,MAAP;AACnD,MAAIS,KAAK,CAACC,OAAN,CAAcV,MAAd,CAAJ,EAA2B,OAAOA,MAAM,CAACK,GAAP,CAAWM,CAAC,IAAIH,YAAY,CAACP,EAAD,EAAKU,CAAL,CAA5B,CAAP;AAC3B,SAAOZ,SAAS,CAACC,MAAD,EAAS;AAAA,QAAC,CAACY,GAAD,EAAMC,KAAN,CAAD;AAAA,WAAiC,CACxDZ,EAAE,CAACW,GAAD,CADsD,EAC/CJ,YAAY,CAACP,EAAD,EAAKY,KAAL,CADmC,CAAjC;AAAA,GAAT,CAAhB;AAGD,CANM;AAQP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,WAAW,GAAGN,YAAY,CAACO,IAAb,CAAkB,IAAlB,EAAwBtB,aAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMuB,aAAa,GAAGR,YAAY,CAACO,IAAb,CAAkB,IAAlB,EAAwBvB,aAAxB,CAAtB","sourcesContent":["import { snakeToPascal, pascalToSnake } from './string'\n\nexport const pause = async (duration: number): Promise<void> =>\n await new Promise(resolve => setTimeout(resolve, duration))\n\nexport const mapObject = (\n object: object,\n fn: (value: [string, any], index: number, array: Array<[string, any]>) => Array<[string, any]>\n): object => Object.fromEntries(Object.entries(object).map(fn))\n\nexport const filterObject = (\n object: object,\n fn: (value: [string, any], index: number, array: Array<[string, any]>) => boolean\n): object => Object.fromEntries(Object.entries(object).filter(fn))\n\n/**\n * Key traversal metafunction\n * @static\n * @function\n * @rtype (fn: (s: String) => String) => (o: Object) => Object\n * @param {Function} fn - Key transformation function\n * @param {Object} object - Object to traverse\n * @return {Object} Transformed object\n */\nexport const traverseKeys = (fn: Function, object: any): any => {\n if (typeof object !== 'object' || object === null) return object\n if (Array.isArray(object)) return object.map(i => traverseKeys(fn, i))\n return mapObject(object, ([key, value]: [string, any]) => [\n fn(key), traverseKeys(fn, value)\n ])\n}\n\n/**\n * snake_case key traversal\n * @static\n * @rtype (o: Object) => Object\n * @param {Object} object - Object to traverse\n * @return {Object} Transformed object\n * @see pascalToSnake\n */\nexport const snakizeKeys = traverseKeys.bind(null, pascalToSnake)\n\n/**\n * PascalCase key traversal\n * @static\n * @rtype (o: Object) => Object\n * @param {Object} object - Object to traverse\n * @return {Object} Transformed object\n * @see snakeToPascal\n */\nexport const pascalizeKeys = traverseKeys.bind(null, snakeToPascal)\n"],"file":"other.js"}
|
|
@@ -1,35 +1,16 @@
|
|
|
1
|
-
import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray";
|
|
2
|
-
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
|
3
|
-
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
|
4
|
-
import _reduceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reduce";
|
|
5
|
-
import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
|
|
6
1
|
export default function (version, geVersion, ltVersion) {
|
|
7
|
-
|
|
2
|
+
const getComponents = v => v.split(/[-+]/)[0].split('.').map(i => +i);
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
const versionComponents = getComponents(version);
|
|
5
|
+
const geComponents = getComponents(geVersion);
|
|
6
|
+
const ltComponents = getComponents(ltVersion);
|
|
7
|
+
const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1;
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
return +i;
|
|
14
|
-
});
|
|
15
|
-
};
|
|
9
|
+
const componentsToNumber = components => components.reverse().reduce((acc, n, idx) => acc + n * Math.pow(base, idx), 0);
|
|
16
10
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var base = Math.max.apply(Math, _concatInstanceProperty(_context2 = _toConsumableArray(versionComponents)).call(_context2, _toConsumableArray(geComponents), _toConsumableArray(ltComponents))) + 1;
|
|
21
|
-
|
|
22
|
-
var componentsToNumber = function componentsToNumber(components) {
|
|
23
|
-
var _context3;
|
|
24
|
-
|
|
25
|
-
return _reduceInstanceProperty(_context3 = _reverseInstanceProperty(components).call(components)).call(_context3, function (acc, n, idx) {
|
|
26
|
-
return acc + n * Math.pow(base, idx);
|
|
27
|
-
}, 0);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
var vNumber = componentsToNumber(versionComponents);
|
|
31
|
-
var geNumber = componentsToNumber(geComponents);
|
|
32
|
-
var ltNumber = componentsToNumber(ltComponents);
|
|
11
|
+
const vNumber = componentsToNumber(versionComponents);
|
|
12
|
+
const geNumber = componentsToNumber(geComponents);
|
|
13
|
+
const ltNumber = componentsToNumber(ltComponents);
|
|
33
14
|
return vNumber >= geNumber && vNumber < ltNumber;
|
|
34
15
|
}
|
|
35
16
|
//# sourceMappingURL=semver-satisfies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/semver-satisfies.ts"],"names":["version","geVersion","ltVersion","getComponents","v","split","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","acc","n","idx","pow","vNumber","geNumber","ltNumber"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/utils/semver-satisfies.ts"],"names":["version","geVersion","ltVersion","getComponents","v","split","map","i","versionComponents","geComponents","ltComponents","base","Math","max","componentsToNumber","components","reverse","reduce","acc","n","idx","pow","vNumber","geNumber","ltNumber"],"mappings":"AAAA,eAAe,UAAUA,OAAV,EAA2BC,SAA3B,EAA8CC,SAA9C,EAA0E;AACvF,QAAMC,aAAa,GAAIC,CAAD,IAAyBA,CAAC,CAC7CC,KAD4C,CACtC,MADsC,EAC9B,CAD8B,EAC3BA,KAD2B,CACrB,GADqB,EAChBC,GADgB,CACZC,CAAC,IAAI,CAACA,CADM,CAA/C;;AAGA,QAAMC,iBAAiB,GAAGL,aAAa,CAACH,OAAD,CAAvC;AACA,QAAMS,YAAY,GAAGN,aAAa,CAACF,SAAD,CAAlC;AACA,QAAMS,YAAY,GAAGP,aAAa,CAACD,SAAD,CAAlC;AAEA,QAAMS,IAAI,GAAGC,IAAI,CAACC,GAAL,CAAS,GAAGL,iBAAZ,EAA+B,GAAGC,YAAlC,EAAgD,GAAGC,YAAnD,IAAmE,CAAhF;;AACA,QAAMI,kBAAkB,GAAIC,UAAD,IAAkCA,UAAU,CAACC,OAAX,GAC1DC,MAD0D,CACnD,CAACC,GAAD,EAAMC,CAAN,EAASC,GAAT,KAAiBF,GAAG,GAAGC,CAAC,GAAGP,IAAI,CAACS,GAAL,CAASV,IAAT,EAAeS,GAAf,CADwB,EACH,CADG,CAA7D;;AAGA,QAAME,OAAO,GAAGR,kBAAkB,CAACN,iBAAD,CAAlC;AACA,QAAMe,QAAQ,GAAGT,kBAAkB,CAACL,YAAD,CAAnC;AACA,QAAMe,QAAQ,GAAGV,kBAAkB,CAACJ,YAAD,CAAnC;AACA,SAAOY,OAAO,IAAIC,QAAX,IAAuBD,OAAO,GAAGE,QAAxC;AACD","sourcesContent":["export default function (version: string, geVersion: string, ltVersion: string): boolean {\n const getComponents = (v: string): number[] => v\n .split(/[-+]/)[0].split('.').map(i => +i)\n\n const versionComponents = getComponents(version)\n const geComponents = getComponents(geVersion)\n const ltComponents = getComponents(ltVersion)\n\n const base = Math.max(...versionComponents, ...geComponents, ...ltComponents) + 1\n const componentsToNumber = (components: number[]): number => components.reverse()\n .reduce((acc, n, idx) => acc + n * Math.pow(base, idx), 0)\n\n const vNumber = componentsToNumber(versionComponents)\n const geNumber = componentsToNumber(geComponents)\n const ltNumber = componentsToNumber(ltComponents)\n return vNumber >= geNumber && vNumber < ltNumber\n}\n"],"file":"semver-satisfies.js"}
|
package/es/utils/string.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import _indexOfInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/index-of";
|
|
2
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
|
3
|
-
|
|
4
1
|
/*
|
|
5
2
|
* ISC License (ISC)
|
|
6
3
|
* Copyright 2018 aeternity developers
|
|
@@ -25,9 +22,7 @@ import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instan
|
|
|
25
22
|
* @return {String} Converted string
|
|
26
23
|
*/
|
|
27
24
|
export function snakeToPascal(s) {
|
|
28
|
-
return s.replace(/_./g,
|
|
29
|
-
return match[1].toUpperCase();
|
|
30
|
-
});
|
|
25
|
+
return s.replace(/_./g, match => match[1].toUpperCase());
|
|
31
26
|
}
|
|
32
27
|
/**
|
|
33
28
|
* Convert string from PascalCase to snake_case
|
|
@@ -37,9 +32,7 @@ export function snakeToPascal(s) {
|
|
|
37
32
|
*/
|
|
38
33
|
|
|
39
34
|
export function pascalToSnake(s) {
|
|
40
|
-
return s.replace(/[A-Z]/g,
|
|
41
|
-
return "_".concat(match.toLowerCase());
|
|
42
|
-
});
|
|
35
|
+
return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`);
|
|
43
36
|
}
|
|
44
37
|
/**
|
|
45
38
|
* Check whether a string is valid hex.
|
|
@@ -58,9 +51,7 @@ export function isHex(str) {
|
|
|
58
51
|
|
|
59
52
|
export function isBase64(str) {
|
|
60
53
|
if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
return index === -1 || /={1,2}/.test(_sliceInstanceProperty(str).call(str, index));
|
|
54
|
+
const index = str.indexOf('=');
|
|
55
|
+
return index === -1 || /={1,2}/.test(str.slice(index));
|
|
65
56
|
}
|
|
66
57
|
//# sourceMappingURL=string.js.map
|
package/es/utils/string.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/string.ts"],"names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../src/utils/string.ts"],"names":["snakeToPascal","s","replace","match","toUpperCase","pascalToSnake","toLowerCase","isHex","str","length","test","isBase64","index","indexOf","slice"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,aAAT,CAAwBC,CAAxB,EAA2C;AAChD,SAAOA,CAAC,CAACC,OAAF,CAAU,KAAV,EAAiBC,KAAK,IAAIA,KAAK,CAAC,CAAD,CAAL,CAASC,WAAT,EAA1B,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,aAAT,CAAwBJ,CAAxB,EAA2C;AAChD,SAAOA,CAAC,CAACC,OAAF,CAAU,QAAV,EAAoBC,KAAK,IAAK,IAAGA,KAAK,CAACG,WAAN,EAAoB,EAArD,CAAP;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,KAAT,CAAgBC,GAAhB,EAAsC;AAC3C,SAAOA,GAAG,CAACC,MAAJ,GAAa,CAAb,KAAmB,CAAnB,IAAwB,eAAeC,IAAf,CAAoBF,GAApB,CAA/B;AACD;AAED;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASG,QAAT,CAAmBH,GAAnB,EAAyC;AAC9C,MAAIA,GAAG,CAACC,MAAJ,GAAa,CAAb,GAAiB,CAAjB,IAAsB,gBAAgBC,IAAhB,CAAqBF,GAArB,CAA1B,EAAqD,OAAO,KAAP;AACrD,QAAMI,KAAK,GAAGJ,GAAG,CAACK,OAAJ,CAAY,GAAZ,CAAd;AACA,SAAOD,KAAK,KAAK,CAAC,CAAX,IAAgB,SAASF,IAAT,CAAcF,GAAG,CAACM,KAAJ,CAAUF,KAAV,CAAd,CAAvB;AACD","sourcesContent":["/*\n * ISC License (ISC)\n * Copyright 2018 aeternity developers\n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH\n * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY\n * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,\n * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM\n * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR\n * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR\n * PERFORMANCE OF THIS SOFTWARE.\n */\n\n/**\n * Convert string from snake_case to PascalCase\n * @rtype (s: String) => String\n * @param {String} s - String to convert\n * @return {String} Converted string\n */\nexport function snakeToPascal (s: string): string {\n return s.replace(/_./g, match => match[1].toUpperCase())\n}\n\n/**\n * Convert string from PascalCase to snake_case\n * @rtype (s: String) => String\n * @param {String} s - String to convert\n * @return {String} Converted string\n */\nexport function pascalToSnake (s: string): string {\n return s.replace(/[A-Z]/g, match => `_${match.toLowerCase()}`)\n}\n\n/**\n * Check whether a string is valid hex.\n * @param {string} str String to validate.\n * @return {boolean} True if the string is valid hex, false otherwise.\n */\nexport function isHex (str: string): boolean {\n return str.length % 2 === 0 && /^[0-9a-f]+$/i.test(str)\n}\n\n/**\n * Check whether a string is valid base-64.\n * @param {string} str String to validate.\n * @return {boolean} True if the string is valid base-64, false otherwise.\n */\nexport function isBase64 (str: string): boolean {\n if (str.length % 4 > 0 || /[^0-9a-z+/=]/i.test(str)) return false\n const index = str.indexOf('=')\n return index === -1 || /={1,2}/.test(str.slice(index))\n}\n"],"file":"string.js"}
|