Skip to content

Instantly share code, notes, and snippets.

View SpaceboatDVLP's full-sized avatar
💭
It's lit

Spaceboat Development SpaceboatDVLP

💭
It's lit
View GitHub Profile
@SpaceboatDVLP
SpaceboatDVLP / SquareWebhookVerification.swift
Created April 20, 2022 22:29
Verify a Square Webhook Signature in Vapor 4.0
func validSquareSignature(req: Request) -> Bool {
guard let headerSignature: String = req.headers["x-square-signature"].first else { return false }
guard let urlData = "my webhook url".data(using: .utf8) else { return false }
guard let bodyData = req.body.string?.replacingOccurrences(of: " ", with: "").replacingOccurrences(of: "\n", with: "").data(using: .utf8) else { return false }
let payload = urlData + bodyData
var hmac = HMAC<Insecure.SHA1>(key: SymmetricKey(data: EnvVars.squareSig.data(using: .utf8) ?? Data()))
hmac.update(data: payload)
let mac = Data(hmac.finalize()).base64EncodedString()
return mac == headerSignature;
}

Keybase proof

I hereby claim:

  • I am spaceboatdvlp on github.
  • I am looney (https://keybase.io/looney) on keybase.
  • I have a public key ASA6HgV72uvd73puzqS9jomIYMO-kKh6rgwL761r6Hypfgo

To claim this, I am signing this object:

@SpaceboatDVLP
SpaceboatDVLP / ModelController.swift
Last active January 11, 2019 18:48
This is boilerplate for a static UIPageViewController built using Interface Builder. View Controllers are initialized in the IB with storyboard identifiers names as "Page" + PageNumber + "Controller". In this snippet, there are 3 view controllers in storyboard that correspond to pages (note the pageCount variable in ModelController).
//
// ModelController.swift
// PageViewShenanigans
//
// Created by Steve Looney on 9/7/17.
// Copyright © 2017 Spaceboat Development, LLC. All rights reserved.
//
import UIKit