Skip to content

Commit

Permalink
generate 64 character hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
callebtc committed Nov 29, 2023
1 parent 83b1693 commit a84cc18
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/CashuWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
getDefaultAmountPreference,
splitAmount
} from './utils.js';
import { bytesToHex } from '@noble/curves/abstract/utils';

/**
* Class that represents a Cashu wallet.
Expand Down Expand Up @@ -424,7 +425,7 @@ class CashuWallet {
const rs: Array<bigint> = [];
const amounts = splitAmount(amount, amountPreference);
for (let i = 0; i < amounts.length; i++) {
const secret = randomBytes(32);
const secret = new TextEncoder().encode(bytesToHex(randomBytes(32)));
secrets.push(secret);
const { B_, r } = dhke.blindMessage(secret);
rs.push(r);
Expand All @@ -446,7 +447,7 @@ class CashuWallet {
const rs: Array<bigint> = [];
const count = Math.ceil(Math.log2(feeReserve)) || 1;
for (let i = 0; i < count; i++) {
const secret = randomBytes(32);
const secret = new TextEncoder().encode(bytesToHex(randomBytes(32)));
secrets.push(secret);
const { B_, r } = dhke.blindMessage(secret);
rs.push(r);
Expand Down
4 changes: 2 additions & 2 deletions src/DHKE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function pointFromHex(hex: string) {
return secp256k1.ProjectivePoint.fromAffine(h2c.toAffine());
} */
function blindMessage(secret: Uint8Array, r?: bigint): { B_: ProjPointType<bigint>; r: bigint } {
const secretMessage = new TextEncoder().encode(bytesToHex(secret));
const secretMessage = new TextEncoder().encode(new TextDecoder().decode(secret));
const Y = hashToCurve(secretMessage);
if (!r) {
r = bytesToNumber(secp256k1.utils.randomPrivateKey());
Expand Down Expand Up @@ -55,7 +55,7 @@ function constructProofs(
const C_ = pointFromHex(p.C_);
const A = pointFromHex(keyset.keys[p.amount]);
const C = unblindSignature(C_, rs[i], A);
const secret = bytesToHex(secrets[i])
const secret = new TextDecoder().decode(secrets[i])
const proof = {
id: p.id,
amount: p.amount,
Expand Down

0 comments on commit a84cc18

Please sign in to comment.