The Book of Mormon clearly teaches that baptism is to be understood as a covenant. For example in speaking of Jesus’ baptism, Nephi says in 2 Nephi 31:7
Know ye not that he was holy? But notwithstanding he being holy, he showeth unto the children of men that, according to the flesh he humbleth himself before the Father, and witnesseth unto the Father that he would be obedient unto him in keeping his commandments.
Noel Reynolds remarks:
Latter-day Saint discourse has long featured and benefited from two different New Testament metaphors in explaining and understanding water baptism. The first is the near universal insight used widely by Christians and pagans alike that washing in water can signify spiritual purification, a washing away of sin or contamination (see Acts 22:15–16, “For thou shalt be his witness unto all men of what thou has seen and heard. And now why tarriest thou? arise, and be baptized, and wash away thy sins, calling on the name of the Lord”). The second is the more specifically Christian insight of Paul that immersion in water can represent the burial and resurrection of Jesus Christ (see Rom. 6:4, “Therefore we are buried with him by baptism into death: that like as Christ was raised up from the dead by the glory of the Father, even so we also should walk in newness of life”). What seems to have gone largely unnoticed in LDS discourse is that discussions of baptism in the Book of Mormon offer instead a third understanding of baptism: that baptism is a witnessing to God of one’s repentance and commitment to follow Jesus Christ– Noel Reynolds – Understanding Christian Baptism through the Book of Mormon
Recent biblical scholarship has shown that baptism is indeed to be understood as a contract with God or a pledge of faithfulness. Noel Reynolds continues:
the most thorough and recent historical scholarship identifies very early Christian teachings and practices that strongly suggest their earliest formulation may well have been identical with those found in the Book of Mormon.– Noel Reynolds – Understanding Christian Baptism through the Book of Mormon
Where would Joseph Smith have gotten this idea about baptism if it has only been brought to light recently?