@leofcoin/chain 1.10.12 → 1.10.14
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-4-PGqr4c.js} +4 -4
- package/exports/browser/browser-DvU1xNFS-BJCQsckZ.js +151 -0
- package/exports/browser/browser-DvU1xNFS-D9eSzJGJ.js +151 -0
- package/exports/browser/browser-crypto-BHeOz9rj.js +8893 -0
- package/exports/browser/browser-crypto-CTP3Yk4M.js +8893 -0
- package/exports/browser/{proposal.proto-BcUgd885.js → browser-crypto-Yk_e6OHw.js} +35 -6
- package/exports/browser/chain.js +63 -321
- package/exports/browser/{client-B-jyclOB-CsNYfj4Z.js → client-DDC8C510-CUi3_3uT.js} +36 -12
- package/exports/browser/client-DDC8C510-DbIdQjhy.js +2225 -0
- package/exports/browser/client-DDC8C510-ZN_MLo1Y.js +2225 -0
- package/exports/browser/connection-monitor-BjXI0nBP.js +453 -0
- package/exports/browser/connection-monitor-Cf0vNDCA.js +453 -0
- package/exports/browser/connection-monitor-pdopeM1I.js +453 -0
- package/exports/browser/hkdf-B9AXp_7K.js +222 -0
- package/exports/browser/hkdf-CnZvwpZ9.js +222 -0
- package/exports/browser/{index-Bxr5Iztg-C6xBk0rK.js → index-Bxr5Iztg-AmkW0EHS.js} +4 -4
- package/exports/browser/index-Bxr5Iztg-Bdpw_E83.js +40 -0
- package/exports/browser/index-Bxr5Iztg-CxXVYm3t.js +40 -0
- package/exports/browser/{index-D7FUx7Dd.js → index-CPQ5yvZ2.js} +5 -6
- package/exports/browser/index-C_RakUAS.js +4995 -0
- package/exports/browser/index-uFaocBqT.js +4995 -0
- package/exports/browser/{messages-FMRAS8QX-CvlZBzy5.js → messages-DH0tgNM9-BRp0gcJh.js} +4 -4
- package/exports/browser/messages-DH0tgNM9-CZwrcL37.js +208 -0
- package/exports/browser/messages-DH0tgNM9-DkNnpePH.js +208 -0
- package/exports/browser/{node-browser-xlqSBOaN.js → node-browser-1VSuCeew.js} +6 -6
- package/exports/browser/node-browser-CQugE1WZ.js +17880 -0
- package/exports/browser/node-browser-wDmRaOEo.js +17880 -0
- package/exports/browser/node-browser.js +4 -4
- package/exports/browser/sha2-Dkoic3vb.js +602 -0
- package/exports/browser/sha2-piimb6xL.js +614 -0
- package/exports/browser/weierstrass-HGdA_prK.js +2156 -0
- package/exports/browser/{weierstrass-C-jX_jly.js → weierstrass-Q0QND1ZT.js} +1 -1
- package/exports/browser/workers/machine-worker.js +419 -147
- package/exports/chain.js +56 -313
- package/exports/connection-monitor.js +324 -0
- package/exports/node.js +2 -0
- package/exports/workers/machine-worker.js +419 -147
- package/package.json +4 -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-CQugE1WZ.js';
|
|
2
|
+
import './browser-crypto-CTP3Yk4M.js';
|
|
3
|
+
import './connection-monitor-pdopeM1I.js';
|
|
5
4
|
import './index-CvKt4UDE.js';
|
|
5
|
+
import './sha2-piimb6xL.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* @params {String} network
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-1VSuCeew.js';
|
|
2
|
+
import './browser-crypto-BHeOz9rj.js';
|
|
3
|
+
import './connection-monitor-BjXI0nBP.js';
|
|
4
|
+
import './index-CvKt4UDE.js';
|
|
5
|
+
import './sha2-Dkoic3vb.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @params {String} network
|
|
9
|
+
* @return {object} { identity, accounts, config }
|
|
10
|
+
*/
|
|
11
|
+
var index = async (password, network) => {
|
|
12
|
+
if (!password)
|
|
13
|
+
throw new Error('wallets need to be password protected.');
|
|
14
|
+
let wallet = new MultiWallet(network);
|
|
15
|
+
/**
|
|
16
|
+
* @type {string}
|
|
17
|
+
*/
|
|
18
|
+
let mnemonic = await wallet.generate(password);
|
|
19
|
+
wallet = new MultiWallet(network);
|
|
20
|
+
await wallet.recover(mnemonic, password, network);
|
|
21
|
+
mnemonic = new Uint8Array(await encrypt(password, mnemonic));
|
|
22
|
+
const multiWIF = new Uint8Array(await encrypt(password, await wallet.multiWIF));
|
|
23
|
+
/**
|
|
24
|
+
* @type {object}
|
|
25
|
+
*/
|
|
26
|
+
const external = await wallet.account(1).external(1);
|
|
27
|
+
const externalAddress = await external.address;
|
|
28
|
+
const internal = await wallet.account(1).internal(1);
|
|
29
|
+
const internalAddress = await internal.address;
|
|
30
|
+
return {
|
|
31
|
+
identity: {
|
|
32
|
+
mnemonic: base58$1.encode(mnemonic),
|
|
33
|
+
multiWIF: base58$1.encode(multiWIF),
|
|
34
|
+
walletId: await external.id
|
|
35
|
+
},
|
|
36
|
+
accounts: [['main account', externalAddress, internalAddress]]
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { index as default };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { M as MultiWallet, e as encrypt, b as base58$1 } from './node-browser-wDmRaOEo.js';
|
|
2
|
+
import './browser-crypto-Yk_e6OHw.js';
|
|
3
|
+
import './connection-monitor-Cf0vNDCA.js';
|
|
4
|
+
import './index-CvKt4UDE.js';
|
|
5
|
+
import './sha2-Dkoic3vb.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @params {String} network
|
|
9
|
+
* @return {object} { identity, accounts, config }
|
|
10
|
+
*/
|
|
11
|
+
var index = async (password, network) => {
|
|
12
|
+
if (!password)
|
|
13
|
+
throw new Error('wallets need to be password protected.');
|
|
14
|
+
let wallet = new MultiWallet(network);
|
|
15
|
+
/**
|
|
16
|
+
* @type {string}
|
|
17
|
+
*/
|
|
18
|
+
let mnemonic = await wallet.generate(password);
|
|
19
|
+
wallet = new MultiWallet(network);
|
|
20
|
+
await wallet.recover(mnemonic, password, network);
|
|
21
|
+
mnemonic = new Uint8Array(await encrypt(password, mnemonic));
|
|
22
|
+
const multiWIF = new Uint8Array(await encrypt(password, await wallet.multiWIF));
|
|
23
|
+
/**
|
|
24
|
+
* @type {object}
|
|
25
|
+
*/
|
|
26
|
+
const external = await wallet.account(1).external(1);
|
|
27
|
+
const externalAddress = await external.address;
|
|
28
|
+
const internal = await wallet.account(1).internal(1);
|
|
29
|
+
const internalAddress = await internal.address;
|
|
30
|
+
return {
|
|
31
|
+
identity: {
|
|
32
|
+
mnemonic: base58$1.encode(mnemonic),
|
|
33
|
+
multiWIF: base58$1.encode(multiWIF),
|
|
34
|
+
walletId: await external.id
|
|
35
|
+
},
|
|
36
|
+
accounts: [['main account', externalAddress, internalAddress]]
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { index as default };
|