svanas / delphereum

web3 implementation for the Delphi programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BIP 39 test for BIP 32 some remarks

PieterValentijn opened this issue · comments

Ok so i have been able to get the BIP 32 going now but i found some issues.
unit web3.bip39;

class function TMnemonic.sha256(const input: TBytes): TBytes;

writes one byte less of the input due to the use of High.

stream.Write(input, High(input)+1);

Im for moving this function tot he tools unit as i need it also in bip 32.

If you change this then you must also change the
constructor TMnemonic.Create(entropy: TBytes);
begin
// checksum is the 1st byte of the SHA256 digest
const checksum = TMnemonic.sha256(entropy)[0];
where the checksum should be calculated before the
// reserve 1 extra byte for the checksum
SetLength(entropy, Length(entropy) + 1);

For BIP 32 i will also need the
HMAC_SHA512 maby that can be added to tools aswell.
Maby for the sake of simplicity also add these functions.

function b58decode(InStr: String): Tbytes;
var
ab: IBase58;
begin
ab := TBase58.Create(TBase58Alphabet.BitCoin);
result := ab.Decode(InStr);
end;

function b58encode(Bytes: Tbytes): String;
var
ab: IBase58;
begin
ab := TBase58.Create(TBase58Alphabet.BitCoin);
result := ab.Encode(Bytes);
end;