Bitcoin/address validation: Difference between revisions
Content deleted Content added
Update Seed7 example |
Update Seed7 example to define the function validBitcoinAddress |
||
Line 1,982: | Line 1,982: | ||
include "encoding.s7i"; |
include "encoding.s7i"; |
||
const |
const func boolean: validBitcoinAddress (in string: address) is func |
||
result |
|||
⚫ | |||
local |
local |
||
var string: decoded is ""; |
var string: decoded is ""; |
||
⚫ | |||
begin |
begin |
||
if |
if succeeds(decoded := fromBase58(address)) and |
||
⚫ | |||
state := "bad char"; |
|||
sha256(sha256(decoded[.. 21]))[.. 4] = decoded[22 ..] then |
|||
isValid := TRUE; |
|||
⚫ | |||
state := "not version 0"; |
|||
elsif sha256(sha256(decoded[.. 21]))[.. 4] <> decoded[22 ..] then |
|||
state := "bad digest"; |
|||
end if; |
end if; |
||
end func; |
|||
⚫ | |||
⚫ | |||
const proc: checkValidationFunction (in string: address, in boolean: expected) is func |
|||
⚫ | |||
local |
|||
var boolean: isValid is FALSE; |
|||
begin |
|||
isValid := validBitcoinAddress(address); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end if; |
end if; |
||
end func; |
end func; |
||
Line 2,004: | Line 2,008: | ||
const proc: main is func |
const proc: main is func |
||
begin |
begin |
||
checkValidationFunction("1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9", TRUE); # okay |
|||
checkValidationFunction("1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9", FALSE); # bad digest |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", TRUE); # okay |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62j", FALSE); # bad digest |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62X", FALSE); # bad digest |
|||
checkValidationFunction("1ANNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", FALSE); # bad digest |
|||
checkValidationFunction("oMRDCDfyQhEerkaSmwCfSPqf3MLgBwNvs", FALSE); # not version 0 |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62iz", FALSE); # wrong length |
|||
checkValidationFunction("1BGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", FALSE); # bad digest |
|||
checkValidationFunction("1A Na15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", FALSE); # bad char |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I", FALSE); # bad char |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62!", FALSE); # bad char |
|||
checkValidationFunction("1AGNa15ZQXAZUgFiqJ3i7Z2DPU2J6hW62i", FALSE); # bad digest |
|||
checkValidationFunction("1111111111111111111114oLvT2", TRUE); # okay |
|||
checkValidationFunction("17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j", TRUE); # okay |
|||
checkValidationFunction("1badbadbadbadbadbadbadbadbadbadbad", FALSE); # wrong length |
|||
checkValidationFunction("BZbvjr", FALSE); # wrong length |
|||
checkValidationFunction("i55j", FALSE); # wrong length |
|||
checkValidationFunction("16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM", TRUE); # okay |
|||
end func;</lang> |
end func;</lang> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9: |
1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9: TRUE |
||
1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9: |
1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nJ9: FALSE |
||
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: |
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: TRUE |
||
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62j: |
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62j: FALSE |
||
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62X: |
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62X: FALSE |
||
1ANNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: |
1ANNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: FALSE |
||
oMRDCDfyQhEerkaSmwCfSPqf3MLgBwNvs: |
oMRDCDfyQhEerkaSmwCfSPqf3MLgBwNvs: FALSE |
||
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62iz: |
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62iz: FALSE |
||
1BGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: |
1BGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: FALSE |
||
1A Na15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: |
1A Na15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i: FALSE |
||
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I: |
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62I: FALSE |
||
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62!: |
1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62!: FALSE |
||
1AGNa15ZQXAZUgFiqJ3i7Z2DPU2J6hW62i: |
1AGNa15ZQXAZUgFiqJ3i7Z2DPU2J6hW62i: FALSE |
||
1111111111111111111114oLvT2: |
1111111111111111111114oLvT2: TRUE |
||
17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j: |
17NdbrSGoUotzeGCcMMCqnFkEvLymoou9j: TRUE |
||
1badbadbadbadbadbadbadbadbadbadbad: |
1badbadbadbadbadbadbadbadbadbadbad: FALSE |
||
BZbvjr: |
BZbvjr: FALSE |
||
i55j: |
i55j: FALSE |
||
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM: |
16UwLL9Risc3QfPqBUvKofHmBQ7wMtjvM: TRUE |
||
</pre> |
</pre> |
||