@leofcoin/chain 1.10.13 → 1.10.15
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/exports/beacon-envelope.js +2 -2
- package/exports/beacon-epoch.js +1 -1
- package/exports/beacon-lifecycle.js +2 -2
- package/exports/beacon-round.js +1 -1
- package/exports/beacon.js +1 -1
- package/exports/browser/beacon-envelope.js +79 -3
- package/exports/browser/beacon-epoch.js +2 -1
- package/exports/browser/beacon-lifecycle.js +3 -2
- package/exports/browser/beacon-round.js +2 -1
- package/exports/browser/beacon-wire.js +3 -3
- package/exports/browser/beacon.js +3 -2
- package/exports/browser/{browser-DvU1xNFS-sdlKNCJc.js → browser-DvU1xNFS-DmmNUdE-.js} +4 -4
- package/exports/browser/{proposal.proto-BcUgd885.js → browser-crypto-B9N9KlL4.js} +35 -6
- package/exports/browser/chain.js +16 -295
- package/exports/browser/{client-B-jyclOB-CsNYfj4Z.js → client-DDC8C510-3uaB70KL.js} +36 -12
- package/exports/browser/connection-monitor-GPztgSSJ.js +454 -0
- package/exports/browser/hkdf-CnZvwpZ9.js +222 -0
- package/exports/browser/{index-Bxr5Iztg-C6xBk0rK.js → index-Bxr5Iztg-WbFIosyf.js} +4 -4
- package/exports/browser/{index-CFBGfpG1.js → index-Ccn5sExe.js} +1 -2
- package/exports/browser/{messages-FMRAS8QX-CvlZBzy5.js → messages-DH0tgNM9-C2CtyLsf.js} +4 -4
- package/exports/browser/{node-browser-xlqSBOaN.js → node-browser-BYi7D_oa.js} +6 -6
- package/exports/browser/node-browser.js +4 -4
- package/exports/browser/sha2-piimb6xL.js +614 -0
- package/exports/browser/{weierstrass-C-jX_jly.js → weierstrass-Q0QND1ZT.js} +1 -1
- package/exports/browser/workers/machine-worker.js +412 -135
- package/exports/chain.js +13 -291
- package/exports/connection-monitor.js +324 -0
- package/exports/node.js +7 -0
- package/exports/workers/machine-worker.js +412 -135
- package/package.json +8 -4
- package/exports/browser/browser-CWeoyGUw-BabtHowB.js +0 -57
- package/exports/browser/constants-Cv0p224A.js +0 -130
- package/exports/browser/hkdf-DhdhLAAv.js +0 -147
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import { a as ahash, b as abytes, c as clean, d as aexists, e as aoutput, f as anumber } from './sha2-piimb6xL.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* HMAC: RFC2104 message authentication code.
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Internal class for HMAC.
|
|
9
|
+
* Accepts any byte key, although RFC 2104 §3 recommends keys at least
|
|
10
|
+
* `HashLen` bytes long.
|
|
11
|
+
*/
|
|
12
|
+
class _HMAC {
|
|
13
|
+
oHash;
|
|
14
|
+
iHash;
|
|
15
|
+
blockLen;
|
|
16
|
+
outputLen;
|
|
17
|
+
canXOF = false;
|
|
18
|
+
finished = false;
|
|
19
|
+
destroyed = false;
|
|
20
|
+
constructor(hash, key) {
|
|
21
|
+
ahash(hash);
|
|
22
|
+
abytes(key, undefined, 'key');
|
|
23
|
+
this.iHash = hash.create();
|
|
24
|
+
if (typeof this.iHash.update !== 'function')
|
|
25
|
+
throw new Error('expected Hash instance');
|
|
26
|
+
this.blockLen = this.iHash.blockLen;
|
|
27
|
+
this.outputLen = this.iHash.outputLen;
|
|
28
|
+
const blockLen = this.blockLen;
|
|
29
|
+
const pad = new Uint8Array(blockLen);
|
|
30
|
+
// blockLen can be bigger than outputLen
|
|
31
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
32
|
+
for (let i = 0; i < pad.length; i++)
|
|
33
|
+
pad[i] ^= 0x36;
|
|
34
|
+
this.iHash.update(pad);
|
|
35
|
+
// By doing update (processing of the first block) of the outer hash here,
|
|
36
|
+
// we can re-use it between multiple calls via clone.
|
|
37
|
+
this.oHash = hash.create();
|
|
38
|
+
// Undo internal XOR && apply outer XOR
|
|
39
|
+
for (let i = 0; i < pad.length; i++)
|
|
40
|
+
pad[i] ^= 0x36 ^ 0x5c;
|
|
41
|
+
this.oHash.update(pad);
|
|
42
|
+
clean(pad);
|
|
43
|
+
}
|
|
44
|
+
update(buf) {
|
|
45
|
+
aexists(this);
|
|
46
|
+
this.iHash.update(buf);
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
digestInto(out) {
|
|
50
|
+
aexists(this);
|
|
51
|
+
aoutput(out, this);
|
|
52
|
+
this.finished = true;
|
|
53
|
+
const buf = out.subarray(0, this.outputLen);
|
|
54
|
+
// Reuse the first outputLen bytes for the inner digest; the outer hash consumes them before
|
|
55
|
+
// overwriting that same prefix with the final tag, leaving any oversized tail untouched.
|
|
56
|
+
this.iHash.digestInto(buf);
|
|
57
|
+
this.oHash.update(buf);
|
|
58
|
+
this.oHash.digestInto(buf);
|
|
59
|
+
this.destroy();
|
|
60
|
+
}
|
|
61
|
+
digest() {
|
|
62
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
63
|
+
this.digestInto(out);
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
_cloneInto(to) {
|
|
67
|
+
// Create new instance without calling constructor since the key
|
|
68
|
+
// is already in state and we don't know it.
|
|
69
|
+
to ||= Object.create(Object.getPrototypeOf(this), {});
|
|
70
|
+
const { oHash, iHash, finished, destroyed, blockLen, outputLen, canXOF } = this;
|
|
71
|
+
to = to;
|
|
72
|
+
to.finished = finished;
|
|
73
|
+
to.destroyed = destroyed;
|
|
74
|
+
to.blockLen = blockLen;
|
|
75
|
+
to.outputLen = outputLen;
|
|
76
|
+
to.canXOF = canXOF;
|
|
77
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
78
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
79
|
+
return to;
|
|
80
|
+
}
|
|
81
|
+
clone() {
|
|
82
|
+
return this._cloneInto();
|
|
83
|
+
}
|
|
84
|
+
destroy() {
|
|
85
|
+
this.destroyed = true;
|
|
86
|
+
this.oHash.destroy();
|
|
87
|
+
this.iHash.destroy();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const hmac = /* @__PURE__ */ (() => {
|
|
91
|
+
const hmac_ = ((hash, key, message) => new _HMAC(hash, key).update(message).digest());
|
|
92
|
+
hmac_.create = (hash, key) => new _HMAC(hash, key);
|
|
93
|
+
return hmac_;
|
|
94
|
+
})();
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* HKDF (RFC 5869): extract + expand in one step.
|
|
98
|
+
* See {@link https://soatok.blog/2021/11/17/understanding-hkdf/}.
|
|
99
|
+
* @module
|
|
100
|
+
*/
|
|
101
|
+
// Shared mutable scratch byte for the RFC 5869 block counter `N`.
|
|
102
|
+
// Safe to reuse because `expand()` is synchronous and resets it with `clean(...)` before returning.
|
|
103
|
+
const HKDF_COUNTER = /* @__PURE__ */ Uint8Array.of(0);
|
|
104
|
+
// Shared RFC 5869 empty string for both `info === undefined` and the first-block `T(0)` input.
|
|
105
|
+
const EMPTY_BUFFER = /* @__PURE__ */ Uint8Array.of();
|
|
106
|
+
/**
|
|
107
|
+
* HKDF-expand from the spec. The most important part. `HKDF-Expand(PRK, info, L) -> OKM`
|
|
108
|
+
* @param hash - hash function that would be used (e.g. sha256)
|
|
109
|
+
* @param prk - a pseudorandom key of at least HashLen octets
|
|
110
|
+
* (usually, the output from the extract step)
|
|
111
|
+
* @param info - optional context and application specific information (can be a zero-length string)
|
|
112
|
+
* @param length - length of output keying material in bytes.
|
|
113
|
+
* RFC 5869 §2.3 allows `0..255*HashLen`, so `0` returns an empty OKM.
|
|
114
|
+
* @param _recycled - Internal destroyed extract hashes owned by the combined `hkdf()` call.
|
|
115
|
+
* @returns Output keying material with the requested length.
|
|
116
|
+
* @throws If the requested output length exceeds the HKDF limit
|
|
117
|
+
* for the selected hash. {@link Error}
|
|
118
|
+
* @example
|
|
119
|
+
* Run the HKDF expand step.
|
|
120
|
+
* ```ts
|
|
121
|
+
* import { expand } from '@noble/hashes/hkdf.js';
|
|
122
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
123
|
+
* expand(sha256, new Uint8Array(32), new Uint8Array([1, 2, 3]), 16);
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
function expand(hash, prk, info, length = 32, _recycled) {
|
|
127
|
+
ahash(hash);
|
|
128
|
+
anumber(length, 'length');
|
|
129
|
+
abytes(prk, undefined, 'prk');
|
|
130
|
+
const olen = hash.outputLen;
|
|
131
|
+
// RFC 5869 §2.3: PRK is "a pseudorandom key of at least HashLen octets".
|
|
132
|
+
if (prk.length < olen)
|
|
133
|
+
throw new Error('"prk" must be at least HashLen octets');
|
|
134
|
+
// RFC 5869 §2.3 only bounds `L` by `<= 255*HashLen`; `L=0` is valid and yields empty OKM.
|
|
135
|
+
if (length > 255 * olen)
|
|
136
|
+
throw new Error('Length must be <= 255*HashLen');
|
|
137
|
+
const blocks = Math.ceil(length / olen);
|
|
138
|
+
if (info === undefined)
|
|
139
|
+
info = EMPTY_BUFFER;
|
|
140
|
+
else
|
|
141
|
+
abytes(info, undefined, 'info');
|
|
142
|
+
if (!blocks) {
|
|
143
|
+
if (_recycled)
|
|
144
|
+
clean(prk); // Full hkdf() owns this intermediate PRK.
|
|
145
|
+
return new Uint8Array();
|
|
146
|
+
}
|
|
147
|
+
// first L(ength) octets of T
|
|
148
|
+
// The private PRK can become both T and a one-block result after HMAC consumes the key.
|
|
149
|
+
const okm = _recycled && blocks === 1 ? prk : new Uint8Array(blocks * olen);
|
|
150
|
+
const { iHash, oHash } = hmac.create(hash, prk);
|
|
151
|
+
// Driving them directly also skips `_HMAC.digestInto`'s per-digest destroy.
|
|
152
|
+
const T = _recycled ? prk : new Uint8Array(olen);
|
|
153
|
+
// Full hkdf() donates one destroyed extract hash; standalone creates one alternating worker.
|
|
154
|
+
const worker = blocks > 1 ? _recycled?.iHash || hash.create() : undefined;
|
|
155
|
+
for (let counter = 0; counter < blocks - 1; counter++) {
|
|
156
|
+
HKDF_COUNTER[0] = counter + 1;
|
|
157
|
+
const iWork = iHash._cloneInto(worker);
|
|
158
|
+
// T(0) = empty string (zero length)
|
|
159
|
+
// T(N) = HMAC-Hash(PRK, T(N-1) | info | N)
|
|
160
|
+
if (counter)
|
|
161
|
+
iWork.update(T);
|
|
162
|
+
iWork.update(info).update(HKDF_COUNTER).digestInto(T);
|
|
163
|
+
oHash._cloneInto(worker).update(T).digestInto(T);
|
|
164
|
+
okm.set(T, olen * counter);
|
|
165
|
+
}
|
|
166
|
+
// Midstates are key-equivalent: they allow computing HMAC(prk, ...) for any message.
|
|
167
|
+
HKDF_COUNTER[0] = blocks; // Final block consumes them; retain worker for cleanup.
|
|
168
|
+
if (blocks > 1)
|
|
169
|
+
iHash.update(T);
|
|
170
|
+
iHash.update(info).update(HKDF_COUNTER).digestInto(T);
|
|
171
|
+
oHash.update(T).digestInto(T);
|
|
172
|
+
okm.set(T, olen * (blocks - 1));
|
|
173
|
+
iHash.destroy(); // Raw digests may leave key-derived base/worker state; wipe all explicitly.
|
|
174
|
+
oHash.destroy();
|
|
175
|
+
worker?.destroy();
|
|
176
|
+
if (T !== okm)
|
|
177
|
+
clean(T); // Wipe private T/PRK; standalone preserves caller-owned PRK.
|
|
178
|
+
clean(HKDF_COUNTER);
|
|
179
|
+
// Exact fit: return without the extra copy.
|
|
180
|
+
if (length === okm.length)
|
|
181
|
+
return okm;
|
|
182
|
+
// Copy the requested prefix, then wipe the full buffer: its tail holds
|
|
183
|
+
// up to HashLen-1 bytes of derived key material past `length`.
|
|
184
|
+
const res = okm.slice(0, length);
|
|
185
|
+
clean(okm);
|
|
186
|
+
return res;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* HKDF (RFC 5869): derive keys from an initial input.
|
|
190
|
+
* Combines hkdf_extract + hkdf_expand in one step
|
|
191
|
+
* @param hash - hash function that would be used (e.g. sha256)
|
|
192
|
+
* @param ikm - input keying material, the initial key
|
|
193
|
+
* @param salt - optional salt value (a non-secret random value)
|
|
194
|
+
* @param info - optional context and application specific information bytes
|
|
195
|
+
* @param length - length of output keying material in bytes.
|
|
196
|
+
* RFC 5869 §2.3 allows `0..255*HashLen`, so `0` returns an empty OKM.
|
|
197
|
+
* @returns Output keying material derived from the input key.
|
|
198
|
+
* @throws If the requested output length exceeds the HKDF limit
|
|
199
|
+
* for the selected hash. {@link Error}
|
|
200
|
+
* @example
|
|
201
|
+
* HKDF (RFC 5869): derive keys from an initial input.
|
|
202
|
+
* ```ts
|
|
203
|
+
* import { hkdf } from '@noble/hashes/hkdf.js';
|
|
204
|
+
* import { sha256 } from '@noble/hashes/sha2.js';
|
|
205
|
+
* import { randomBytes, utf8ToBytes } from '@noble/hashes/utils.js';
|
|
206
|
+
* const inputKey = randomBytes(32);
|
|
207
|
+
* const salt = randomBytes(32);
|
|
208
|
+
* const info = utf8ToBytes('application-key');
|
|
209
|
+
* const okm = hkdf(sha256, inputKey, salt, info, 32);
|
|
210
|
+
* ```
|
|
211
|
+
*/
|
|
212
|
+
const hkdf = (hash, ikm, salt, info, length) => {
|
|
213
|
+
ahash(hash);
|
|
214
|
+
if (salt === undefined)
|
|
215
|
+
salt = new Uint8Array(hash.outputLen);
|
|
216
|
+
const HMAC = hmac.create(hash, salt).update(ikm);
|
|
217
|
+
// The intermediate PRK is secret key material; wipe it instead of
|
|
218
|
+
// leaving it for GC.
|
|
219
|
+
return expand(hash, HMAC.digest(), info, length, HMAC); // expand() owns and consumes it.
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export { hkdf as h };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-
|
|
2
|
-
import 'crypto';
|
|
3
|
-
import './
|
|
4
|
-
import './proposal.proto-BcUgd885.js';
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-BYi7D_oa.js';
|
|
2
|
+
import './browser-crypto-B9N9KlL4.js';
|
|
3
|
+
import './connection-monitor-GPztgSSJ.js';
|
|
5
4
|
import './index-CvKt4UDE.js';
|
|
5
|
+
import './sha2-piimb6xL.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @params {String} network
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { F as FormatInterface, e as proto, T as TransactionMessage, C as ContractMessage, i as index$1, f as index$2, g as createRIPEMD160, h as createHMAC, k as createSHA512, l as createKeccak, m as index$3 } from './
|
|
1
|
+
import { F as FormatInterface, e as proto, T as TransactionMessage, C as ContractMessage, i as index$1, f as index$2, g as createRIPEMD160, h as createHMAC, k as createSHA512, l as createKeccak, m as index$3, n as createHash$1 } from './browser-crypto-B9N9KlL4.js';
|
|
2
2
|
import { t as toBase58, b as base58$1, i as index$4 } from './index-CvKt4UDE.js';
|
|
3
|
-
import { createHash as createHash$1 } from 'crypto';
|
|
4
3
|
|
|
5
4
|
/* Do NOT modify this file; see /src.ts/_admin/update-version.ts */
|
|
6
5
|
/**
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { F as FormatInterface } from './node-browser-
|
|
2
|
-
import 'crypto';
|
|
3
|
-
import './
|
|
4
|
-
import './proposal.proto-BcUgd885.js';
|
|
1
|
+
import { F as FormatInterface } from './node-browser-BYi7D_oa.js';
|
|
2
|
+
import './browser-crypto-B9N9KlL4.js';
|
|
3
|
+
import './connection-monitor-GPztgSSJ.js';
|
|
5
4
|
import './index-CvKt4UDE.js';
|
|
5
|
+
import './sha2-piimb6xL.js';
|
|
6
6
|
|
|
7
7
|
var proto$b = {
|
|
8
8
|
data: new Uint8Array(),
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { B as BlockMessage, a as BWMessage, V as ValidatorMessage, S as StateMessage, L as LastBlockMessage, D as DEFAULT_NODE_OPTIONS } from './
|
|
1
|
+
import { F as FormatInterface$2, T as TransactionMessage, C as ContractMessage, n as createHash$1 } from './browser-crypto-B9N9KlL4.js';
|
|
2
|
+
import { B as BlockMessage, a as BWMessage, V as ValidatorMessage, S as StateMessage, L as LastBlockMessage, D as DEFAULT_NODE_OPTIONS, g as guardPeerMessages } from './connection-monitor-GPztgSSJ.js';
|
|
3
3
|
import './index-CvKt4UDE.js';
|
|
4
|
-
import { F as FormatInterface$2, T as TransactionMessage, C as ContractMessage } from './proposal.proto-BcUgd885.js';
|
|
5
4
|
|
|
6
5
|
var proto = {};
|
|
7
6
|
|
|
@@ -8391,7 +8390,7 @@ class Identity {
|
|
|
8391
8390
|
this.selectedAccount = new TextDecoder().decode(selected);
|
|
8392
8391
|
}
|
|
8393
8392
|
else {
|
|
8394
|
-
const importee = await import(/* webpackChunkName: "generate-account" */ './index-Bxr5Iztg-
|
|
8393
|
+
const importee = await import(/* webpackChunkName: "generate-account" */ './index-Bxr5Iztg-WbFIosyf.js');
|
|
8395
8394
|
const { identity, accounts } = await importee.default(password, this.network);
|
|
8396
8395
|
if (fresh) {
|
|
8397
8396
|
await globalThis.accountStore.clear();
|
|
@@ -17140,7 +17139,7 @@ class Peernet {
|
|
|
17140
17139
|
await getAddress();
|
|
17141
17140
|
this.storePrefix = options.storePrefix;
|
|
17142
17141
|
this.root = options.root;
|
|
17143
|
-
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-
|
|
17142
|
+
const { RequestMessage, ResponseMessage, PeerMessage, PeerMessageResponse, PeernetMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PsMessage, ChatMessage, PeernetFile } = await import(/* webpackChunkName: "messages" */ './messages-DH0tgNM9-C2CtyLsf.js');
|
|
17144
17143
|
/**
|
|
17145
17144
|
* proto Object containing protos
|
|
17146
17145
|
* @type {Object}
|
|
@@ -17187,7 +17186,7 @@ class Peernet {
|
|
|
17187
17186
|
if (this.#starting || this.#started)
|
|
17188
17187
|
return;
|
|
17189
17188
|
this.#starting = true;
|
|
17190
|
-
const importee = await import('./client-
|
|
17189
|
+
const importee = await import('./client-DDC8C510-3uaB70KL.js');
|
|
17191
17190
|
/**
|
|
17192
17191
|
* @access public
|
|
17193
17192
|
* @type {PeernetClient}
|
|
@@ -17866,6 +17865,7 @@ class Node {
|
|
|
17866
17865
|
async _init(config = {}, password) {
|
|
17867
17866
|
config = { ...DEFAULT_NODE_OPTIONS, ...config };
|
|
17868
17867
|
this.#node = globalThis.Peernet ? await new globalThis.Peernet(config, password) : await new Peernet(config, password);
|
|
17868
|
+
guardPeerMessages(this.#node);
|
|
17869
17869
|
await nodeConfig(config);
|
|
17870
17870
|
globalThis.pubsub.subscribe("chain:ready", async () => {
|
|
17871
17871
|
if (!this.#node.autoStart) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { N as default } from './node-browser-
|
|
2
|
-
import 'crypto';
|
|
3
|
-
import './
|
|
1
|
+
export { N as default } from './node-browser-BYi7D_oa.js';
|
|
2
|
+
import './browser-crypto-B9N9KlL4.js';
|
|
3
|
+
import './connection-monitor-GPztgSSJ.js';
|
|
4
4
|
import './index-CvKt4UDE.js';
|
|
5
|
-
import './
|
|
5
|
+
import './sha2-piimb6xL.js';
|