aptok/verify.go

55 lines
1.6 KiB
Go
Raw Normal View History

2024-08-18 15:21:24 +03:00
package main
import (
2024-09-08 16:28:55 +03:00
"crypto/ed25519"
"crypto/sha256"
"encoding/json"
"fmt"
"github.com/btcsuite/btcutil/base58"
2024-09-08 19:01:18 +03:00
"place.re128.org/ofs/aptok"
2024-09-08 16:28:55 +03:00
// "crypto"
2024-08-18 15:21:24 +03:00
)
2024-08-18 15:24:34 +03:00
2024-09-08 16:28:55 +03:00
func main() {
actor, err := activityserve.LoadActor("ED4xVR2hw6frfBNFJataKYZn58WnaotS8d8WKg4H5rfC")
if err != nil {
fmt.Println(err)
}
activityserve.Setup("config.ini", false)
// rActor, err := activityserve.NewRemoteActor(actor, "https://mitra.social/.well-known/apgateway/did:key:z6MknVmyPtQmD2SaGnqyGgTVEqfqkkJJnY3YVKBmbzSUNCcX/actor")
rActor, err := activityserve.NewRemoteActor(actor, "http://localhost:8000/silverpill.json")
if err != nil {
fmt.Println(err)
}
ractorRaw := rActor.GetRaw()
proof := ractorRaw["proof"].(map[string]interface{})
delete(ractorRaw, "proof")
ractorJson, err := json.Marshal(ractorRaw)
if err != nil {
fmt.Println(err)
}
ractorJsonString := string(ractorJson)
hashActor := sha256.New()
hashActor.Write([]byte(ractorJsonString))
hashActorRes := hashActor.Sum(nil)
2024-08-18 15:21:24 +03:00
2024-09-08 16:28:55 +03:00
verificationMethod := proof["verificationMethod"].(string)
proofValue := proof["proofValue"].(string)[0:]
2024-08-18 15:21:24 +03:00
2024-09-08 16:28:55 +03:00
proofValueDecoded := base58.Decode(proofValue)
proofValueStripped := proofValueDecoded[2:]
publicKeyDecoded := base58.Decode(verificationMethod[9:])
publicKeyDecoded32 := publicKeyDecoded[2:]
// publicKey := ed25519.PublicKey(publicKeyDecoded32)
// fmt.Println(publicKey)
fmt.Println(publicKeyDecoded32)
fmt.Println(hashActorRes)
fmt.Println(proofValueStripped)
err = ed25519.VerifyWithOptions(publicKeyDecoded32, hashActorRes, proofValueStripped, &ed25519.Options{
Hash: 0,
})
if err != nil {
fmt.Println(err)
}
2024-08-18 15:24:34 +03:00
}