this.me 3.0.27 → 3.0.29
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/README.md +264 -66
- package/dist/index.d.ts +0 -1
- package/dist/me.cjs +8 -0
- package/dist/me.es.d.ts +0 -4
- package/dist/me.es.js +407 -162
- package/dist/me.umd.js +2 -2
- package/dist/src/me.d.ts +84 -33
- package/package.json +6 -2
- package/dist/me.cjs.js +0 -8
- package/dist/src/tests.d.ts +0 -1
package/dist/me.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
var
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
var ce = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {};
|
|
2
|
+
function ae(E) {
|
|
3
|
+
return E && E.__esModule && Object.prototype.hasOwnProperty.call(E, "default") ? E.default : E;
|
|
4
4
|
}
|
|
5
|
-
var
|
|
5
|
+
var Ut = { exports: {} };
|
|
6
6
|
/**
|
|
7
7
|
* [js-sha3]{@link https://github.com/emn178/js-sha3}
|
|
8
8
|
*
|
|
@@ -12,14 +12,14 @@ var Pt = { exports: {} };
|
|
|
12
12
|
* @license MIT
|
|
13
13
|
*/
|
|
14
14
|
var Qt;
|
|
15
|
-
function
|
|
16
|
-
return Qt || (Qt = 1, (function(
|
|
15
|
+
function he() {
|
|
16
|
+
return Qt || (Qt = 1, (function(E) {
|
|
17
17
|
(function() {
|
|
18
|
-
var
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
for (var
|
|
18
|
+
var i = "input is invalid type", o = "finalize already called", l = typeof window == "object", a = l ? window : {};
|
|
19
|
+
a.JS_SHA3_NO_WINDOW && (l = !1);
|
|
20
|
+
var y = !l && typeof self == "object", b = !a.JS_SHA3_NO_NODE_JS && typeof process == "object" && process.versions && process.versions.node;
|
|
21
|
+
b ? a = ce : y && (a = self);
|
|
22
|
+
for (var P = !a.JS_SHA3_NO_COMMON_JS && !0 && E.exports, p = !a.JS_SHA3_NO_ARRAY_BUFFER && typeof ArrayBuffer < "u", d = "0123456789abcdef".split(""), B = [31, 7936, 2031616, 520093696], k = [4, 1024, 262144, 67108864], F = [1, 256, 65536, 16777216], w = [6, 1536, 393216, 100663296], v = [0, 8, 16, 24], _ = [
|
|
23
23
|
1,
|
|
24
24
|
0,
|
|
25
25
|
32898,
|
|
@@ -68,145 +68,145 @@ function ue() {
|
|
|
68
68
|
0,
|
|
69
69
|
2147516424,
|
|
70
70
|
2147483648
|
|
71
|
-
],
|
|
71
|
+
], j = [224, 256, 384, 512], C = [128, 256], A = ["hex", "buffer", "arrayBuffer", "array", "digest"], K = {
|
|
72
72
|
128: 168,
|
|
73
73
|
256: 136
|
|
74
|
-
},
|
|
74
|
+
}, ee = a.JS_SHA3_NO_NODE_JS || !Array.isArray ? function(t) {
|
|
75
75
|
return Object.prototype.toString.call(t) === "[object Array]";
|
|
76
|
-
} : Array.isArray,
|
|
76
|
+
} : Array.isArray, re = p && (a.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW || !ArrayBuffer.isView) ? function(t) {
|
|
77
77
|
return typeof t == "object" && t.buffer && t.buffer.constructor === ArrayBuffer;
|
|
78
|
-
} : ArrayBuffer.isView,
|
|
78
|
+
} : ArrayBuffer.isView, Vt = function(t) {
|
|
79
79
|
var e = typeof t;
|
|
80
80
|
if (e === "string")
|
|
81
81
|
return [t, !0];
|
|
82
82
|
if (e !== "object" || t === null)
|
|
83
|
-
throw new Error(
|
|
84
|
-
if (
|
|
83
|
+
throw new Error(i);
|
|
84
|
+
if (p && t.constructor === ArrayBuffer)
|
|
85
85
|
return [new Uint8Array(t), !1];
|
|
86
|
-
if (!
|
|
87
|
-
throw new Error(
|
|
86
|
+
if (!ee(t) && !re(t))
|
|
87
|
+
throw new Error(i);
|
|
88
88
|
return [t, !1];
|
|
89
|
-
},
|
|
90
|
-
return
|
|
91
|
-
},
|
|
89
|
+
}, mt = function(t) {
|
|
90
|
+
return Vt(t)[0].length === 0;
|
|
91
|
+
}, Jt = function(t) {
|
|
92
92
|
for (var e = [], r = 0; r < t.length; ++r)
|
|
93
93
|
e[r] = t[r];
|
|
94
94
|
return e;
|
|
95
|
-
},
|
|
95
|
+
}, Gt = function(t, e, r) {
|
|
96
96
|
return function(n) {
|
|
97
|
-
return new
|
|
97
|
+
return new g(t, e, t).update(n)[r]();
|
|
98
98
|
};
|
|
99
|
-
},
|
|
100
|
-
return function(n,
|
|
101
|
-
return new
|
|
99
|
+
}, Yt = function(t, e, r) {
|
|
100
|
+
return function(n, c) {
|
|
101
|
+
return new g(t, e, c).update(n)[r]();
|
|
102
102
|
};
|
|
103
103
|
}, qt = function(t, e, r) {
|
|
104
|
-
return function(n,
|
|
105
|
-
return
|
|
104
|
+
return function(n, c, h, u) {
|
|
105
|
+
return T["cshake" + t].update(n, c, h, u)[r]();
|
|
106
106
|
};
|
|
107
|
-
},
|
|
108
|
-
return function(n,
|
|
109
|
-
return
|
|
107
|
+
}, $t = function(t, e, r) {
|
|
108
|
+
return function(n, c, h, u) {
|
|
109
|
+
return T["kmac" + t].update(n, c, h, u)[r]();
|
|
110
110
|
};
|
|
111
111
|
}, I = function(t, e, r, n) {
|
|
112
|
-
for (var
|
|
113
|
-
var
|
|
114
|
-
t[
|
|
112
|
+
for (var c = 0; c < A.length; ++c) {
|
|
113
|
+
var h = A[c];
|
|
114
|
+
t[h] = e(r, n, h);
|
|
115
115
|
}
|
|
116
116
|
return t;
|
|
117
|
-
},
|
|
118
|
-
var r =
|
|
117
|
+
}, Lt = function(t, e) {
|
|
118
|
+
var r = Gt(t, e, "hex");
|
|
119
119
|
return r.create = function() {
|
|
120
|
-
return new
|
|
120
|
+
return new g(t, e, t);
|
|
121
121
|
}, r.update = function(n) {
|
|
122
122
|
return r.create().update(n);
|
|
123
|
-
}, I(r,
|
|
124
|
-
}, re = function(t, e) {
|
|
125
|
-
var r = Vt(t, e, "hex");
|
|
126
|
-
return r.create = function(n) {
|
|
127
|
-
return new l(t, e, n);
|
|
128
|
-
}, r.update = function(n, o) {
|
|
129
|
-
return r.create(o).update(n);
|
|
130
|
-
}, I(r, Vt, t, e);
|
|
123
|
+
}, I(r, Gt, t, e);
|
|
131
124
|
}, ne = function(t, e) {
|
|
132
|
-
var r =
|
|
133
|
-
return
|
|
134
|
-
return
|
|
135
|
-
},
|
|
136
|
-
return
|
|
137
|
-
}, I(
|
|
125
|
+
var r = Yt(t, e, "hex");
|
|
126
|
+
return r.create = function(n) {
|
|
127
|
+
return new g(t, e, n);
|
|
128
|
+
}, r.update = function(n, c) {
|
|
129
|
+
return r.create(c).update(n);
|
|
130
|
+
}, I(r, Yt, t, e);
|
|
138
131
|
}, oe = function(t, e) {
|
|
139
|
-
var r =
|
|
140
|
-
return n.create = function(
|
|
141
|
-
return new
|
|
142
|
-
}, n.update = function(
|
|
143
|
-
return n.create(
|
|
144
|
-
}, I(n,
|
|
145
|
-
},
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
132
|
+
var r = K[t], n = qt(t, e, "hex");
|
|
133
|
+
return n.create = function(c, h, u) {
|
|
134
|
+
return mt(h) && mt(u) ? T["shake" + t].create(c) : new g(t, e, c).bytepad([h, u], r);
|
|
135
|
+
}, n.update = function(c, h, u, f) {
|
|
136
|
+
return n.create(h, u, f).update(c);
|
|
137
|
+
}, I(n, qt, t, e);
|
|
138
|
+
}, ie = function(t, e) {
|
|
139
|
+
var r = K[t], n = $t(t, e, "hex");
|
|
140
|
+
return n.create = function(c, h, u) {
|
|
141
|
+
return new Wt(t, e, h).bytepad(["KMAC", u], r).bytepad([c], r);
|
|
142
|
+
}, n.update = function(c, h, u, f) {
|
|
143
|
+
return n.create(c, u, f).update(h);
|
|
144
|
+
}, I(n, $t, t, e);
|
|
145
|
+
}, Xt = [
|
|
146
|
+
{ name: "keccak", padding: F, bits: j, createMethod: Lt },
|
|
147
|
+
{ name: "sha3", padding: w, bits: j, createMethod: Lt },
|
|
148
|
+
{ name: "shake", padding: B, bits: C, createMethod: ne },
|
|
149
|
+
{ name: "cshake", padding: k, bits: C, createMethod: oe },
|
|
150
|
+
{ name: "kmac", padding: k, bits: C, createMethod: ie }
|
|
151
|
+
], T = {}, M = [], R = 0; R < Xt.length; ++R)
|
|
152
|
+
for (var N = Xt[R], V = N.bits, D = 0; D < V.length; ++D) {
|
|
153
|
+
var zt = N.name + "_" + V[D];
|
|
154
|
+
if (M.push(zt), T[zt] = N.createMethod(V[D], N.padding), N.name !== "sha3") {
|
|
155
|
+
var Zt = N.name + V[D];
|
|
156
|
+
M.push(Zt), T[Zt] = T[zt];
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function g(t, e, r) {
|
|
160
160
|
this.blocks = [], this.s = [], this.padding = e, this.outputBits = r, this.reset = !0, this.finalized = !1, this.block = 0, this.start = 0, this.blockCount = 1600 - (t << 1) >> 5, this.byteCount = this.blockCount << 2, this.outputBlocks = r >> 5, this.extraBytes = (r & 31) >> 3;
|
|
161
161
|
for (var n = 0; n < 50; ++n)
|
|
162
162
|
this.s[n] = 0;
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
g.prototype.update = function(t) {
|
|
165
165
|
if (this.finalized)
|
|
166
|
-
throw new Error(
|
|
167
|
-
var e =
|
|
166
|
+
throw new Error(o);
|
|
167
|
+
var e = Vt(t);
|
|
168
168
|
t = e[0];
|
|
169
|
-
for (var r = e[1], n = this.blocks,
|
|
169
|
+
for (var r = e[1], n = this.blocks, c = this.byteCount, h = t.length, u = this.blockCount, f = 0, S = this.s, s, x; f < h; ) {
|
|
170
170
|
if (this.reset)
|
|
171
|
-
for (this.reset = !1, n[0] = this.block,
|
|
172
|
-
n[
|
|
171
|
+
for (this.reset = !1, n[0] = this.block, s = 1; s < u + 1; ++s)
|
|
172
|
+
n[s] = 0;
|
|
173
173
|
if (r)
|
|
174
|
-
for (
|
|
175
|
-
|
|
174
|
+
for (s = this.start; f < h && s < c; ++f)
|
|
175
|
+
x = t.charCodeAt(f), x < 128 ? n[s >> 2] |= x << v[s++ & 3] : x < 2048 ? (n[s >> 2] |= (192 | x >> 6) << v[s++ & 3], n[s >> 2] |= (128 | x & 63) << v[s++ & 3]) : x < 55296 || x >= 57344 ? (n[s >> 2] |= (224 | x >> 12) << v[s++ & 3], n[s >> 2] |= (128 | x >> 6 & 63) << v[s++ & 3], n[s >> 2] |= (128 | x & 63) << v[s++ & 3]) : (x = 65536 + ((x & 1023) << 10 | t.charCodeAt(++f) & 1023), n[s >> 2] |= (240 | x >> 18) << v[s++ & 3], n[s >> 2] |= (128 | x >> 12 & 63) << v[s++ & 3], n[s >> 2] |= (128 | x >> 6 & 63) << v[s++ & 3], n[s >> 2] |= (128 | x & 63) << v[s++ & 3]);
|
|
176
176
|
else
|
|
177
|
-
for (
|
|
178
|
-
n[
|
|
179
|
-
if (this.lastByteIndex =
|
|
180
|
-
for (this.start =
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
for (s = this.start; f < h && s < c; ++f)
|
|
178
|
+
n[s >> 2] |= t[f] << v[s++ & 3];
|
|
179
|
+
if (this.lastByteIndex = s, s >= c) {
|
|
180
|
+
for (this.start = s - c, this.block = n[u], s = 0; s < u; ++s)
|
|
181
|
+
S[s] ^= n[s];
|
|
182
|
+
H(S), this.reset = !0;
|
|
183
183
|
} else
|
|
184
|
-
this.start =
|
|
184
|
+
this.start = s;
|
|
185
185
|
}
|
|
186
186
|
return this;
|
|
187
|
-
},
|
|
188
|
-
var r = t & 255, n = 1,
|
|
187
|
+
}, g.prototype.encode = function(t, e) {
|
|
188
|
+
var r = t & 255, n = 1, c = [r];
|
|
189
189
|
for (t = t >> 8, r = t & 255; r > 0; )
|
|
190
|
-
|
|
191
|
-
return e ?
|
|
192
|
-
},
|
|
193
|
-
var e =
|
|
190
|
+
c.unshift(r), t = t >> 8, r = t & 255, ++n;
|
|
191
|
+
return e ? c.push(n) : c.unshift(n), this.update(c), c.length;
|
|
192
|
+
}, g.prototype.encodeString = function(t) {
|
|
193
|
+
var e = Vt(t);
|
|
194
194
|
t = e[0];
|
|
195
|
-
var r = e[1], n = 0,
|
|
195
|
+
var r = e[1], n = 0, c = t.length;
|
|
196
196
|
if (r)
|
|
197
|
-
for (var
|
|
198
|
-
var u = t.charCodeAt(
|
|
199
|
-
u < 128 ? n += 1 : u < 2048 ? n += 2 : u < 55296 || u >= 57344 ? n += 3 : (u = 65536 + ((u & 1023) << 10 | t.charCodeAt(++
|
|
197
|
+
for (var h = 0; h < t.length; ++h) {
|
|
198
|
+
var u = t.charCodeAt(h);
|
|
199
|
+
u < 128 ? n += 1 : u < 2048 ? n += 2 : u < 55296 || u >= 57344 ? n += 3 : (u = 65536 + ((u & 1023) << 10 | t.charCodeAt(++h) & 1023), n += 4);
|
|
200
200
|
}
|
|
201
201
|
else
|
|
202
|
-
n =
|
|
202
|
+
n = c;
|
|
203
203
|
return n += this.encode(n * 8), this.update(t), n;
|
|
204
|
-
},
|
|
204
|
+
}, g.prototype.bytepad = function(t, e) {
|
|
205
205
|
for (var r = this.encode(e), n = 0; n < t.length; ++n)
|
|
206
206
|
r += this.encodeString(t[n]);
|
|
207
|
-
var
|
|
208
|
-
return
|
|
209
|
-
},
|
|
207
|
+
var c = (e - r % e) % e, h = [];
|
|
208
|
+
return h.length = c, this.update(h), this;
|
|
209
|
+
}, g.prototype.finalize = function() {
|
|
210
210
|
if (!this.finalized) {
|
|
211
211
|
this.finalized = !0;
|
|
212
212
|
var t = this.blocks, e = this.lastByteIndex, r = this.blockCount, n = this.s;
|
|
@@ -215,98 +215,343 @@ function ue() {
|
|
|
215
215
|
t[e] = 0;
|
|
216
216
|
for (t[r - 1] |= 2147483648, e = 0; e < r; ++e)
|
|
217
217
|
n[e] ^= t[e];
|
|
218
|
-
|
|
218
|
+
H(n);
|
|
219
219
|
}
|
|
220
|
-
},
|
|
220
|
+
}, g.prototype.toString = g.prototype.hex = function() {
|
|
221
221
|
this.finalize();
|
|
222
|
-
for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes,
|
|
223
|
-
for (
|
|
224
|
-
|
|
225
|
-
|
|
222
|
+
for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, c = 0, h = 0, u = "", f; h < r; ) {
|
|
223
|
+
for (c = 0; c < t && h < r; ++c, ++h)
|
|
224
|
+
f = e[c], u += d[f >> 4 & 15] + d[f & 15] + d[f >> 12 & 15] + d[f >> 8 & 15] + d[f >> 20 & 15] + d[f >> 16 & 15] + d[f >> 28 & 15] + d[f >> 24 & 15];
|
|
225
|
+
h % t === 0 && (e = Jt(e), H(e), c = 0);
|
|
226
226
|
}
|
|
227
|
-
return n && (
|
|
228
|
-
},
|
|
227
|
+
return n && (f = e[c], u += d[f >> 4 & 15] + d[f & 15], n > 1 && (u += d[f >> 12 & 15] + d[f >> 8 & 15]), n > 2 && (u += d[f >> 20 & 15] + d[f >> 16 & 15])), u;
|
|
228
|
+
}, g.prototype.arrayBuffer = function() {
|
|
229
229
|
this.finalize();
|
|
230
|
-
var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes,
|
|
231
|
-
n ?
|
|
232
|
-
for (var
|
|
233
|
-
for (
|
|
234
|
-
|
|
235
|
-
|
|
230
|
+
var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, c = 0, h = 0, u = this.outputBits >> 3, f;
|
|
231
|
+
n ? f = new ArrayBuffer(r + 1 << 2) : f = new ArrayBuffer(u);
|
|
232
|
+
for (var S = new Uint32Array(f); h < r; ) {
|
|
233
|
+
for (c = 0; c < t && h < r; ++c, ++h)
|
|
234
|
+
S[h] = e[c];
|
|
235
|
+
h % t === 0 && (e = Jt(e), H(e));
|
|
236
236
|
}
|
|
237
|
-
return n && (
|
|
238
|
-
},
|
|
237
|
+
return n && (S[h] = e[c], f = f.slice(0, u)), f;
|
|
238
|
+
}, g.prototype.buffer = g.prototype.arrayBuffer, g.prototype.digest = g.prototype.array = function() {
|
|
239
239
|
this.finalize();
|
|
240
|
-
for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes,
|
|
241
|
-
for (
|
|
242
|
-
|
|
243
|
-
|
|
240
|
+
for (var t = this.blockCount, e = this.s, r = this.outputBlocks, n = this.extraBytes, c = 0, h = 0, u = [], f, S; h < r; ) {
|
|
241
|
+
for (c = 0; c < t && h < r; ++c, ++h)
|
|
242
|
+
f = h << 2, S = e[c], u[f] = S & 255, u[f + 1] = S >> 8 & 255, u[f + 2] = S >> 16 & 255, u[f + 3] = S >> 24 & 255;
|
|
243
|
+
h % t === 0 && (e = Jt(e), H(e));
|
|
244
244
|
}
|
|
245
|
-
return n && (
|
|
245
|
+
return n && (f = h << 2, S = e[c], u[f] = S & 255, n > 1 && (u[f + 1] = S >> 8 & 255), n > 2 && (u[f + 2] = S >> 16 & 255)), u;
|
|
246
246
|
};
|
|
247
|
-
function
|
|
248
|
-
|
|
247
|
+
function Wt(t, e, r) {
|
|
248
|
+
g.call(this, t, e, r);
|
|
249
249
|
}
|
|
250
|
-
|
|
251
|
-
return this.encode(this.outputBits, !0),
|
|
250
|
+
Wt.prototype = new g(), Wt.prototype.finalize = function() {
|
|
251
|
+
return this.encode(this.outputBits, !0), g.prototype.finalize.call(this);
|
|
252
252
|
};
|
|
253
|
-
var
|
|
254
|
-
var e, r, n,
|
|
253
|
+
var H = function(t) {
|
|
254
|
+
var e, r, n, c, h, u, f, S, s, x, J, z, W, U, m, G, Y, q, $, L, X, Z, Q, tt, et, rt, nt, ot, it, ct, at, ht, ft, lt, ut, st, yt, dt, bt, pt, vt, xt, gt, St, Bt, Pt, kt, At, Ft, wt, _t, jt, Ct, Ot, Et, Tt, Rt, Kt, Nt, Mt, Dt, Ht, It;
|
|
255
255
|
for (n = 0; n < 48; n += 2)
|
|
256
|
-
|
|
256
|
+
c = t[0] ^ t[10] ^ t[20] ^ t[30] ^ t[40], h = t[1] ^ t[11] ^ t[21] ^ t[31] ^ t[41], u = t[2] ^ t[12] ^ t[22] ^ t[32] ^ t[42], f = t[3] ^ t[13] ^ t[23] ^ t[33] ^ t[43], S = t[4] ^ t[14] ^ t[24] ^ t[34] ^ t[44], s = t[5] ^ t[15] ^ t[25] ^ t[35] ^ t[45], x = t[6] ^ t[16] ^ t[26] ^ t[36] ^ t[46], J = t[7] ^ t[17] ^ t[27] ^ t[37] ^ t[47], z = t[8] ^ t[18] ^ t[28] ^ t[38] ^ t[48], W = t[9] ^ t[19] ^ t[29] ^ t[39] ^ t[49], e = z ^ (u << 1 | f >>> 31), r = W ^ (f << 1 | u >>> 31), t[0] ^= e, t[1] ^= r, t[10] ^= e, t[11] ^= r, t[20] ^= e, t[21] ^= r, t[30] ^= e, t[31] ^= r, t[40] ^= e, t[41] ^= r, e = c ^ (S << 1 | s >>> 31), r = h ^ (s << 1 | S >>> 31), t[2] ^= e, t[3] ^= r, t[12] ^= e, t[13] ^= r, t[22] ^= e, t[23] ^= r, t[32] ^= e, t[33] ^= r, t[42] ^= e, t[43] ^= r, e = u ^ (x << 1 | J >>> 31), r = f ^ (J << 1 | x >>> 31), t[4] ^= e, t[5] ^= r, t[14] ^= e, t[15] ^= r, t[24] ^= e, t[25] ^= r, t[34] ^= e, t[35] ^= r, t[44] ^= e, t[45] ^= r, e = S ^ (z << 1 | W >>> 31), r = s ^ (W << 1 | z >>> 31), t[6] ^= e, t[7] ^= r, t[16] ^= e, t[17] ^= r, t[26] ^= e, t[27] ^= r, t[36] ^= e, t[37] ^= r, t[46] ^= e, t[47] ^= r, e = x ^ (c << 1 | h >>> 31), r = J ^ (h << 1 | c >>> 31), t[8] ^= e, t[9] ^= r, t[18] ^= e, t[19] ^= r, t[28] ^= e, t[29] ^= r, t[38] ^= e, t[39] ^= r, t[48] ^= e, t[49] ^= r, U = t[0], m = t[1], Pt = t[11] << 4 | t[10] >>> 28, kt = t[10] << 4 | t[11] >>> 28, ot = t[20] << 3 | t[21] >>> 29, it = t[21] << 3 | t[20] >>> 29, Mt = t[31] << 9 | t[30] >>> 23, Dt = t[30] << 9 | t[31] >>> 23, xt = t[40] << 18 | t[41] >>> 14, gt = t[41] << 18 | t[40] >>> 14, lt = t[2] << 1 | t[3] >>> 31, ut = t[3] << 1 | t[2] >>> 31, G = t[13] << 12 | t[12] >>> 20, Y = t[12] << 12 | t[13] >>> 20, At = t[22] << 10 | t[23] >>> 22, Ft = t[23] << 10 | t[22] >>> 22, ct = t[33] << 13 | t[32] >>> 19, at = t[32] << 13 | t[33] >>> 19, Ht = t[42] << 2 | t[43] >>> 30, It = t[43] << 2 | t[42] >>> 30, Ot = t[5] << 30 | t[4] >>> 2, Et = t[4] << 30 | t[5] >>> 2, st = t[14] << 6 | t[15] >>> 26, yt = t[15] << 6 | t[14] >>> 26, q = t[25] << 11 | t[24] >>> 21, $ = t[24] << 11 | t[25] >>> 21, wt = t[34] << 15 | t[35] >>> 17, _t = t[35] << 15 | t[34] >>> 17, ht = t[45] << 29 | t[44] >>> 3, ft = t[44] << 29 | t[45] >>> 3, tt = t[6] << 28 | t[7] >>> 4, et = t[7] << 28 | t[6] >>> 4, Tt = t[17] << 23 | t[16] >>> 9, Rt = t[16] << 23 | t[17] >>> 9, dt = t[26] << 25 | t[27] >>> 7, bt = t[27] << 25 | t[26] >>> 7, L = t[36] << 21 | t[37] >>> 11, X = t[37] << 21 | t[36] >>> 11, jt = t[47] << 24 | t[46] >>> 8, Ct = t[46] << 24 | t[47] >>> 8, St = t[8] << 27 | t[9] >>> 5, Bt = t[9] << 27 | t[8] >>> 5, rt = t[18] << 20 | t[19] >>> 12, nt = t[19] << 20 | t[18] >>> 12, Kt = t[29] << 7 | t[28] >>> 25, Nt = t[28] << 7 | t[29] >>> 25, pt = t[38] << 8 | t[39] >>> 24, vt = t[39] << 8 | t[38] >>> 24, Z = t[48] << 14 | t[49] >>> 18, Q = t[49] << 14 | t[48] >>> 18, t[0] = U ^ ~G & q, t[1] = m ^ ~Y & $, t[10] = tt ^ ~rt & ot, t[11] = et ^ ~nt & it, t[20] = lt ^ ~st & dt, t[21] = ut ^ ~yt & bt, t[30] = St ^ ~Pt & At, t[31] = Bt ^ ~kt & Ft, t[40] = Ot ^ ~Tt & Kt, t[41] = Et ^ ~Rt & Nt, t[2] = G ^ ~q & L, t[3] = Y ^ ~$ & X, t[12] = rt ^ ~ot & ct, t[13] = nt ^ ~it & at, t[22] = st ^ ~dt & pt, t[23] = yt ^ ~bt & vt, t[32] = Pt ^ ~At & wt, t[33] = kt ^ ~Ft & _t, t[42] = Tt ^ ~Kt & Mt, t[43] = Rt ^ ~Nt & Dt, t[4] = q ^ ~L & Z, t[5] = $ ^ ~X & Q, t[14] = ot ^ ~ct & ht, t[15] = it ^ ~at & ft, t[24] = dt ^ ~pt & xt, t[25] = bt ^ ~vt & gt, t[34] = At ^ ~wt & jt, t[35] = Ft ^ ~_t & Ct, t[44] = Kt ^ ~Mt & Ht, t[45] = Nt ^ ~Dt & It, t[6] = L ^ ~Z & U, t[7] = X ^ ~Q & m, t[16] = ct ^ ~ht & tt, t[17] = at ^ ~ft & et, t[26] = pt ^ ~xt & lt, t[27] = vt ^ ~gt & ut, t[36] = wt ^ ~jt & St, t[37] = _t ^ ~Ct & Bt, t[46] = Mt ^ ~Ht & Ot, t[47] = Dt ^ ~It & Et, t[8] = Z ^ ~U & G, t[9] = Q ^ ~m & Y, t[18] = ht ^ ~tt & rt, t[19] = ft ^ ~et & nt, t[28] = xt ^ ~lt & st, t[29] = gt ^ ~ut & yt, t[38] = jt ^ ~St & Pt, t[39] = Ct ^ ~Bt & kt, t[48] = Ht ^ ~Ot & Tt, t[49] = It ^ ~Et & Rt, t[0] ^= _[n], t[1] ^= _[n + 1];
|
|
257
257
|
};
|
|
258
|
-
if (
|
|
259
|
-
|
|
258
|
+
if (P)
|
|
259
|
+
E.exports = T;
|
|
260
260
|
else
|
|
261
|
-
for (
|
|
262
|
-
|
|
261
|
+
for (R = 0; R < M.length; ++R)
|
|
262
|
+
a[M[R]] = T[M[R]];
|
|
263
263
|
})();
|
|
264
|
-
})(
|
|
264
|
+
})(Ut)), Ut.exports;
|
|
265
265
|
}
|
|
266
|
-
var fe =
|
|
267
|
-
const
|
|
268
|
-
class
|
|
269
|
-
constructor(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
return
|
|
266
|
+
var fe = he();
|
|
267
|
+
const le = /* @__PURE__ */ ae(fe), { keccak256: O } = le;
|
|
268
|
+
class te {
|
|
269
|
+
constructor(i, o) {
|
|
270
|
+
this.payload = {}, this.declarations = [], this.secrets = {}, this.branchVersions = {}, this.username = i, this.secret = o, this.identityRoot = "0x" + O(o), this.publicKey = "0x" + O("public:" + o), this.identityHash = "0x" + O(this.publicKey + this.username), this.secrets[""] = o;
|
|
271
|
+
const l = this.createProxy([]);
|
|
272
|
+
return Object.setPrototypeOf(l, te.prototype), Object.assign(l, this), l;
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Create a proxy bound to a specific path, e.g. ["wallet", "income"]
|
|
276
|
+
* The proxy itself is callable (function) and also expandable via property access.
|
|
277
|
+
*/
|
|
278
|
+
createProxy(i) {
|
|
279
|
+
const o = this, l = (...a) => o.handleCall(i, a);
|
|
280
|
+
return new Proxy(l, {
|
|
281
|
+
get(a, y) {
|
|
282
|
+
if (typeof y == "symbol") return a[y];
|
|
283
|
+
if (y === "secret") return o.createProxy([...i, String(y)]);
|
|
284
|
+
if (y in o) return o[y];
|
|
285
|
+
const b = [...i, String(y)];
|
|
286
|
+
return o.createProxy(b);
|
|
287
|
+
},
|
|
288
|
+
apply(a, y, b) {
|
|
289
|
+
return o.handleCall(i, b);
|
|
284
290
|
}
|
|
285
291
|
});
|
|
286
292
|
}
|
|
287
293
|
/**
|
|
288
|
-
*
|
|
294
|
+
* Handle a call at a given path.
|
|
295
|
+
* Examples:
|
|
296
|
+
* me.wallet.income(200) → set encrypted payload at wallet.income
|
|
297
|
+
* me.wallet.secret("abc123") → set secret for path "wallet"
|
|
298
|
+
* me.wallet.ptr() → return pointer object { __ptr: "wallet" }
|
|
289
299
|
*/
|
|
290
|
-
|
|
291
|
-
|
|
300
|
+
handleCall(i, o) {
|
|
301
|
+
if (i.length === 0) {
|
|
302
|
+
if (o.length === 1 && typeof o[0] == "string") {
|
|
303
|
+
const p = o[0].split(".").filter(Boolean);
|
|
304
|
+
return this.exportBranch(p.join("."));
|
|
305
|
+
}
|
|
306
|
+
return this.createProxy([]);
|
|
307
|
+
}
|
|
308
|
+
const l = i[i.length - 1];
|
|
309
|
+
if (l === "secret") {
|
|
310
|
+
const p = i.slice(0, -1), d = p.join("."), B = String(o[0] ?? "");
|
|
311
|
+
if (!B) return this.createProxy(p);
|
|
312
|
+
this.secrets[d] = B;
|
|
313
|
+
const k = "0x" + O(this.secret + d + "::secret-set");
|
|
314
|
+
return this.declarations.push({
|
|
315
|
+
key: d + ".secret",
|
|
316
|
+
value: "<secret-set>",
|
|
317
|
+
signature: k,
|
|
318
|
+
timestamp: Date.now()
|
|
319
|
+
}), this.createProxy(p);
|
|
320
|
+
}
|
|
321
|
+
if (l === "ptr")
|
|
322
|
+
return { __ptr: i.slice(0, -1).join(".") };
|
|
323
|
+
const a = i.join(".");
|
|
324
|
+
let y;
|
|
325
|
+
o.length === 0 ? y = void 0 : o.length === 1 ? y = o[0] : y = o, this.ensurePath(i, y);
|
|
326
|
+
const b = this.resolveSecret(i), P = "0x" + O(
|
|
327
|
+
b + a + JSON.stringify(y)
|
|
328
|
+
);
|
|
329
|
+
return this.declarations.push({
|
|
330
|
+
key: a,
|
|
331
|
+
value: y,
|
|
332
|
+
signature: P,
|
|
333
|
+
timestamp: Date.now()
|
|
334
|
+
}), this.createProxy(i);
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Secret scope resolution with path:
|
|
338
|
+
* - Find the most specific path that has a secret.
|
|
339
|
+
* - Return both the secret and the path at which it was defined.
|
|
340
|
+
* - If none, fall back to root secret with empty path.
|
|
341
|
+
*/
|
|
342
|
+
resolveSecretWithPath(i) {
|
|
343
|
+
for (let o = i.length; o >= 0; o--) {
|
|
344
|
+
const l = i.slice(0, o).join(".");
|
|
345
|
+
if (this.secrets[l])
|
|
346
|
+
return { secret: this.secrets[l], secretPath: i.slice(0, o) };
|
|
347
|
+
}
|
|
348
|
+
return { secret: this.secret, secretPath: [] };
|
|
349
|
+
}
|
|
350
|
+
/**
|
|
351
|
+
* Backwards-compatible helper: only return the secret string.
|
|
352
|
+
*/
|
|
353
|
+
resolveSecret(i) {
|
|
354
|
+
return this.resolveSecretWithPath(i).secret;
|
|
292
355
|
}
|
|
293
356
|
/**
|
|
294
|
-
*
|
|
357
|
+
* Encrypt and store the value at the given path inside `payload`.
|
|
358
|
+
*
|
|
359
|
+
* If there is a non-root secret defined for some ancestor path P of `path`,
|
|
360
|
+
* we treat that ancestor path P as the "branch root" and store the ENTIRE
|
|
361
|
+
* subtree under P as ONE encrypted blob at that location.
|
|
362
|
+
*
|
|
363
|
+
* This means that to re-enter that channel you need both:
|
|
364
|
+
* - the full expression for P, and
|
|
365
|
+
* - the secret used at P.
|
|
366
|
+
*/
|
|
367
|
+
ensurePath(i, o) {
|
|
368
|
+
const { secret: l, secretPath: a } = this.resolveSecretWithPath(i), y = a.join("."), b = O(l);
|
|
369
|
+
if (a.length > 0) {
|
|
370
|
+
let k = {};
|
|
371
|
+
const F = this.branchVersions[y]?.[b], w = this.getSubPayload(a);
|
|
372
|
+
if (F) {
|
|
373
|
+
const A = this.decryptForPath(a, F);
|
|
374
|
+
A && typeof A == "object" && (k = A);
|
|
375
|
+
} else if (typeof w == "string") {
|
|
376
|
+
const A = this.decryptForPath(a, w);
|
|
377
|
+
A && typeof A == "object" && (k = A);
|
|
378
|
+
} else w && typeof w == "object" && (k = w);
|
|
379
|
+
const v = i.slice(a.length);
|
|
380
|
+
let _ = k;
|
|
381
|
+
for (let A = 0; A < v.length - 1; A++) {
|
|
382
|
+
const K = v[A];
|
|
383
|
+
(!_[K] || typeof _[K] != "object") && (_[K] = {}), _ = _[K];
|
|
384
|
+
}
|
|
385
|
+
const j = v[v.length - 1];
|
|
386
|
+
_[j] = o;
|
|
387
|
+
const C = this.encryptForPath(a, k);
|
|
388
|
+
this.branchVersions[y] || (this.branchVersions[y] = {}), this.branchVersions[y][b] = C, this.writeBranchBlob(a, C);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
const p = this.encryptForPath(i, o);
|
|
392
|
+
let d = this.payload;
|
|
393
|
+
for (let k = 0; k < i.length - 1; k++) {
|
|
394
|
+
const F = i[k];
|
|
395
|
+
(!d[F] || typeof d[F] != "object") && (d[F] = {}), d = d[F];
|
|
396
|
+
}
|
|
397
|
+
const B = i[i.length - 1];
|
|
398
|
+
d[B] = p;
|
|
399
|
+
}
|
|
400
|
+
/**
|
|
401
|
+
* Set a value at a nested path inside `payload`.
|
|
402
|
+
*/
|
|
403
|
+
setSubPayload(i, o) {
|
|
404
|
+
if (i.length === 0) {
|
|
405
|
+
this.payload = o;
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
let l = this.payload;
|
|
409
|
+
for (let y = 0; y < i.length - 1; y++) {
|
|
410
|
+
const b = i[y];
|
|
411
|
+
(!l[b] || typeof l[b] != "object") && (l[b] = {}), l = l[b];
|
|
412
|
+
}
|
|
413
|
+
const a = i[i.length - 1];
|
|
414
|
+
l[a] = o;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Find the nearest ancestor path that represents an encrypted branch blob.
|
|
418
|
+
*/
|
|
419
|
+
findNearestBranchAncestor(i) {
|
|
420
|
+
for (let o = i.length - 1; o >= 1; o--) {
|
|
421
|
+
const l = i.slice(0, o), a = l.join(".");
|
|
422
|
+
if (this.branchVersions[a])
|
|
423
|
+
return { path: l, secret: this.resolveSecret(l) };
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
/**
|
|
428
|
+
* Write an encrypted branch blob while preserving any encrypted ancestor branches.
|
|
429
|
+
*/
|
|
430
|
+
writeBranchBlob(i, o) {
|
|
431
|
+
let l = i, a = o;
|
|
432
|
+
for (; ; ) {
|
|
433
|
+
const y = this.findNearestBranchAncestor(l);
|
|
434
|
+
if (!y) {
|
|
435
|
+
this.setSubPayload(l, a);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const { path: b, secret: P } = y, p = b.join("."), d = O(P), B = this.getSubPayload(b), k = this.branchVersions[p]?.[d] ?? (typeof B == "string" ? B : void 0);
|
|
439
|
+
let F = {};
|
|
440
|
+
if (k) {
|
|
441
|
+
const j = this.decryptForPath(b, k);
|
|
442
|
+
j && typeof j == "object" && (F = j);
|
|
443
|
+
}
|
|
444
|
+
const w = l.slice(b.length);
|
|
445
|
+
let v = F;
|
|
446
|
+
for (let j = 0; j < w.length - 1; j++) {
|
|
447
|
+
const C = w[j];
|
|
448
|
+
(!v[C] || typeof v[C] != "object") && (v[C] = {}), v = v[C];
|
|
449
|
+
}
|
|
450
|
+
v[w[w.length - 1]] = a;
|
|
451
|
+
const _ = this.encryptForPath(b, F);
|
|
452
|
+
this.branchVersions[p] || (this.branchVersions[p] = {}), this.branchVersions[p][d] = _, l = b, a = _;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
getSubPayload(i) {
|
|
456
|
+
let o = this.payload;
|
|
457
|
+
for (const l of i) {
|
|
458
|
+
if (!o || typeof o != "object") return;
|
|
459
|
+
o = o[l];
|
|
460
|
+
}
|
|
461
|
+
return o;
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Recursively decrypt a node of the encrypted payload tree.
|
|
465
|
+
*/
|
|
466
|
+
decryptTree(i, o) {
|
|
467
|
+
if (o == null) return o;
|
|
468
|
+
if (typeof o == "string") {
|
|
469
|
+
if (!this.isHexString(o)) return o;
|
|
470
|
+
const a = this.decryptForPath(i, o);
|
|
471
|
+
return a === null ? o : a;
|
|
472
|
+
}
|
|
473
|
+
if (typeof o != "object")
|
|
474
|
+
return o;
|
|
475
|
+
const l = Array.isArray(o) ? [] : {};
|
|
476
|
+
for (const a of Object.keys(o)) {
|
|
477
|
+
const y = [...i, a];
|
|
478
|
+
l[a] = this.decryptTree(y, o[a]);
|
|
479
|
+
}
|
|
480
|
+
return l;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Encrypt a value (object or primitive) using the secret resolved for the given path.
|
|
484
|
+
* Produces a hex string compatible with decryptForPath().
|
|
485
|
+
*/
|
|
486
|
+
encryptForPath(i, o) {
|
|
487
|
+
const l = this.resolveSecret(i), a = JSON.stringify(o), y = new TextEncoder().encode(a), b = O(l + ":" + i.join(".")), P = this.asciiToBytes(b), p = new Uint8Array(y.length);
|
|
488
|
+
for (let B = 0; B < y.length; B++)
|
|
489
|
+
p[B] = y[B] ^ P[B % P.length];
|
|
490
|
+
let d = "";
|
|
491
|
+
for (let B = 0; B < p.length; B++)
|
|
492
|
+
d += p[B].toString(16).padStart(2, "0");
|
|
493
|
+
return d;
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* Decrypt a single encrypted blob using the secret resolved for the given path.
|
|
497
|
+
*/
|
|
498
|
+
decryptForPath(i, o) {
|
|
499
|
+
const l = this.resolveSecret(i);
|
|
500
|
+
try {
|
|
501
|
+
const a = this.hexToBytes(o), y = O(l + ":" + i.join(".")), b = this.asciiToBytes(y), P = new Uint8Array(a.length);
|
|
502
|
+
for (let d = 0; d < a.length; d++)
|
|
503
|
+
P[d] = a[d] ^ b[d % b.length];
|
|
504
|
+
const p = new TextDecoder().decode(P);
|
|
505
|
+
return JSON.parse(p);
|
|
506
|
+
} catch {
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
asciiToBytes(i) {
|
|
511
|
+
return new TextEncoder().encode(i);
|
|
512
|
+
}
|
|
513
|
+
hexToBytes(i) {
|
|
514
|
+
const o = i.startsWith("0x") ? i.slice(2) : i, l = new Uint8Array(o.length / 2);
|
|
515
|
+
for (let a = 0; a < l.length; a++)
|
|
516
|
+
l[a] = parseInt(o.substr(a * 2, 2), 16);
|
|
517
|
+
return l;
|
|
518
|
+
}
|
|
519
|
+
isHexString(i) {
|
|
520
|
+
const o = i.startsWith("0x") ? i.slice(2) : i;
|
|
521
|
+
return o.length > 0 && o.length % 2 === 0 && /^[0-9a-fA-F]+$/.test(o);
|
|
522
|
+
}
|
|
523
|
+
/**
|
|
524
|
+
* Export the encrypted payload and declaration metadata.
|
|
295
525
|
*/
|
|
296
526
|
export() {
|
|
297
527
|
return {
|
|
298
528
|
identityRoot: this.identityRoot,
|
|
299
529
|
publicKey: this.publicKey,
|
|
300
|
-
namespace: this.namespace,
|
|
301
530
|
identityHash: this.identityHash,
|
|
302
|
-
declarations: this.declarations
|
|
531
|
+
declarations: this.declarations,
|
|
532
|
+
payload: this.payload
|
|
303
533
|
};
|
|
304
534
|
}
|
|
305
|
-
|
|
306
|
-
|
|
535
|
+
/**
|
|
536
|
+
* Export and decrypt a specific branch using the currently active secret
|
|
537
|
+
* resolved for that path.
|
|
538
|
+
*/
|
|
539
|
+
exportBranch(i) {
|
|
540
|
+
const o = i ? i.split(".").filter(Boolean) : [], l = o.join("."), a = this.resolveSecret(o), y = O(a), b = this.branchVersions[l]?.[y];
|
|
541
|
+
if (b) {
|
|
542
|
+
const p = this.decryptForPath(o, b);
|
|
543
|
+
return this.decryptTree(o, p);
|
|
544
|
+
}
|
|
545
|
+
const P = this.getSubPayload(o);
|
|
546
|
+
if (P !== void 0) {
|
|
547
|
+
if (typeof P == "string") {
|
|
548
|
+
const p = this.decryptForPath(o, P);
|
|
549
|
+
return this.decryptTree(o, p);
|
|
550
|
+
}
|
|
551
|
+
return this.decryptTree(o, P);
|
|
552
|
+
}
|
|
307
553
|
}
|
|
308
554
|
}
|
|
309
555
|
export {
|
|
310
|
-
|
|
311
|
-
he as default
|
|
556
|
+
te as ME
|
|
312
557
|
};
|