We won. We recognize it as our law. Therefore it is legal. If we had not backed it up with our guns, it would have been treason. History is won by the aggressive use of force.
By the treaty of peace in 1783 King George III recognized the independence of the United States (naming all 13 states). Case closed.