Skip to content

Commit

Permalink
Reproduce actual behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Aug 28, 2024
1 parent 80f10b1 commit dd72e66
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"astro": "^4.14.6",
"bech32": "^2.0.0",
"chia-bls": "^1.0.2",
"clvm-lib": "^1.0.1",
"react": "^18.3.1",
"react-dom": "^18.3.1"
}
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 56 additions & 2 deletions src/components/Main.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { bech32m } from "bech32";
import bls from "chia-bls";
import clvm from "clvm-lib";
import { useState } from "react";

const { AugSchemeMPL, JacobianPoint } = bls;
const { AugSchemeMPL, JacobianPoint, PrivateKey, bigIntToBytes, hash256 } = bls;
const { Program } = clvm;

export default function Main() {
const [m, setM] = useState("");
Expand All @@ -27,11 +29,63 @@ export default function Main() {
);
}

function pathInto(pk, nums) {
for (const num of nums) {
pk = AugSchemeMPL.deriveChildPkUnhardened(pk, num);
}
return pk;
}

const groupOrder =
0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001n;

const defaultHidden = Program.deserializeHex("ff0980").hash();

export function calculateSyntheticPublicKey(publicKey, hiddenPuzzleHash) {
return JacobianPoint.fromBytes(
Program.deserializeHex("ff1dff02ffff1effff0bff02ff05808080").run(
Program.fromList([
Program.fromJacobianPoint(publicKey),
Program.fromBytes(hiddenPuzzleHash),
])
).value.atom,
false
);
}

export function calculateSyntheticPrivateKey(privateKey, hiddenPuzzleHash) {
const privateExponent = bytesToBigInt(privateKey.toBytes(), "big");
const publicKey = privateKey.getG1();
const syntheticOffset = calculateSyntheticOffset(publicKey, hiddenPuzzleHash);
const syntheticPrivateExponent = mod(
privateExponent + syntheticOffset,
groupOrder
);
const blob = bigIntToBytes(syntheticPrivateExponent, 32, "big");
return PrivateKey.fromBytes(blob);
}

export function calculateSyntheticOffset(publicKey, hiddenPuzzleHash) {
const blob = hash256(concatBytes(publicKey.toBytes(), hiddenPuzzleHash));
return mod(decodeBigInt(blob), groupOrder);
}

function calc(hex) {
try {
const key = JacobianPoint.fromHexG1(hex.replace("0x", ""));
const address = toAddress(
AugSchemeMPL.deriveChildPkUnhardened(key, 0).toBytes(),
Program.deserializeHex(
"ff02ffff01ff02ffff03ff0bffff01ff02ffff03ffff09ff05ffff1dff0bffff1effff0bff0bffff02ff06ffff04ff02ffff04ff17ff8080808080808080ffff01ff02ff17ff2f80ffff01ff088080ff0180ffff01ff04ffff04ff04ffff04ff05ffff04ffff02ff06ffff04ff02ffff04ff17ff80808080ff80808080ffff02ff17ff2f808080ff0180ffff04ffff01ff32ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff06ffff04ff02ffff04ff09ff80808080ffff02ff06ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080"
)
.curry([
Program.fromJacobianPoint(
calculateSyntheticPublicKey(
pathInto(key, [12381, 8444, 2, 0]),
defaultHidden
)
),
])
.hash(),
"bls1238"
);
return address;
Expand Down

0 comments on commit dd72e66

Please sign in to comment.