Skip to content

Instantly share code, notes, and snippets.

View KunalKumarSwift's full-sized avatar
💭
I may be slow to respond.

Kunal Kumar KunalKumarSwift

💭
I may be slow to respond.
View GitHub Profile
import Foundation
class APIManager {
static let shared = APIManager()
private let baseURL = "http://localhost:3000" // Replace with your server's URL
/// Fetches a challenge from the server
func fetchChallenge(completion: @escaping (Result<(String, String), Error>) -> Void) {
guard let url = URL(string: "\(baseURL)/generate-challenge") else { return }
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const cbor = require('cbor');
const app = express();
app.use(bodyParser.json());
// Apple's App Attest root certificate (replace with actual PEM format certificate)
const APPLE_ROOT_CERT_PEM = `
const cbor = require('cbor');
// Example base64-encoded attestation object (replace with your actual data)
const base64AttestationObject = "your_base64_encoded_attestation_object";
// Decode the Base64 string into a buffer
const attestationBuffer = Buffer.from(base64AttestationObject, 'base64');
// Decode the CBOR object
cbor.decodeFirst(attestationBuffer)

To get the APPLE_PRIVATE_KEY for app attestation, you'll need to follow these steps in your Apple Developer account:

Go to Apple Developer Portal

Visit https://developer.apple.com Sign in with your Apple Developer account Click on "Certificates, Identifiers & Profiles"

Create a new key:

APPLE_TEAM_ID=your_team_id
APPLE_KEY_ID=your_key_id
APPLE_PRIVATE_KEY=-----BEGIN PRIVATE KEY-----\nYour Private Key Here\n-----END PRIVATE KEY-----
const express = require("express");
const fetch = require("node-fetch");
const jwt = require("jsonwebtoken");
const app = express();
const port = 9000;
// Apple's attestation API endpoint (using development endpoint)
const APPLE_ATTESTATION_API =
"https://api.development.devicecheck.apple.com/v1/validate_device_token";
// For production use: https://api.devicecheck.apple.com/v1/validate_device_token
import DeviceCheck
import CryptoKit
class AppAttestationService {
private let dcAppAttestService = DCAppAttestService.shared
// Update to your local machine's IP address - don't use localhost since iOS simulator/device
// needs to reach your computer's actual IP
private let serverURL = URL(string: "http://192.168.1.X:3000/verify-attestation")!
func performAttestation() async throws {
{
"public_identifier":"kunalkumar91",
"profile_pic_url":"None",
"background_cover_image_url":"https://media.licdn.com/dms/image/v2/D5616AQFZv7evcAE94A/profile-displaybackgroundimage-shrink_350_1400/profile-displaybackgroundimage-shrink_350_1400/0/1716177983373?e=1737590400&v=beta&t=SmnAGatxJRpbCRbSFhYCp5POxlxRE25CBX5iYWZTq2g",
"first_name":"Kunal",
"last_name":"Kumar",
"full_name":"Kunal Kumar",
"follower_count":1048,
"occupation":"Software Architect at Scotiabank Digital Factory",
"headline":"Software Architect at Scotiabank Digital Factory | Ex-Accenture | Transforming ideas into MVPs 💡📈",
var n = 8
var row = 2 * n - 1
for i in 1...n {
for j in 1...row {
let lowerRange = n-(i-1)
let upperRange = n+(i-1)
if j < lowerRange {
print(" ", terminator: " ")