Files
osiris/examples/freezone/freezone.rhai
Timur Gordon 87c556df7a wip
2025-10-29 16:52:33 +01:00

366 lines
14 KiB
Plaintext

// ============================================================================
// FREEZONE REGISTRATION FLOW
// ============================================================================
// Complete registration flow for new freezone members including:
// 0. Freezone initialization and configuration
// 1. Public key registration
// 2. User profile creation & email verification
// 3. Terms & Conditions signing
// 4. Crypto wallet creation (TFT + ETH)
// 5. Payment processing
// 6. KYC verification with info collection
print("=== FREEZONE REGISTRATION FLOW ===\n");
// ============================================================================
// KEYPAIRS AND IDENTITIES
// ============================================================================
// Freezone Organization (Keypair 1)
let freezone_pubkey = "04d0aea7f0a48bcab4389753ddc2e61623dd89d800652b11d0a383eb3ea74561d730bdd06e0ca8f4cd4013907d95782a0a584313e1d91ae5ad09b663de36bfac44";
// User: Timur (Keypair 2)
let timur_pubkey = "04090636d0a15854c4c0b73f65b6de5f6a27a7b22d6fbf5f6d97c45476a0384fe50781444c33f5af577e017599e4b432373fbcdcd844d8783c5e52240a14b63dc3";
print("Identities:");
print(" Freezone: " + freezone_pubkey);
print(" Timur: " + timur_pubkey);
print();
// ============================================================================
// INITIALIZATION: Freezone Configuration
// ============================================================================
print("Initialization: Freezone Configuration");
print("─────────────────────────────────────────────────────────────");
// Create context with freezone as the signatory
let freezone_ctx = get_context([freezone_pubkey]);
print("✓ Freezone context created");
print(" Context ID: " + freezone_ctx.context_id());
print(" Signatory: Freezone (" + freezone_pubkey + ")");
// Configure Email Client
print("\nConfiguring Email Client...");
let freezone_email_client = new_email_client()
.smtp_host("smtp.freezone.example")
.smtp_port(587)
.from_email("noreply@freezone.example")
.from_name("Freezone Platform");
print("✓ Email client configured");
print(" SMTP Host: smtp.freezone.example");
print(" From: noreply@freezone.example");
// Configure Payment Provider (Pesapal)
print("\nConfiguring Payment Provider...");
let freezone_payment_client = new_payment_client_pesapal_sandbox(
1,
"qkio1BGGYAXTu2JOfm7XSXNruoZsrqEW",
"osGQ364R49cXKeOYSpaOnT++rHs="
);
print("✓ Payment provider configured (Pesapal Sandbox)");
print(" Provider: Pesapal");
print(" Environment: Sandbox");
// Configure KYC Provider
print("\nConfiguring KYC Provider...");
print("✓ KYC provider configured");
print(" Provider: Freezone KYC");
print(" Callback URL: https://freezone.example/kyc/callback");
// Create Freezone's own Ethereum wallet
print("\nCreating Freezone Ethereum Wallet...");
let freezone_eth_wallet = new_ethereum_wallet()
.owner_id(999) // Freezone organization ID
.network("mainnet");
print("✓ Freezone Ethereum wallet created");
print(" Address: " + freezone_eth_wallet.get_address());
print(" Network: " + freezone_eth_wallet.get_network());
print(" Owner: Freezone Organization (ID: 999)");
// Save Freezone's Ethereum account
let freezone_eth_account = new_account()
.owner_id(999)
.address(freezone_eth_wallet.get_address())
.currency("ETH")
.balance(0.0);
freezone_ctx.save(freezone_eth_account);
print("✓ Freezone Ethereum account saved");
print("\n✓ Freezone initialization complete\n");
// ============================================================================
// STEP 0: Registration Flow Setup
// ============================================================================
print("Step 0: Registration Flow Setup");
print("─────────────────────────────────────────────────────────────");
// Define registration flow steps
print("\nRegistration Flow Steps:");
print(" 1. Public key registration");
print(" 2. User profile creation & email verification");
print(" 3. Terms & Conditions signing");
print(" 4. Crypto wallet creation (TFT + ETH)");
print(" 5. Payment processing");
print(" 6. KYC verification with info collection");
print();
// ============================================================================
// STEP 1: Public Key Registration
// ============================================================================
print("Step 1: Public Key Registration");
print("─────────────────────────────────────────────────────────────");
// User (Timur) provides their public key
print("User public key received: " + timur_pubkey);
print("✓ Public key validated and stored\n");
// ============================================================================
// STEP 2: User Profile Creation & Email Verification
// ============================================================================
print("Step 2: User Profile Creation & Email Verification");
print("─────────────────────────────────────────────────────────────");
// Collect basic user information
let user_name = "Timur Gordon";
let user_email = "timur@freezone.example";
print("Collecting user information:");
print(" Name: " + user_name);
print(" Email: " + user_email);
// Create user profile
let user_profile = new_user()
.username(user_name)
.pubkey(timur_pubkey)
.add_email(user_email);
print("✓ User profile created");
freezone_ctx.save(user_profile);
print("✓ Profile saved");
// Email Verification
print("\nInitiating email verification...");
let verification = new_verification("user_1", user_email);
print("✓ Email verification created");
print(" Verification code: " + verification.get_code());
print(" Nonce: " + verification.get_nonce());
// Prepare verification email
let verification_link = "https://freezone.example/verify?nonce=" + verification.get_nonce();
print(" Verification link: " + verification_link);
print(" (Email sent to: " + user_email + ")");
// Simulate user clicking verification link and verifying
print("\n✓ User clicks verification link and verifies email");
verification.verify_nonce(verification.get_nonce());
print("✓ Email verified: " + verification.get_status());
freezone_ctx.save(verification);
print("✓ Verification saved\n");
// ============================================================================
// STEP 3: Terms & Conditions Signing
// ============================================================================
print("Step 3: Terms & Conditions Signing");
print("─────────────────────────────────────────────────────────────");
// Create Terms & Conditions contract
let terms_contract = new_contract(1)
.title("Freezone Membership Terms & Conditions")
.content("By signing this agreement, you agree to abide by all freezone rules and regulations...")
.creator_id(999); // Freezone admin
print("✓ Terms & Conditions contract created");
print(" Title: " + terms_contract.title());
// User signs the contract (add their signature ID)
let user_signature_id = 1001;
terms_contract = terms_contract.add_signature(user_signature_id);
print("✓ User signature added (ID: " + user_signature_id + ")");
// Activate contract once signed
if terms_contract.is_fully_signed(1) {
terms_contract = terms_contract.activate();
print("✓ Contract activated: " + terms_contract.status());
}
freezone_ctx.save(terms_contract);
print("✓ Signed contract saved\n");
// ============================================================================
// STEP 4: Crypto Wallet Creation
// ============================================================================
print("Step 4: Crypto Wallet Creation");
print("─────────────────────────────────────────────────────────────");
// Create TFT crypto account for user
let tft_account = new_account()
.owner_id(1)
.currency("TFT") // ThreeFold Token
.balance(0.0);
print("✓ TFT account created");
print(" Owner ID: 1");
print(" Currency: TFT");
print(" Initial balance: 0");
freezone_ctx.save(tft_account);
// Create Ethereum wallet for user
print("\nCreating Ethereum wallet...");
let eth_wallet = new_ethereum_wallet()
.owner_id(1)
.network("mainnet");
print("✓ Ethereum wallet created");
print(" Address: " + eth_wallet.get_address());
print(" Network: mainnet");
print(" Balance: 0 ETH");
// Save as account
let eth_account = new_account()
.owner_id(1)
.address(eth_wallet.get_address())
.currency("ETH")
.balance(0.0);
freezone_ctx.save(eth_account);
print("✓ Ethereum account saved\n");
// ============================================================================
// STEP 5: Payment Processing
// ============================================================================
print("Step 5: Payment Processing");
print("─────────────────────────────────────────────────────────────");
print("Using configured Pesapal payment client...");
// Create payment request for registration fee
print("\nCreating payment session...");
let payment_request = new_payment_request()
.amount(100.0)
.currency("USD")
.description("Freezone Registration Fee")
.callback_url("https://freezone.example/payment/callback")
.merchant_reference("REG_USER_1_" + timestamp());
print("✓ Payment request created");
print(" Amount: $100 USD");
print(" Description: Freezone Registration Fee");
// Initiate payment with Pesapal (this would return a payment URL)
print("\nInitiating payment session with Pesapal...");
print(" Payment URL: https://pay.pesapal.com/iframe/PesapalIframe3/Index/?OrderTrackingId=abc123");
print(" (User would be redirected to Pesapal payment page)");
// Simulate user completing payment
print("\n✓ User clicks payment link and completes payment");
print(" Payment Status: COMPLETED");
print(" Transaction ID: TXN_" + timestamp());
// Create payment transaction record
let payment_tx = new_transaction()
.source(0) // External payment
.destination(1) // Freezone account
.amount(100.0)
.assetid(1);
print("✓ Payment transaction recorded");
freezone_ctx.save(payment_tx);
print("✓ Transaction saved\n");
// ============================================================================
// STEP 6: KYC Verification
// ============================================================================
print("Step 6: KYC Verification");
print("─────────────────────────────────────────────────────────────");
// Create KYC session
let kyc_session = new_kyc_session("user_1", "freezone_kyc")
.callback_url("https://freezone.example/kyc/callback")
.success_url("https://freezone.example/kyc/success")
.error_url("https://freezone.example/kyc/error");
print("✓ KYC session created");
print(" Client ID: " + kyc_session.get_client_id());
print(" Provider: " + kyc_session.get_provider());
// Generate KYC verification URL
print("\nKYC Verification URL generated:");
print(" https://kyc.provider.com/verify?session=kyc_session_" + timestamp());
print(" (User would be redirected to KYC provider)");
// Simulate user clicking KYC link and completing verification
print("\n✓ User clicks KYC link and completes verification");
print(" - Uploads identity document (Passport)");
print(" - Takes selfie for liveness check");
print(" - Provides address proof");
// Simulate KYC callback with verification results
print("\n✓ KYC Provider callback received:");
print(" - Identity verification: PASSED");
print(" - Liveness check: PASSED");
print(" - Address verification: PASSED");
print(" - Sanctions screening: CLEAR");
print(" - PEP check: NOT FOUND");
print(" - Overall Status: VERIFIED");
// Create KYC info with verified data from callback
print("\nStoring verified KYC information...");
let kyc_info_verified = new_kyc_info()
.first_name("Timur")
.last_name("Gordon")
.email(user_email)
.phone("+1-555-0123")
.country("US")
.date_of_birth("1990-05-15")
.document_type("passport")
.document_number("P123456789")
.verified(true);
freezone_ctx.save(kyc_info_verified);
freezone_ctx.save(kyc_session);
print("✓ KYC verification data saved");
print("✓ KYC verification completed\n");
// ============================================================================
// SUMMARY
// ============================================================================
print("═══════════════════════════════════════════════════════════════");
print("REGISTRATION COMPLETE");
print("═══════════════════════════════════════════════════════════════");
print("\nUser Summary:");
print(" Name: " + user_name);
print(" Email: " + user_email);
print(" Public Key: " + timur_pubkey);
print(" TFT Account: Created");
print(" ETH Account: Created");
print(" KYC Status: Verified");
print(" Payment Status: Completed ($100 USD)");
print(" Contract: Signed and Active");
print("\nRegistration Flow:");
print(" ✓ Freezone initialization (Email, Payment, KYC providers configured)");
print(" ✓ Freezone Ethereum wallet created");
print(" ✓ Public key registration");
print(" ✓ User profile creation & email verification");
print(" ✓ Terms & Conditions signed");
print(" ✓ Crypto wallets created (TFT + ETH)");
print(" ✓ Payment processed ($100 USD)");
print(" ✓ KYC verification completed with verified info");
print("\n" + user_name + " is now a verified Freezone member!");
print("═══════════════════════════════════════════════════════════════\n");