|
1 | 1 | import { FleetError, _0n, concatBytes } from "@fleet-sdk/common"; |
2 | | -import { |
3 | | - bigintBE, |
4 | | - blake2b256, |
5 | | - hex, |
6 | | - randomBytes, |
7 | | - validateEcPoint, |
8 | | -} from "@fleet-sdk/crypto"; |
| 2 | +import { bigintBE, blake2b256, hex, randomBytes, validateEcPoint } from "@fleet-sdk/crypto"; |
9 | 3 | import { secp256k1 } from "@noble/curves/secp256k1"; |
10 | 4 |
|
11 | 5 | const { ProjectivePoint: ECPoint, CURVE } = secp256k1; |
@@ -43,10 +37,7 @@ export function sign(message: Uint8Array, secretKey: Uint8Array) { |
43 | 37 | * @returns The generated signature as a Uint8Array, or undefined if the verification fails. |
44 | 38 | * @throws Error if failed to generate commitment. |
45 | 39 | */ |
46 | | -export function genSignature( |
47 | | - message: Uint8Array, |
48 | | - secretKey: Uint8Array, |
49 | | -): undefined | Uint8Array { |
| 40 | +export function genSignature(message: Uint8Array, secretKey: Uint8Array): undefined | Uint8Array { |
50 | 41 | const sk = bigintBE.encode(secretKey); |
51 | 42 | const pk = G.multiply(sk).toRawBytes(); |
52 | 43 | const k = genRandomSecret(); |
@@ -107,18 +98,12 @@ export function umod(a: bigint, b: bigint): bigint { |
107 | 98 | * @returns A boolean indicating whether the signature is valid or not. |
108 | 99 | * @throws FleetError if the public key is invalid. |
109 | 100 | */ |
110 | | -export function verify( |
111 | | - message: Uint8Array, |
112 | | - proof: Uint8Array, |
113 | | - publicKey: Uint8Array, |
114 | | -) { |
| 101 | +export function verify(message: Uint8Array, proof: Uint8Array, publicKey: Uint8Array) { |
115 | 102 | if (!proof || proof.length !== ERGO_SCHNORR_SIG_LEN) return false; |
116 | 103 | if (!validateEcPoint(publicKey)) throw new FleetError("Invalid Public Key."); |
117 | 104 |
|
118 | 105 | const c = bigintBE.encode(proof.slice(0, ERGO_SOUNDNESS_BYTES)); |
119 | | - const z = bigintBE.encode( |
120 | | - proof.slice(ERGO_SOUNDNESS_BYTES, ERGO_SCHNORR_SIG_LEN), |
121 | | - ); |
| 106 | + const z = bigintBE.encode(proof.slice(ERGO_SOUNDNESS_BYTES, ERGO_SCHNORR_SIG_LEN)); |
122 | 107 |
|
123 | 108 | const t = ECPoint.fromHex(publicKey).multiply(CURVE.n - c); |
124 | 109 | const w = G.multiply(z).add(t).toRawBytes(); |
|
0 commit comments