()
| 84 | } |
| 85 | |
| 86 | func (gh *Github) Validate() (err error) { |
| 87 | gh.Identity = strings.ToLower(gh.Identity) |
| 88 | gh.SignaturePayload = gh.GenerateSignPayload() |
| 89 | |
| 90 | client := ghub.NewClient(nil) |
| 91 | gist, response, err := client.Gists.Get(context.TODO(), gh.ProofLocation) |
| 92 | if err != nil { |
| 93 | return xerrors.Errorf("error when fetching gist: %w", err) |
| 94 | } |
| 95 | |
| 96 | if response.StatusCode != 200 { |
| 97 | return xerrors.Errorf("error when fetching gist") |
| 98 | } |
| 99 | |
| 100 | if gh.Identity != gist.Owner.GetLogin() { |
| 101 | return xerrors.Errorf("gist owner mismatch: should be %s, but got %s", gh.Identity, gist.Owner.GetLogin()) |
| 102 | } |
| 103 | gh.AltID = strconv.FormatInt(gist.Owner.GetID(), 10) |
| 104 | |
| 105 | gist_filename := fmt.Sprintf("0x%s.json", crypto.CompressedPubkeyHex(gh.Pubkey)) |
| 106 | files := gist.GetFiles() |
| 107 | content := "" |
| 108 | for filename, file := range files { |
| 109 | if filename != ghub.GistFilename(gist_filename) { |
| 110 | continue |
| 111 | } |
| 112 | |
| 113 | content = *file.Content |
| 114 | } |
| 115 | if content == "" { |
| 116 | return xerrors.Errorf("%s not found or empty", gist_filename) |
| 117 | } |
| 118 | payload := gistPayload{} |
| 119 | err = json.Unmarshal([]byte(content), &payload) |
| 120 | if err != nil { |
| 121 | return xerrors.Errorf("error when parsing JSON: %w", err) |
| 122 | } |
| 123 | |
| 124 | pubkey_recovered, err := crypto.StringToPubkey(payload.Persona) |
| 125 | if err != nil { |
| 126 | return xerrors.Errorf("error when recovering pubkey: %w", err) |
| 127 | } |
| 128 | signature, err := util.DecodeString(payload.Signature) |
| 129 | if err != nil { |
| 130 | return xerrors.Errorf("error when decoding signature: %w", err) |
| 131 | } |
| 132 | return crypto.ValidatePersonalSignature(payload.SignPayload, signature, pubkey_recovered) |
| 133 | } |
nothing calls this directly
no test coverage detected