Created
August 15, 2023 15:50
-
-
Save Rigidity/f4b7ffc76990acbf10337d1ba45eb56f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { AugSchemeMPL, JacobianPoint } from 'chia-bls'; | |
import { Program } from 'clvm-lib'; | |
const standardTransaction = Program.deserializeHex( | |
'ff02ffff01ff02ffff03ff0bffff01ff02ffff03ffff09ff05ffff1dff0bffff1effff0bff0bffff02ff06ffff04ff02ffff04ff17ff8080808080808080ffff01ff02ff17ff2f80ffff01ff088080ff0180ffff01ff04ffff04ff04ffff04ff05ffff04ffff02ff06ffff04ff02ffff04ff17ff80808080ff80808080ffff02ff17ff2f808080ff0180ffff04ffff01ff32ff02ffff03ffff07ff0580ffff01ff0bffff0102ffff02ff06ffff04ff02ffff04ff09ff80808080ffff02ff06ffff04ff02ffff04ff0dff8080808080ffff01ff0bffff0101ff058080ff0180ff018080' | |
); | |
const syntheticPublicKey = Program.deserializeHex( | |
'ff1dff02ffff1effff0bff02ff05808080' | |
); | |
const defaultHiddenPuzzleHash = Program.deserializeHex('ff0980').hash(); | |
export function getWalletPuzzle( | |
publicKey: JacobianPoint, | |
index: number | |
): Program { | |
return standardTransaction.curry([ | |
Program.fromJacobianPoint( | |
calculateSyntheticPublicKey(derivePublicKey(publicKey, index)) | |
), | |
]); | |
} | |
export function calculateSyntheticPublicKey( | |
publicKey: JacobianPoint, | |
hiddenPuzzleHash: Uint8Array = defaultHiddenPuzzleHash | |
): JacobianPoint { | |
return JacobianPoint.fromBytes( | |
syntheticPublicKey.run( | |
Program.fromList([ | |
Program.fromJacobianPoint(publicKey), | |
Program.fromBytes(hiddenPuzzleHash), | |
]) | |
).value.atom, | |
false | |
); | |
} | |
export function derivePublicKeyPath( | |
publicKey: JacobianPoint, | |
path: number[] | |
): JacobianPoint { | |
for (const index of path) | |
publicKey = AugSchemeMPL.deriveChildPkUnhardened(publicKey, index); | |
return publicKey; | |
} | |
export function derivePublicKey( | |
masterPublicKey: JacobianPoint, | |
index: number | |
): JacobianPoint { | |
return derivePublicKeyPath(masterPublicKey, [12381, 8444, 2, index]); | |
} | |
// Get first address's puzzle, then call .hashHex() or .hash() and convert to bech32m | |
getWalletPuzzle(JacobianPoint.fromHexG1("master pubkey"), 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment