@leofcoin/chain 1.10.16 → 1.10.17
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 +6 -6
- package/exports/beacon-epoch.js +1 -1
- package/exports/beacon-lifecycle.js +1 -1
- package/exports/beacon-round.js +1 -1
- package/exports/beacon.js +15 -14
- package/exports/browser/_commonjsHelpers-B85MJLTf.js +5 -0
- package/exports/browser/beacon-envelope.js +61 -150
- package/exports/browser/beacon-epoch.js +2 -2
- package/exports/browser/beacon-lifecycle.js +3 -3
- package/exports/browser/beacon-round.js +2 -2
- package/exports/browser/beacon-wire.js +3 -3
- package/exports/browser/beacon.js +2483 -1228
- package/exports/browser/{browser-CCfR9KOM-CvhDZrGu.js → browser-CCfR9KOM-CpStHgTj.js} +4 -4
- package/exports/browser/{browser-crypto-CeE-yId5.js → browser-crypto-CH0ua22L.js} +1 -1
- package/exports/browser/chain.js +5 -8
- package/exports/browser/{client-CAC7RVMf-Dmz_2A_5.js → client-C_pBoi1g-_pfKzCvX.js} +256 -80
- package/exports/browser/{connection-monitor-Cmv00mwl.js → connection-monitor-D-krNiRH.js} +1 -1
- package/exports/browser/{hkdf-CnZvwpZ9.js → hkdf-BUHINPFj.js} +2 -94
- package/exports/browser/{index-BC-KRBgE.js → index-DmuI-29u.js} +1 -1
- package/exports/browser/{index-dTQVgkpf-CuHJWO2l.js → index-dTQVgkpf-BbdshWB0.js} +4 -4
- package/exports/browser/index.browser-CFfJpgKV.js +857 -0
- package/exports/browser/{messages-Dw86z0zq-DrPw_nlZ.js → messages-BGHaihSi-eHZVl0y9.js} +4 -4
- package/exports/browser/{node-browser-DWSdi-XP.js → node-browser-BNe-en1l.js} +5 -5
- package/exports/browser/node-browser.js +4 -4
- package/exports/browser/{sha2-piimb6xL.js → sha2-BKcEJzgd.js} +144 -3
- package/exports/browser/weierstrass-BVfhtHbl.js +3596 -0
- package/exports/browser/workers/machine-worker.js +42 -14
- package/exports/workers/machine-worker.js +42 -14
- package/package.json +14 -13
- package/exports/browser/weierstrass-Q0QND1ZT.js +0 -2156
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { secp256k1 } from '@noble/curves/secp256k1';
|
|
1
|
+
import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
2
2
|
import { hkdf } from '@noble/hashes/hkdf.js';
|
|
3
3
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
4
4
|
|
|
@@ -11,7 +11,7 @@ const context = (network, epoch, sender, recipient) => {
|
|
|
11
11
|
return encoder.encode(`leofcoin-beacon-share-v1:${network}:${epoch}:${sender}:${recipient}`);
|
|
12
12
|
};
|
|
13
13
|
const scalarBytes = (share) => {
|
|
14
|
-
if (share <= 0n || share >= secp256k1.
|
|
14
|
+
if (share <= 0n || share >= secp256k1.Point.Fn.ORDER) throw new RangeError("invalid beacon secret share");
|
|
15
15
|
const output = new Uint8Array(SCALAR_BYTES);
|
|
16
16
|
let value = share;
|
|
17
17
|
for (let index = output.length - 1; index >= 0; index -= 1) {
|
|
@@ -24,18 +24,18 @@ const bytesScalar = (bytes) => {
|
|
|
24
24
|
if (bytes.length !== SCALAR_BYTES) throw new Error("invalid decrypted beacon share length");
|
|
25
25
|
let value = 0n;
|
|
26
26
|
for (const byte of bytes) value = value << 8n | BigInt(byte);
|
|
27
|
-
if (value <= 0n || value >= secp256k1.
|
|
27
|
+
if (value <= 0n || value >= secp256k1.Point.Fn.ORDER) throw new Error("invalid decrypted beacon share");
|
|
28
28
|
return value;
|
|
29
29
|
};
|
|
30
30
|
const encryptionKey = (privateKey, publicKey, aad) => {
|
|
31
|
-
if (!secp256k1.utils.
|
|
31
|
+
if (!secp256k1.utils.isValidSecretKey(privateKey)) throw new Error("invalid beacon encryption private key");
|
|
32
32
|
const sharedSecret = secp256k1.getSharedSecret(privateKey, publicKey, true);
|
|
33
33
|
return hkdf(sha256, sharedSecret, sha256(aad), aad, 32);
|
|
34
34
|
};
|
|
35
35
|
const importAesKey = (key, usage) => globalThis.crypto.subtle.importKey("raw", key, { name: "AES-GCM" }, false, [usage]);
|
|
36
|
-
const createBeaconEncryptionKey = (randomPrivateKey = () => secp256k1.utils.
|
|
36
|
+
const createBeaconEncryptionKey = (randomPrivateKey = () => secp256k1.utils.randomSecretKey()) => {
|
|
37
37
|
const privateKey = randomPrivateKey();
|
|
38
|
-
if (!secp256k1.utils.
|
|
38
|
+
if (!secp256k1.utils.isValidSecretKey(privateKey)) throw new Error("invalid generated beacon encryption key");
|
|
39
39
|
return { privateKey, publicKey: secp256k1.getPublicKey(privateKey, true) };
|
|
40
40
|
};
|
|
41
41
|
const encryptBeaconShare = async (share, recipientPublicKey, network, epoch, sender, recipient, randomPrivateKey, randomNonce = () => globalThis.crypto.getRandomValues(new Uint8Array(12))) => {
|
package/exports/beacon-epoch.js
CHANGED
|
@@ -2,7 +2,7 @@ import { sha256 } from '@noble/hashes/sha2.js';
|
|
|
2
2
|
import { toBase58, fromBase58 } from '@vandeurenglenn/typed-array-utils';
|
|
3
3
|
import { deriveBeaconGroupPublicKey } from './beacon.js';
|
|
4
4
|
import { q as quorumThreshold } from './quorum-S_qdgiAY.js';
|
|
5
|
-
import '@noble/curves/bls12-381';
|
|
5
|
+
import '@noble/curves/bls12-381.js';
|
|
6
6
|
|
|
7
7
|
const encoder = new TextEncoder();
|
|
8
8
|
const lengthPrefix = (bytes) => {
|
|
@@ -3,7 +3,7 @@ import { sha256 } from '@noble/hashes/sha2.js';
|
|
|
3
3
|
import { canonicalBeaconEpochConfig, beaconEpochDigest } from './beacon-epoch.js';
|
|
4
4
|
import '@vandeurenglenn/typed-array-utils';
|
|
5
5
|
import './beacon.js';
|
|
6
|
-
import '@noble/curves/bls12-381';
|
|
6
|
+
import '@noble/curves/bls12-381.js';
|
|
7
7
|
import './quorum-S_qdgiAY.js';
|
|
8
8
|
|
|
9
9
|
const encoder = new TextEncoder();
|
package/exports/beacon-round.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fromBase58, toBase58 } from '@vandeurenglenn/typed-array-utils';
|
|
2
2
|
import { beaconMessage, deriveBeaconPublicShare, verifyBeaconSignatureShare, reconstructBeaconSignature, verifyBeaconProof, beaconRandomness } from './beacon.js';
|
|
3
3
|
import { canonicalBeaconEpochConfig, beaconParticipants, beaconEpochGroupPublicKey } from './beacon-epoch.js';
|
|
4
|
-
import '@noble/curves/bls12-381';
|
|
4
|
+
import '@noble/curves/bls12-381.js';
|
|
5
5
|
import '@noble/hashes/sha2.js';
|
|
6
6
|
import './quorum-S_qdgiAY.js';
|
|
7
7
|
|
package/exports/beacon.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { bls12_381 } from '@noble/curves/bls12-381';
|
|
1
|
+
import { bls12_381 } from '@noble/curves/bls12-381.js';
|
|
2
2
|
import { sha256 } from '@noble/hashes/sha2.js';
|
|
3
3
|
|
|
4
4
|
const encoder = new TextEncoder();
|
|
5
5
|
const Fr = bls12_381.fields.Fr;
|
|
6
|
-
const G1 = bls12_381.G1.
|
|
7
|
-
const G2 = bls12_381.G2.
|
|
6
|
+
const G1 = bls12_381.G1.Point;
|
|
7
|
+
const G2 = bls12_381.G2.Point;
|
|
8
|
+
const signatures = bls12_381.longSignatures;
|
|
8
9
|
const assertParticipant = (participant) => {
|
|
9
10
|
if (typeof participant !== "bigint" || participant <= 0n || participant >= Fr.ORDER) {
|
|
10
11
|
throw new TypeError("beacon participant identifiers must be non-zero field elements");
|
|
@@ -30,7 +31,7 @@ const evaluateCommitments = (commitments, x) => {
|
|
|
30
31
|
let result = G1.ZERO;
|
|
31
32
|
let power = 1n;
|
|
32
33
|
for (const encoded of commitments) {
|
|
33
|
-
const commitment = G1.
|
|
34
|
+
const commitment = G1.fromBytes(encoded);
|
|
34
35
|
commitment.assertValidity();
|
|
35
36
|
result = result.add(commitment.multiply(power));
|
|
36
37
|
power = Fr.mul(power, x);
|
|
@@ -40,7 +41,7 @@ const evaluateCommitments = (commitments, x) => {
|
|
|
40
41
|
const sumPoints = (points) => {
|
|
41
42
|
let result = G1.ZERO;
|
|
42
43
|
for (const encoded of points) {
|
|
43
|
-
const point = G1.
|
|
44
|
+
const point = G1.fromBytes(encoded);
|
|
44
45
|
point.assertValidity();
|
|
45
46
|
result = result.add(point);
|
|
46
47
|
}
|
|
@@ -65,7 +66,7 @@ const createBeaconContribution = (participants, threshold, randomScalar) => {
|
|
|
65
66
|
return scalar;
|
|
66
67
|
});
|
|
67
68
|
return {
|
|
68
|
-
commitments: coefficients.map((coefficient) => G1.BASE.multiply(coefficient).
|
|
69
|
+
commitments: coefficients.map((coefficient) => G1.BASE.multiply(coefficient).toBytes(true)),
|
|
69
70
|
shares: new Map(participants.map((participant) => [participant, evaluatePolynomial(coefficients, participant)]))
|
|
70
71
|
};
|
|
71
72
|
};
|
|
@@ -86,14 +87,14 @@ const deriveBeaconPublicShare = (participant, dealerCommitments) => {
|
|
|
86
87
|
assertParticipant(participant);
|
|
87
88
|
if (dealerCommitments.length < 2) throw new Error("at least two dealer commitments are required");
|
|
88
89
|
return sumPoints(
|
|
89
|
-
dealerCommitments.map((commitments) => evaluateCommitments(commitments, participant).
|
|
90
|
-
).
|
|
90
|
+
dealerCommitments.map((commitments) => evaluateCommitments(commitments, participant).toBytes(true))
|
|
91
|
+
).toBytes(true);
|
|
91
92
|
};
|
|
92
93
|
const deriveBeaconGroupPublicKey = (dealerCommitments) => {
|
|
93
94
|
if (dealerCommitments.length < 2 || dealerCommitments.some((commitments) => commitments.length < 2)) {
|
|
94
95
|
throw new Error("invalid beacon dealer commitments");
|
|
95
96
|
}
|
|
96
|
-
return sumPoints(dealerCommitments.map((commitments) => commitments[0])).
|
|
97
|
+
return sumPoints(dealerCommitments.map((commitments) => commitments[0])).toBytes(true);
|
|
97
98
|
};
|
|
98
99
|
const beaconMessage = (network, epoch, round, previousProof) => {
|
|
99
100
|
if (!network || epoch < 0n || round < 0n) throw new TypeError("invalid beacon round");
|
|
@@ -103,10 +104,10 @@ const beaconMessage = (network, epoch, round, previousProof) => {
|
|
|
103
104
|
message.set(previousProof, prefix.length);
|
|
104
105
|
return message;
|
|
105
106
|
};
|
|
106
|
-
const signBeaconRound = (secretShare, message) =>
|
|
107
|
+
const signBeaconRound = (secretShare, message) => signatures.Signature.toBytes(signatures.sign(signatures.hash(message), Fr.toBytes(Fr.create(secretShare))));
|
|
107
108
|
const verifyBeaconSignatureShare = (signature, message, publicShare) => {
|
|
108
109
|
try {
|
|
109
|
-
return
|
|
110
|
+
return signatures.verify(signature, signatures.hash(message), publicShare);
|
|
110
111
|
} catch {
|
|
111
112
|
return false;
|
|
112
113
|
}
|
|
@@ -120,15 +121,15 @@ const reconstructBeaconSignature = (rawShares, threshold) => {
|
|
|
120
121
|
assertUniqueParticipants(participants);
|
|
121
122
|
let signature = G2.ZERO;
|
|
122
123
|
for (const share of selected) {
|
|
123
|
-
const point =
|
|
124
|
+
const point = signatures.Signature.fromBytes(share.signature);
|
|
124
125
|
point.assertValidity();
|
|
125
126
|
signature = signature.add(point.multiply(lagrangeAtZero(share.participant, participants)));
|
|
126
127
|
}
|
|
127
|
-
return
|
|
128
|
+
return signatures.Signature.toBytes(signature);
|
|
128
129
|
};
|
|
129
130
|
const verifyBeaconProof = (proof, message, groupPublicKey) => {
|
|
130
131
|
try {
|
|
131
|
-
return
|
|
132
|
+
return signatures.verify(proof, signatures.hash(message), groupPublicKey);
|
|
132
133
|
} catch {
|
|
133
134
|
return false;
|
|
134
135
|
}
|
|
@@ -1,108 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { s as sha256 } from './sha2-BKcEJzgd.js';
|
|
2
|
+
import { e as ecdsa, w as weierstrass, F as Field, p as pow2 } from './weierstrass-BVfhtHbl.js';
|
|
3
|
+
import { h as hkdf } from './hkdf-BUHINPFj.js';
|
|
4
4
|
|
|
5
|
-
// HMAC (RFC 2104)
|
|
6
|
-
class HMAC extends Hash {
|
|
7
|
-
constructor(hash$1, _key) {
|
|
8
|
-
super();
|
|
9
|
-
this.finished = false;
|
|
10
|
-
this.destroyed = false;
|
|
11
|
-
hash(hash$1);
|
|
12
|
-
const key = toBytes(_key);
|
|
13
|
-
this.iHash = hash$1.create();
|
|
14
|
-
if (typeof this.iHash.update !== 'function')
|
|
15
|
-
throw new Error('Expected instance of class which extends utils.Hash');
|
|
16
|
-
this.blockLen = this.iHash.blockLen;
|
|
17
|
-
this.outputLen = this.iHash.outputLen;
|
|
18
|
-
const blockLen = this.blockLen;
|
|
19
|
-
const pad = new Uint8Array(blockLen);
|
|
20
|
-
// blockLen can be bigger than outputLen
|
|
21
|
-
pad.set(key.length > blockLen ? hash$1.create().update(key).digest() : key);
|
|
22
|
-
for (let i = 0; i < pad.length; i++)
|
|
23
|
-
pad[i] ^= 0x36;
|
|
24
|
-
this.iHash.update(pad);
|
|
25
|
-
// By doing update (processing of first block) of outer hash here we can re-use it between multiple calls via clone
|
|
26
|
-
this.oHash = hash$1.create();
|
|
27
|
-
// Undo internal XOR && apply outer XOR
|
|
28
|
-
for (let i = 0; i < pad.length; i++)
|
|
29
|
-
pad[i] ^= 0x36 ^ 0x5c;
|
|
30
|
-
this.oHash.update(pad);
|
|
31
|
-
pad.fill(0);
|
|
32
|
-
}
|
|
33
|
-
update(buf) {
|
|
34
|
-
exists(this);
|
|
35
|
-
this.iHash.update(buf);
|
|
36
|
-
return this;
|
|
37
|
-
}
|
|
38
|
-
digestInto(out) {
|
|
39
|
-
exists(this);
|
|
40
|
-
bytes(out, this.outputLen);
|
|
41
|
-
this.finished = true;
|
|
42
|
-
this.iHash.digestInto(out);
|
|
43
|
-
this.oHash.update(out);
|
|
44
|
-
this.oHash.digestInto(out);
|
|
45
|
-
this.destroy();
|
|
46
|
-
}
|
|
47
|
-
digest() {
|
|
48
|
-
const out = new Uint8Array(this.oHash.outputLen);
|
|
49
|
-
this.digestInto(out);
|
|
50
|
-
return out;
|
|
51
|
-
}
|
|
52
|
-
_cloneInto(to) {
|
|
53
|
-
// Create new instance without calling constructor since key already in state and we don't know it.
|
|
54
|
-
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
55
|
-
const { oHash, iHash, finished, destroyed, blockLen, outputLen } = this;
|
|
56
|
-
to = to;
|
|
57
|
-
to.finished = finished;
|
|
58
|
-
to.destroyed = destroyed;
|
|
59
|
-
to.blockLen = blockLen;
|
|
60
|
-
to.outputLen = outputLen;
|
|
61
|
-
to.oHash = oHash._cloneInto(to.oHash);
|
|
62
|
-
to.iHash = iHash._cloneInto(to.iHash);
|
|
63
|
-
return to;
|
|
64
|
-
}
|
|
65
|
-
destroy() {
|
|
66
|
-
this.destroyed = true;
|
|
67
|
-
this.oHash.destroy();
|
|
68
|
-
this.iHash.destroy();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
5
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
75
|
-
* @
|
|
6
|
+
* SECG secp256k1. See [pdf](https://www.secg.org/sec2-v2.pdf).
|
|
7
|
+
*
|
|
8
|
+
* Belongs to Koblitz curves: it has efficiently-computable GLV endomorphism ψ,
|
|
9
|
+
* check out {@link EndomorphismOpts}. Seems to be rigid (not backdoored).
|
|
10
|
+
* @module
|
|
76
11
|
*/
|
|
77
|
-
const hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
78
|
-
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
79
|
-
|
|
80
|
-
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
81
|
-
// connects noble-curves to noble-hashes
|
|
82
|
-
function getHash(hash) {
|
|
83
|
-
return {
|
|
84
|
-
hash,
|
|
85
|
-
hmac: (key, ...msgs) => hmac(hash, key, concatBytes(...msgs)),
|
|
86
|
-
randomBytes,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
function createCurve(curveDef, defHash) {
|
|
90
|
-
const create = (hash) => weierstrass({ ...curveDef, ...getHash(hash) });
|
|
91
|
-
return Object.freeze({ ...create(defHash), create });
|
|
92
|
-
}
|
|
93
|
-
|
|
94
12
|
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
13
|
+
// Seems like generator was produced from some seed:
|
|
14
|
+
// `Pointk1.BASE.multiply(Pointk1.Fn.inv(2n, N)).toAffine().x`
|
|
15
|
+
// // gives short x 0x3b78ce563f89a0ed9414f5aa28ad0d96d6795f9c63n
|
|
16
|
+
const secp256k1_CURVE = {
|
|
17
|
+
p: BigInt('0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f'),
|
|
18
|
+
n: BigInt('0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141'),
|
|
19
|
+
h: BigInt(1),
|
|
20
|
+
a: BigInt(0),
|
|
21
|
+
b: BigInt(7),
|
|
22
|
+
Gx: BigInt('0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'),
|
|
23
|
+
Gy: BigInt('0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8'),
|
|
24
|
+
};
|
|
25
|
+
const secp256k1_ENDO = {
|
|
26
|
+
beta: BigInt('0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee'),
|
|
27
|
+
basises: [
|
|
28
|
+
[BigInt('0x3086d221a7d46bcde86c90e49284eb15'), -BigInt('0xe4437ed6010e88286f547fa90abfe4c3')],
|
|
29
|
+
[BigInt('0x114ca50f7a8e2f3f657c1108d9d44cfd8'), BigInt('0x3086d221a7d46bcde86c90e49284eb15')],
|
|
30
|
+
],
|
|
31
|
+
};
|
|
32
|
+
const _2n = /* @__PURE__ */ BigInt(2);
|
|
100
33
|
/**
|
|
101
34
|
* √n = n^((p+1)/4) for fields p = 3 mod 4. We unwrap the loop and multiply bit-by-bit.
|
|
102
35
|
* (P+1n/4n).toString(2) would produce bits [223x 1, 0, 22x 1, 4x 0, 11, 00]
|
|
103
36
|
*/
|
|
104
37
|
function sqrtMod(y) {
|
|
105
|
-
const P =
|
|
38
|
+
const P = secp256k1_CURVE.p;
|
|
106
39
|
// prettier-ignore
|
|
107
40
|
const _3n = BigInt(3), _6n = BigInt(6), _11n = BigInt(11), _22n = BigInt(22);
|
|
108
41
|
// prettier-ignore
|
|
@@ -121,57 +54,35 @@ function sqrtMod(y) {
|
|
|
121
54
|
const t1 = (pow2(b223, _23n, P) * b22) % P;
|
|
122
55
|
const t2 = (pow2(t1, _6n, P) * b2) % P;
|
|
123
56
|
const root = pow2(t2, _2n, P);
|
|
124
|
-
if (!
|
|
57
|
+
if (!Fpk1.eql(Fpk1.sqr(root), y))
|
|
125
58
|
throw new Error('Cannot find square root');
|
|
126
59
|
return root;
|
|
127
60
|
}
|
|
128
|
-
const
|
|
129
|
-
const
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const POW_2_128 = BigInt('0x100000000000000000000000000000000'); // (2n**128n).toString(16)
|
|
154
|
-
const c1 = divNearest(b2 * k, n);
|
|
155
|
-
const c2 = divNearest(-b1 * k, n);
|
|
156
|
-
let k1 = mod(k - c1 * a1 - c2 * a2, n);
|
|
157
|
-
let k2 = mod(-c1 * b1 - c2 * b2, n);
|
|
158
|
-
const k1neg = k1 > POW_2_128;
|
|
159
|
-
const k2neg = k2 > POW_2_128;
|
|
160
|
-
if (k1neg)
|
|
161
|
-
k1 = n - k1;
|
|
162
|
-
if (k2neg)
|
|
163
|
-
k2 = n - k2;
|
|
164
|
-
if (k1 > POW_2_128 || k2 > POW_2_128) {
|
|
165
|
-
throw new Error('splitScalar: Endomorphism failed, k=' + k);
|
|
166
|
-
}
|
|
167
|
-
return { k1neg, k1, k2neg, k2 };
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
}, sha256);
|
|
171
|
-
// Schnorr signatures are superior to ECDSA from above. Below is Schnorr-specific BIP0340 code.
|
|
172
|
-
// https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki
|
|
173
|
-
BigInt(0);
|
|
174
|
-
secp256k1.ProjectivePoint;
|
|
61
|
+
const Fpk1 = /* @__PURE__ */ Field(secp256k1_CURVE.p, { sqrt: sqrtMod });
|
|
62
|
+
const Pointk1 = /* @__PURE__ */ weierstrass(secp256k1_CURVE, {
|
|
63
|
+
Fp: Fpk1,
|
|
64
|
+
endo: secp256k1_ENDO,
|
|
65
|
+
});
|
|
66
|
+
/**
|
|
67
|
+
* secp256k1 curve: ECDSA and ECDH methods.
|
|
68
|
+
*
|
|
69
|
+
* Uses sha256 to hash messages. To use a different hash,
|
|
70
|
+
* pass `{ prehash: false }` to sign / verify.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* Generate one secp256k1 keypair, sign a message, and verify it.
|
|
74
|
+
*
|
|
75
|
+
* ```js
|
|
76
|
+
* import { secp256k1 } from '@noble/curves/secp256k1.js';
|
|
77
|
+
* const { secretKey, publicKey } = secp256k1.keygen();
|
|
78
|
+
* // const publicKey = secp256k1.getPublicKey(secretKey);
|
|
79
|
+
* const msg = new TextEncoder().encode('hello noble');
|
|
80
|
+
* const sig = secp256k1.sign(msg, secretKey);
|
|
81
|
+
* const isValid = secp256k1.verify(sig, msg, publicKey);
|
|
82
|
+
* // const sigKeccak = secp256k1.sign(keccak256(msg), secretKey, { prehash: false });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
const secp256k1 = /* @__PURE__ */ ecdsa(Pointk1, sha256);
|
|
175
86
|
|
|
176
87
|
const encoder = new TextEncoder();
|
|
177
88
|
const SCALAR_BYTES = 32;
|
|
@@ -182,7 +93,7 @@ const context = (network, epoch, sender, recipient) => {
|
|
|
182
93
|
return encoder.encode(`leofcoin-beacon-share-v1:${network}:${epoch}:${sender}:${recipient}`);
|
|
183
94
|
};
|
|
184
95
|
const scalarBytes = (share) => {
|
|
185
|
-
if (share <= 0n || share >= secp256k1.
|
|
96
|
+
if (share <= 0n || share >= secp256k1.Point.Fn.ORDER) throw new RangeError("invalid beacon secret share");
|
|
186
97
|
const output = new Uint8Array(SCALAR_BYTES);
|
|
187
98
|
let value = share;
|
|
188
99
|
for (let index = output.length - 1; index >= 0; index -= 1) {
|
|
@@ -195,18 +106,18 @@ const bytesScalar = (bytes) => {
|
|
|
195
106
|
if (bytes.length !== SCALAR_BYTES) throw new Error("invalid decrypted beacon share length");
|
|
196
107
|
let value = 0n;
|
|
197
108
|
for (const byte of bytes) value = value << 8n | BigInt(byte);
|
|
198
|
-
if (value <= 0n || value >= secp256k1.
|
|
109
|
+
if (value <= 0n || value >= secp256k1.Point.Fn.ORDER) throw new Error("invalid decrypted beacon share");
|
|
199
110
|
return value;
|
|
200
111
|
};
|
|
201
112
|
const encryptionKey = (privateKey, publicKey, aad) => {
|
|
202
|
-
if (!secp256k1.utils.
|
|
113
|
+
if (!secp256k1.utils.isValidSecretKey(privateKey)) throw new Error("invalid beacon encryption private key");
|
|
203
114
|
const sharedSecret = secp256k1.getSharedSecret(privateKey, publicKey, true);
|
|
204
|
-
return hkdf(sha256
|
|
115
|
+
return hkdf(sha256, sharedSecret, sha256(aad), aad, 32);
|
|
205
116
|
};
|
|
206
117
|
const importAesKey = (key, usage) => globalThis.crypto.subtle.importKey("raw", key, { name: "AES-GCM" }, false, [usage]);
|
|
207
|
-
const createBeaconEncryptionKey = (randomPrivateKey = () => secp256k1.utils.
|
|
118
|
+
const createBeaconEncryptionKey = (randomPrivateKey = () => secp256k1.utils.randomSecretKey()) => {
|
|
208
119
|
const privateKey = randomPrivateKey();
|
|
209
|
-
if (!secp256k1.utils.
|
|
120
|
+
if (!secp256k1.utils.isValidSecretKey(privateKey)) throw new Error("invalid generated beacon encryption key");
|
|
210
121
|
return { privateKey, publicKey: secp256k1.getPublicKey(privateKey, true) };
|
|
211
122
|
};
|
|
212
123
|
const encryptBeaconShare = async (share, recipientPublicKey, network, epoch, sender, recipient, randomPrivateKey, randomNonce = () => globalThis.crypto.getRandomValues(new Uint8Array(12))) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { s as sha256 } from './sha2-
|
|
1
|
+
import { s as sha256 } from './sha2-BKcEJzgd.js';
|
|
2
2
|
import { t as toBase58, f as fromBase58 } from './index-CvKt4UDE.js';
|
|
3
3
|
import { deriveBeaconGroupPublicKey } from './beacon.js';
|
|
4
4
|
import { q as quorumThreshold } from './quorum-S_qdgiAY.js';
|
|
5
|
-
import './weierstrass-
|
|
5
|
+
import './weierstrass-BVfhtHbl.js';
|
|
6
6
|
|
|
7
7
|
const encoder = new TextEncoder();
|
|
8
8
|
const lengthPrefix = (bytes) => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { h as hkdf } from './hkdf-
|
|
2
|
-
import { s as sha256 } from './sha2-
|
|
1
|
+
import { h as hkdf } from './hkdf-BUHINPFj.js';
|
|
2
|
+
import { s as sha256 } from './sha2-BKcEJzgd.js';
|
|
3
3
|
import { canonicalBeaconEpochConfig, beaconEpochDigest } from './beacon-epoch.js';
|
|
4
|
+
import './weierstrass-BVfhtHbl.js';
|
|
4
5
|
import './index-CvKt4UDE.js';
|
|
5
6
|
import './beacon.js';
|
|
6
|
-
import './weierstrass-Q0QND1ZT.js';
|
|
7
7
|
import './quorum-S_qdgiAY.js';
|
|
8
8
|
|
|
9
9
|
const encoder = new TextEncoder();
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { f as fromBase58, t as toBase58 } from './index-CvKt4UDE.js';
|
|
2
2
|
import { beaconMessage, deriveBeaconPublicShare, verifyBeaconSignatureShare, reconstructBeaconSignature, verifyBeaconProof, beaconRandomness } from './beacon.js';
|
|
3
3
|
import { canonicalBeaconEpochConfig, beaconParticipants, beaconEpochGroupPublicKey } from './beacon-epoch.js';
|
|
4
|
-
import './
|
|
5
|
-
import './
|
|
4
|
+
import './sha2-BKcEJzgd.js';
|
|
5
|
+
import './weierstrass-BVfhtHbl.js';
|
|
6
6
|
import './quorum-S_qdgiAY.js';
|
|
7
7
|
|
|
8
8
|
class BeaconRound {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as signTransaction, c as MultiWallet, d as createTransactionHash } from './index-
|
|
1
|
+
import { s as signTransaction, c as MultiWallet, d as createTransactionHash } from './index-DmuI-29u.js';
|
|
2
2
|
import { f as fromBase58 } from './index-CvKt4UDE.js';
|
|
3
|
-
import './browser-crypto-
|
|
4
|
-
import './sha2-
|
|
3
|
+
import './browser-crypto-CH0ua22L.js';
|
|
4
|
+
import './sha2-BKcEJzgd.js';
|
|
5
5
|
|
|
6
6
|
const validInteger = (value, minimum = 0n) => {
|
|
7
7
|
try {
|