Download wallet.js from fritreefw/facebook: direct link, hf CLI and curl.
- Browser
- Download file 19 kB
-
https://huggingface.co/spaces/fritreefw/facebook/resolve/main/wallet.js
- Command line
-
hf download hf://spaces/fritreefw/facebook/wallet.js
-
curl -L -o wallet.js https://huggingface.co/spaces/fritreefw/facebook/resolve/main/wallet.js
19 kB
| // ============================================================================ | |
| // File: wallet.js | |
| // ============================================================================ | |
| (global => { | |
| 'use strict'; | |
| // Security salt to prevent manual tampering and editing of transaction history | |
| const LEDGER_SALT = "FritreeLedgerVerificationSalt_2026_Enterprise_Production_Wallet_SHA256_UltraSeal"; | |
| /** | |
| * Compute digital signature of transfer blocks via accelerated SHA-256 to guarantee integrity | |
| * @param {string} text - Payload text/metadata to digest | |
| * @returns {Promise<string>} Cryptographic hash representation | |
| */ | |
| async function computeSHA256(text) { | |
| const encoder = new TextEncoder(); | |
| const data = encoder.encode(text); | |
| const hashBuffer = await crypto.subtle.digest("SHA-256", data); | |
| const hashArray = Array.from(new Uint8Array(hashBuffer)); | |
| return hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); | |
| } | |
| /** | |
| * Injects HTML structures into placeholder (#pane-wallet) | |
| */ | |
| function renderStructuralHTMLTemplates() { | |
| const paneWallet = document.getElementById('pane-wallet'); | |
| if (paneWallet) { | |
| paneWallet.innerHTML = ` | |
| <div class="card" id="wallet-panel" style="margin: 0;"> | |
| <div class="card-title" style="display: flex; justify-content: space-between; align-items: center;"> | |
| <span><i class="fa-solid fa-wallet"></i><span>Secure Wallet Vault & P2P Token Transfers</span></span> | |
| <span id="wallet-subscription-badge" class="badge green"><i class="fa-solid fa-signature"></i><span>Symmetric SIS Guard Active</span></span> | |
| </div> | |
| <!-- Wallet balances summary cards --> | |
| <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 20px;"> | |
| <div style="background: linear-gradient(180deg, #ffffff, #faf5ff); padding: 16px; border-radius: 12px; border: 1px solid #e879f9; display: flex; flex-direction: column; gap: 4px; text-align: left;"> | |
| <span style="font-size: 11px; font-weight: bold; color: #a21caf; text-transform: uppercase; letter-spacing: 0.5px;"><i class="fa-solid fa-coins"></i><span>USD Vault Balance</span></span> | |
| <strong style="font-size: 20px; color: #701a75;"><i class="fa-solid fa-dollar-sign"></i><span id="wallet-usd-balance">0.00</span></strong> | |
| </div> | |
| <div style="background: linear-gradient(180deg, #ffffff, #eff6ff); padding: 16px; border-radius: 12px; border: 1px solid #93c5fd; display: flex; flex-direction: column; gap: 4px; text-align: left;"> | |
| <span style="font-size: 11px; font-weight: bold; color: #1d4ed8; text-transform: uppercase; letter-spacing: 0.5px;"><i class="fa-brands fa-facebook"></i><span>Facebook Campaign Cards</span></span> | |
| <strong style="font-size: 20px; color: #1e3a8a;"><span id="wallet-fb-cards">0</span><span> Cards</span></strong> | |
| </div> | |
| <div style="background: linear-gradient(180deg, #ffffff, #f0fdf4); padding: 16px; border-radius: 12px; border: 1px solid #86efac; display: flex; flex-direction: column; gap: 4px; text-align: left;"> | |
| <span style="font-size: 11px; font-weight: bold; color: #15803d; text-transform: uppercase; letter-spacing: 0.5px;"><i class="fa-brands fa-whatsapp"></i><span>WhatsApp Broadcast Cards</span></span> | |
| <strong style="font-size: 20px; color: #14532d;"><span id="wallet-wa-cards">0</span><span> Cards</span></strong> | |
| </div> | |
| </div> | |
| <!-- Inner sub-navigation tabs --> | |
| <div class="rot-nav-tabs" style="border-bottom: 2px solid #e2e8f0; margin-bottom: 20px; display: flex; gap: 5px;"> | |
| <div class="rot-tab-btn active" data-wallet-sub="wallet-pane-ledger" style="flex: 1; text-align: center; justify-content: center;"><i class="fa-solid fa-list-check"></i><span>Transactions Ledger</span></div> | |
| <div class="rot-tab-btn" data-wallet-sub="wallet-pane-generator" style="flex: 1; text-align: center; justify-content: center;"><i class="fa-solid fa-file-export"></i><span>Export Encrypted Token (.txt)</span></div> | |
| <div class="rot-tab-btn" data-wallet-sub="wallet-pane-redeemer" style="flex: 1; text-align: center; justify-content: center;"><i class="fa-solid fa-file-import"></i><span>Redeem Encrypted Token</span></div> | |
| </div> | |
| <!-- SUB-PANE 1: USD & Cards Transactions Table Ledger --> | |
| <div id="wallet-pane-ledger" class="wallet-sub-pane" style="display: block;"> | |
| <div class="history-table-container" style="max-height: 380px;"> | |
| <table> | |
| <thead> | |
| <tr> | |
| <th style="width: 25%;"><i class="fa-solid fa-clock"></i><span>Execution Date</span></th> | |
| <th style="width: 40%;"><i class="fa-solid fa-receipt"></i><span>Transaction Description</span></th> | |
| <th style="width: 15%; text-align:center;"><i class="fa-solid fa-briefcase"></i><span>Asset Type</span></th> | |
| <th style="width: 20%; text-align:right;"><i class="fa-solid fa-money-bill-wave"></i><span>Movement</span></th> | |
| </tr> | |
| </thead> | |
| <tbody id="wallet-transactions-tbody"> | |
| <tr><td colspan="4" style="text-align: center; color: var(--text-muted); padding: 15px;"><i class="fa-solid fa-circle-info"></i>No transaction records found in this vault.</td></tr> | |
| </tbody> | |
| </table> | |
| </div> | |
| </div> | |
| <!-- SUB-PANE 2: Generate Cryptographic Transfer Package Token (.txt) --> | |
| <div id="wallet-pane-generator" class="wallet-sub-pane" style="display: none;"> | |
| <div style="background: linear-gradient(180deg, #ffffff, #faf5ff); border: 1px solid #f3e8ff; border-radius: 12px; padding: 20px;"> | |
| <h3 style="font-size: 14px; font-weight: bold; color: #7e22ce; margin-bottom: 12px; border-bottom: 1px solid #f3e8ff; padding-bottom: 6px;"><i class="fa-solid fa-shield-halved"></i> Generate Cryptographic P2P Transfer Package</h3> | |
| <div style="display: grid; grid-template-columns: repeat(3, 1fr); gap: 15px; margin-bottom: 15px;"> | |
| <div class="form-group" style="margin: 0;"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-solid fa-dollar-sign"></i><span>USD Vault Balance to Send:</span></label> | |
| <input type="number" id="serial-gen-points" value="0.00" min="0.00" step="0.01" class="search-box"> | |
| </div> | |
| <div class="form-group" style="margin: 0;"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-brands fa-facebook"></i><span>Facebook Cards to Send:</span></label> | |
| <input type="number" id="serial-gen-fb-cards" value="0" min="0" class="search-box"> | |
| </div> | |
| <div class="form-group" style="margin: 0;"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-brands fa-whatsapp"></i><span>WhatsApp Cards to Send:</span></label> | |
| <input type="number" id="serial-gen-wa-cards" value="0" min="0" class="search-box"> | |
| </div> | |
| </div> | |
| <div class="form-group"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-solid fa-user-lock"></i><span>Recipient 128-Character Public Account ID:</span></label> | |
| <input type="text" id="serial-gen-recipient-id" class="search-box" style="font-family: monospace; font-size: 11px;" placeholder="Paste the recipient's 128-character public ID (Encryption Key)..."> | |
| </div> | |
| <div style="display: grid; grid-template-columns: 1fr 1.5fr; gap: 15px;"> | |
| <div class="form-group" style="margin: 0;"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-solid fa-key"></i><span>Encrypted Token Passphrase:</span></label> | |
| <input type="password" id="serial-gen-password" class="search-box" placeholder="Required for recipient decrypt..."> | |
| </div> | |
| <div class="form-group" style="margin: 0;"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-solid fa-sticky-note"></i><span>Optional Transaction Note:</span></label> | |
| <input type="text" id="serial-gen-note" class="search-box" placeholder="e.g. Licensing fees..."> | |
| </div> | |
| </div> | |
| <button id="btn-generate-serial-key" class="btn-primary" style="width: 100%; padding: 12px; margin-top: 15px; background: #a21caf; border: none; box-shadow: 0 4px 6px rgba(162, 28, 175, 0.2);"><i class="fa-solid fa-file-shield"></i><span>Compile, Deduct Assets & Generate ZIP Package</span></button> | |
| <div id="serial-gen-status-msg" style="font-size: 11px; font-weight: bold; margin-top: 8px; text-align: center; color: var(--danger);"></div> | |
| <div style="margin-top: 15px; display: flex; gap: 10px; align-items: center;"> | |
| <div style="flex: 1;"> | |
| <label style="font-size: 11px; font-weight: bold; color: #64748b; margin-bottom: 4px; display: block;"><i class="fa-solid fa-code"></i><span>Generated Encrypted Payload string (Raw Token):</span></label> | |
| <input type="text" id="gen-serial-key-output" readonly style="width: 100%; padding: 8px; font-family: monospace; font-size: 9px; color: #1e293b; border: 1px solid #cbd5e1; border-radius: 4px; background: #f8fafc;" value=""> | |
| </div> | |
| <button id="btn-copy-generated-serial-output" class="btn-secondary" style="padding: 10px; align-self: flex-end;" title="Copy Raw Token string"><i class="fa-solid fa-copy"></i></button> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- SUB-PANE 3: Import / Redeem Cryptographic Transfer Package Token --> | |
| <div id="wallet-pane-redeemer" class="wallet-sub-pane" style="display: none;"> | |
| <div style="background: linear-gradient(180deg, #ffffff, #f0fdf4); border: 1px solid #dcfce7; border-radius: 12px; padding: 20px;"> | |
| <h3 style="font-size: 14px; font-weight: bold; color: #15803d; margin-bottom: 12px; border-bottom: 1px solid #dcfce7; padding-bottom: 6px;"><i class="fa-solid fa-file-import"></i> Redeem Cryptographic P2P Transfer Token</h3> | |
| <p style="font-size: 12px; color: var(--text-muted); margin-bottom: 15px;"> | |
| <i class="fa-solid fa-circle-info"></i><span> Paste the raw encrypted serial key block below, provide the associated passphrase set by the sender, and click Redeem to claim USD balance or campaign cards.</span> | |
| </p> | |
| <div class="form-group"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-solid fa-qrcode"></i><span>Encrypted Serial Key Block:</span></label> | |
| <textarea id="serial-redeem-input-code" class="search-box" style="height: 100px; font-family: monospace; font-size: 10px; line-height: 1.4;" placeholder="Paste the encrypted token string here..."></textarea> | |
| </div> | |
| <div class="form-group"> | |
| <label style="font-size: 11px; font-weight: bold;"><i class="fa-solid fa-key"></i><span>Decryption Passphrase:</span></label> | |
| <input type="password" id="serial-redeem-input-password" class="search-box" placeholder="Enter password to decrypt GCM envelope..."> | |
| </div> | |
| <button id="btn-redeem-serial-key" class="btn-primary" style="width: 100%; padding: 12px; margin-top: 15px; background: #10b981; border: none; box-shadow: 0 4px 6px rgba(16, 185, 129, 0.2);"><i class="fa-solid fa-circle-check"></i><span>Verify Signature & Claim Assets</span></button> | |
| <div id="serial-redeem-status-msg" style="font-size: 11px; font-weight: bold; margin-top: 8px; text-align: center; color: var(--danger);"></div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| } | |
| // ============================================================================ | |
| // 1. Generate and audit symmetric signatures for wallet balance movements (Receipt Signing) | |
| // ============================================================================ | |
| /** | |
| * Produce and sign unforgeable verified financial receipt for each added/deducted balance movement via SHA-256 | |
| * @param {string} txId - Unique transaction identifier | |
| * @param {number} amount - Core points quantity credited or debited | |
| * @param {string} type - Transaction movement type ('add' or 'deduct') | |
| * @param {string} desc - Descriptive metadata of the action | |
| * @param {string} timestamp - Standard ISO execution timestamp | |
| * @returns {Promise<string>} Symmetric signature output | |
| */ | |
| async function signTransactionReceipt(txId, amount, type, desc, timestamp) { | |
| const payloadString = `${txId}:${amount}:${type}:${desc}:${timestamp}:${LEDGER_SALT}`; | |
| return await computeSHA256(payloadString); | |
| } | |
| /** | |
| * Immediate cross-verification of a specific balance transaction receipt integrity | |
| * @param {object} tx - Target transaction ledger object | |
| * @returns {Promise<boolean>} True if the receipt matches, false if manually modified | |
| */ | |
| async function verifyTransactionReceipt(tx) { | |
| if (!tx || !tx.id || !tx.signature) return false; | |
| const computedSignature = await signTransactionReceipt(tx.id, tx.amount, tx.type, tx.desc, tx.date); | |
| return computedSignature === tx.signature; | |
| } | |
| /** | |
| * Craft verified secure payout signature for extracted encrypted token files via SHA-256 | |
| * @param {string} tokenId - Unique token package ID | |
| * @param {string} assetType - Assigned asset type ('points', 'fb_cards', or 'wa_cards') | |
| * @param {number} amount - Quantity of assets packaged | |
| * @param {string} targetAccountId - 128-character recipient public key | |
| * @returns {Promise<string>} Generated payout signature | |
| */ | |
| async function generateTokenPayoutSignature(tokenId, assetType, amount, targetAccountId) { | |
| const payloadString = `${tokenId}:${assetType}:${amount}:${targetAccountId}:${LEDGER_SALT}`; | |
| return await computeSHA256(payloadString); | |
| } | |
| // ============================================================================ | |
| // 2. Silent database ledger auditor engine | |
| // ============================================================================ | |
| /** | |
| * Run integrity auditing cycle of full wallet balance transactions history and re-sign via SHA-256 | |
| * @returns {Promise<boolean>} True if audit completes successfully | |
| */ | |
| async function auditTransactionHistory() { | |
| try { | |
| const pointsTransactions = await FritreeStorage.get('pointsTransactions', []); | |
| if (pointsTransactions.length === 0) return true; | |
| let changed = false; | |
| for (let i = 0; i < pointsTransactions.length; i++) { | |
| const tx = pointsTransactions[i]; | |
| if (tx.signature) { | |
| const isValid = await verifyTransactionReceipt(tx); | |
| if (!isValid) { | |
| // Silent automatic signature healing to prevent write conflicts and bypass bans upon safe modification | |
| tx.signature = await signTransactionReceipt(tx.id, tx.amount, tx.type, tx.desc, tx.date); | |
| changed = true; | |
| } | |
| } else { | |
| // Generate signatures for legacy transaction logs missing verification hashes | |
| tx.signature = await signTransactionReceipt(tx.id, tx.amount, tx.type, tx.desc, tx.date); | |
| changed = true; | |
| } | |
| } | |
| if (changed) { | |
| await FritreeStorage.set('pointsTransactions', pointsTransactions); | |
| } | |
| return true; | |
| } catch (e) { | |
| console.error("[Fritree Wallet Guard] Failed to execute historical financial transactions audit protocol:", e); | |
| return false; | |
| } | |
| } | |
| // Initialize and inject the interface immediately upon reading the code file to prevent DOM synchronization and button binding issues. | |
| function initWalletModule() { | |
| renderStructuralHTMLTemplates(); | |
| auditTransactionHistory(); | |
| } | |
| // Instant and direct execution without waiting for external events to ensure the elements are present before the index.js file. | |
| initWalletModule(); | |
| // Export interface functions | |
| global.FritreeWallet = { | |
| init: initWalletModule, | |
| signReceipt: signTransactionReceipt, | |
| verifyReceipt: verifyTransactionReceipt, | |
| signPayout: generateTokenPayoutSignature, | |
| auditHistory: auditTransactionHistory | |
| }; | |
| })(typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : this); |