diff --git a/NexVerse/Core/Economy/NexMasterBankPayoutPolicy.cs b/NexVerse/Core/Economy/NexMasterBankPayoutPolicy.cs new file mode 100644 index 00000000..ff1fde81 --- /dev/null +++ b/NexVerse/Core/Economy/NexMasterBankPayoutPolicy.cs @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: MPL-2.0 +using System; +using System.Collections.Generic; + +namespace NexVerse.Core.Economy +{ + /// + /// Explicit administrator-managed Master Bank delegations. + /// A wallet UUID alone grants NO script payout rights. + /// Inventory script IDs must be paired with their exact rezzed object IDs. + /// + public sealed class NexMasterBankPayoutPolicy + { + private readonly HashSet m_Bindings; + + public Guid AccountId { get; } + public Guid OperatorId { get; } + public long MaxAmount { get; } + public bool Enabled => AccountId != Guid.Empty && + OperatorId != Guid.Empty && MaxAmount > 0 && + m_Bindings.Count > 0; + + public NexMasterBankPayoutPolicy(Guid accountId, Guid operatorId, + long maxAmount, string authorizedBindings) + { + if (maxAmount < 0 || maxAmount > int.MaxValue) + throw new ArgumentOutOfRangeException(nameof(maxAmount)); + if (accountId != Guid.Empty && accountId == operatorId) + throw new ArgumentException( + "The Master Bank account must be different from the operator's wallet."); + + AccountId = accountId; + OperatorId = operatorId; + MaxAmount = maxAmount; + m_Bindings = new HashSet(StringComparer.Ordinal); + + foreach (string raw in (authorizedBindings ?? string.Empty).Split( + new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) + { + string[] pair = raw.Trim().Split('/'); + if (pair.Length != 2 || + !Guid.TryParse(pair[0], out Guid objectId) || + !Guid.TryParse(pair[1], out Guid scriptId) || + objectId == Guid.Empty || scriptId == Guid.Empty) + throw new ArgumentException( + "Master Bank allowed scripts must use objectUUID/scriptItemUUID pairs.", + nameof(authorizedBindings)); + m_Bindings.Add(Key(objectId, scriptId)); + } + } + + private static string Key(Guid objectId, Guid scriptId) => + objectId.ToString("D") + "/" + scriptId.ToString("D"); + + public bool IsAuthorized(Guid objectId, Guid scriptId, Guid ownerId) + { + return Enabled && objectId != Guid.Empty && + scriptId != Guid.Empty && ownerId == OperatorId && + m_Bindings.Contains(Key(objectId, scriptId)); + } + + public bool CanPayout(Guid objectId, Guid scriptId, Guid ownerId, + Guid recipientId, long amount) + { + return IsAuthorized(objectId, scriptId, ownerId) && + recipientId != Guid.Empty && recipientId != OperatorId && + recipientId != AccountId && amount > 0 && + amount <= MaxAmount; + } + } +} diff --git a/NexVerse/RegionModules/Economy/NexVerseMoneyModule.cs b/NexVerse/RegionModules/Economy/NexVerseMoneyModule.cs index b37f8527..e26e2ea3 100644 --- a/NexVerse/RegionModules/Economy/NexVerseMoneyModule.cs +++ b/NexVerse/RegionModules/Economy/NexVerseMoneyModule.cs @@ -30,6 +30,7 @@ namespace NexVerse.RegionModules.Economy Id = "NexVerseMoneyModule")] public sealed class NexVerseMoneyModule : IMoneyModule, + INexMasterBankPayoutModule, ISharedRegionModule { private static readonly ILog m_Log = @@ -49,6 +50,7 @@ namespace NexVerse.RegionModules.Economy private bool m_Enabled; private bool m_LegacyHelperRegistered; private bool m_AllowHypergridGuests; + private NexMasterBankPayoutPolicy m_MasterBank; private string m_LocalEconomyUrl = string.Empty; private string m_CurrencyPurchasePortalUrl = string.Empty; private Dictionary m_LegacyRpcHandlers; @@ -201,6 +203,28 @@ namespace NexVerse.RegionModules.Economy m_AllowHypergridGuests = economy.GetBoolean("AllowHypergridGuests", false); + // Explicitly delegated payouts from one prefunded, separate + // Business wallet. No script sees the simulator API key. + if (economy.GetBoolean("MasterBankEnabled", false)) + { + string rawBank = economy.GetString("MasterBankAccountId", ""); + string rawOperator = economy.GetString("MasterBankOperatorId", ""); + if (!Guid.TryParse(rawBank, out Guid bankId) || + bankId == Guid.Empty || + !Guid.TryParse(rawOperator, out Guid operatorId) || + operatorId == Guid.Empty) + throw new InvalidOperationException( + "Master Bank requires nonzero account/operator UUIDs."); + + m_MasterBank = new NexMasterBankPayoutPolicy( + bankId, operatorId, + economy.GetInt("MasterBankMaxPayout", 100), + economy.GetString("MasterBankAuthorizedScripts", "")); + if (!m_MasterBank.Enabled) + throw new InvalidOperationException( + "Master Bank requires at least one exact object/script binding."); + } + string feeWallet = economy.GetString( "FeeWalletId", @@ -295,6 +319,8 @@ namespace NexVerse.RegionModules.Economy scene.RegisterModuleInterface( this); + if (m_MasterBank?.Enabled == true) + scene.RegisterModuleInterface(this); scene.EventManager.OnNewClient += OnNewClient; @@ -320,6 +346,8 @@ namespace NexVerse.RegionModules.Economy MoneyTransferAction; scene.EventManager.OnClientClosed -= ClientClosed; + if (m_MasterBank?.Enabled == true) + scene.UnregisterModuleInterface(this); lock (m_Sync) m_Scenes.Remove( @@ -569,6 +597,141 @@ namespace NexVerse.RegionModules.Economy out _); } + + public bool IsAuthorizedBankScript(UUID objectId, UUID scriptItemId, + UUID ownerId) + { + if (!m_Enabled || m_MasterBank?.Enabled != true || + !m_MasterBank.IsAuthorized(objectId.Guid, + scriptItemId.Guid, ownerId.Guid)) + return false; + + // A registered object MUST still exist as a live scene object, + // owned by the registered operator. Its inventory MUST contain + // the exact approved script instance. + lock (m_Sync) + foreach (Scene scene in m_Scenes.Values) + { + SceneObjectPart root = scene?.GetSceneObjectPart(objectId); + if (root?.ParentGroup == null || + root.ParentGroup.IsDeleted || + root.ParentGroup.RootPart.UUID != objectId || + root.ParentGroup.RootPart.OwnerID != ownerId) + continue; + if (root.ParentGroup.RootPart.TaskInventory.ContainsKey(scriptItemId)) + return true; + } + + return false; + } + + public bool TryBankPayout(UUID objectId, UUID scriptItemId, + UUID ownerId, UUID residentId, int amount, UUID transactionId, + out string reason) + { + reason = "Master Bank payout is not authorized."; + if (m_MasterBank?.CanPayout(objectId.Guid, scriptItemId.Guid, + ownerId.Guid, residentId.Guid, amount) != true || + !IsAuthorizedBankScript(objectId, scriptItemId, ownerId)) + return false; + + // Only send money to a resident currently present in this + // simulator. For HG visitors this also ensures their wallet is + // resolved from the authenticated home grid circuit. + IClientAPI recipient = LocateClient(residentId); + if (recipient == null || !recipient.IsActive || + !TryResolveWallet(residentId, false, + out UUID destinationWallet, out reason)) + { + if (string.IsNullOrWhiteSpace(reason)) + reason = "Recipient must be present in NexVerse."; + return false; + } + + if (destinationWallet == new UUID(m_MasterBank.AccountId)) + { + reason = "Master Bank cannot pay itself."; + return false; + } + + if (!EnsureMasterBankAccount(out reason)) + return false; + + try + { + UUID paymentId = transactionId.IsZero() ? + UUID.Random() : transactionId; + byte[] payload = JsonSerializer.SerializeToUtf8Bytes(new + { + from_account_id = m_MasterBank.AccountId.ToString("D"), + to_account_id = destinationWallet.ToString(), + amount, + reference = "Authorized Master Bank payout (" + + objectId.ToString() + "/" + scriptItemId.ToString() + ")" + }); + using HttpRequestMessage request = CreateRequest( + HttpMethod.Post, "/api/v1/banking/transfers"); + request.Headers.TryAddWithoutValidation("Idempotency-Key", + "master-bank-" + paymentId.ToString()); + request.Content = new ByteArrayContent(payload); + request.Content.Headers.ContentType = + new MediaTypeHeaderValue("application/json"); + using HttpResponseMessage response = m_Http.Send(request); + if (!response.IsSuccessStatusCode) + { + reason = ReadErrorMessage(response); + return false; + } + + reason = string.Empty; + SendBalanceRefresh(residentId); + m_Log.InfoFormat( + "[NEX-MASTER-BANK]: Verified script {0}/{1} paid {2} NV$ to {3}; txn {4}.", + objectId, scriptItemId, amount, destinationWallet, paymentId); + return true; + } + catch (Exception e) + { + reason = "Central Master Bank payout unavailable."; + m_Log.WarnFormat("[NEX-MASTER-BANK]: Payout failed: {0}", + e.Message); + return false; + } + } + + private bool EnsureMasterBankAccount(out string reason) + { + reason = string.Empty; + try + { + byte[] payload = JsonSerializer.SerializeToUtf8Bytes(new + { + account_id = m_MasterBank.AccountId.ToString("D"), + account_class = "business", + display_name = "NexVerse Master Bank" + }); + using HttpRequestMessage request = CreateRequest( + HttpMethod.Post, "/api/v1/economy/accounts/ensure"); + request.Content = new ByteArrayContent(payload); + request.Content.Headers.ContentType = + new MediaTypeHeaderValue("application/json"); + using HttpResponseMessage response = m_Http.Send(request); + if (!response.IsSuccessStatusCode) + { + reason = ReadErrorMessage(response); + return false; + } + return true; + } + catch (Exception e) + { + reason = "Central bank wallet unavailable."; + m_Log.WarnFormat("[NEX-MASTER-BANK]: Ensure failed: {0}", + e.Message); + return false; + } + } + public bool ObjectGiveMoney( UUID objectID, UUID fromID, diff --git a/OpenSim/Region/Framework/Interfaces/INexMasterBankPayoutModule.cs b/OpenSim/Region/Framework/Interfaces/INexMasterBankPayoutModule.cs new file mode 100644 index 00000000..591338cd --- /dev/null +++ b/OpenSim/Region/Framework/Interfaces/INexMasterBankPayoutModule.cs @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: MPL-2.0 +using OpenMetaverse; + +namespace OpenSim.Region.Framework.Interfaces +{ + /// + /// Only the server-side script engine can invoke delegated NV$ Master Bank + /// payments. Never expose a capability that accepts object/script IDs from + /// an untrusted viewer or in-world HTTP client. + /// + public interface INexMasterBankPayoutModule + { + bool IsAuthorizedBankScript(UUID objectId, UUID scriptItemId, UUID ownerId); + bool TryBankPayout(UUID objectId, UUID scriptItemId, UUID ownerId, + UUID residentId, int amount, UUID transactionId, out string reason); + } +} diff --git a/OpenSim/Region/Framework/OpenSim.Region.Framework.csproj b/OpenSim/Region/Framework/OpenSim.Region.Framework.csproj index b9019081..c2aca4cd 100644 --- a/OpenSim/Region/Framework/OpenSim.Region.Framework.csproj +++ b/OpenSim/Region/Framework/OpenSim.Region.Framework.csproj @@ -426,6 +426,9 @@ Code + + Code + Code diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index bb1eb821..cf32cc68 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs @@ -3412,10 +3412,26 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return 0; } + // The Master Bank requires an exact server-side object+script + // delegation AND explicit PERMISSION_DEBIT from its operator. + // A copied script or a bare bank UUID cannot access bank funds. + INexMasterBankPayoutModule bank = + World.RequestModuleInterface(); + UUID rootObject = m_host.ParentGroup.RootPart.UUID; + UUID rootOwner = m_host.ParentGroup.RootPart.OwnerID; + bool master = bank != null && + bank.IsAuthorizedBankScript(rootObject, m_item.ItemID, rootOwner); + if (master && m_item.PermsGranter != rootOwner) + return 0; + void act(string _) { - money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, - toID, amount, UUID.Zero, out _); + if (master) + bank.TryBankPayout(rootObject, m_item.ItemID, rootOwner, + toID, amount, UUID.Random(), out _); + else + money.ObjectGiveMoney(rootObject, rootOwner, + toID, amount, UUID.Zero, out _); } m_AsyncCommands.DataserverPlugin.RegisterRequest(m_host.LocalId, m_item.ItemID, act); @@ -17285,21 +17301,51 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api return txn.ToString(); } - //fire and forget... + INexMasterBankPayoutModule bank = + World.RequestModuleInterface(); + UUID rootObject = m_host.ParentGroup.RootPart.UUID; + UUID rootOwner = m_host.ParentGroup.RootPart.OwnerID; + bool master = bank != null && + bank.IsAuthorizedBankScript(rootObject, m_item.ItemID, rootOwner); + + // The approved bank operator must be the debit granter. + if (master && m_item.PermsGranter != rootOwner) + { + m_ScriptEngine.PostScriptEvent(m_item.ItemID, new EventParams( + "transaction_result", new object[] { + new LSL_String(txn.ToString()), + new LSL_Integer(0), + new LSL_String("MISSING_MASTER_BANK_OPERATOR_PERMISSION") + }, Array.Empty())); + return txn.ToString(); + } + + // Fire and forget, with a correlated transaction_result event. void act(string eventID) { int replycode = 0; try { - UserAccount account = m_userAccountService.GetUserAccount(RegionScopeID, toID); - if (account is null) + // Generic LSL transfers still require local UserAccount. + // Authorized bank scripts may also pay verified *present* + // HG visitors, resolved by the economy region module. + if (!master) { - replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST"; - return; + UserAccount account = + m_userAccountService.GetUserAccount(RegionScopeID, toID); + if (account is null) + { + replydata = "LINDENDOLLAR_ENTITYDOESNOTEXIST"; + return; + } } - bool result = money.ObjectGiveMoney(m_host.ParentGroup.RootPart.UUID, m_host.ParentGroup.RootPart.OwnerID, - toID, amount, txn, out string reason); + string reason; + bool result = master + ? bank.TryBankPayout(rootObject, m_item.ItemID, rootOwner, + toID, amount, txn, out reason) + : money.ObjectGiveMoney(rootObject, rootOwner, + toID, amount, txn, out reason); if (result) { replycode = 1; diff --git a/bin/OpenSim.ini b/bin/OpenSim.ini index 68283cb6..66181a4a 100644 --- a/bin/OpenSim.ini +++ b/bin/OpenSim.ini @@ -1069,6 +1069,18 @@ ; No foreign-grid currency exchange and no ATM withdrawals are enabled. AllowHypergridGuests = false + ; Optional central NV$ master bank (currently disabled). + ; This is a distinct, prefunded Business wallet, NOT the operator avatar. + ; A UUID alone never grants access to the Master Bank. + ; Binding syntax: objectUUID/scriptInventoryItemUUID;... + ; The script owner must be MasterBankOperatorId and have granted + ; PERMISSION_DEBIT; payments use central BankingTransfer policy/limits. + MasterBankEnabled = false + MasterBankAccountId = "" + MasterBankOperatorId = "" + MasterBankAuthorizedScripts = "" + MasterBankMaxPayout = 100 + ; Optional secure web portal opened/recommended by the legacy Firestorm ; buy-currency helper. No currency is minted by unauthenticated XML-RPC. CurrencyPurchasePortalUrl = "" diff --git a/bin/OpenSim.ini.example b/bin/OpenSim.ini.example index 9fc857b9..3f203096 100644 --- a/bin/OpenSim.ini.example +++ b/bin/OpenSim.ini.example @@ -1082,6 +1082,18 @@ ; No foreign-grid currency exchange and no ATM withdrawals are enabled. AllowHypergridGuests = false + ; Optional central NV$ master bank (currently disabled). + ; This is a distinct, prefunded Business wallet, NOT the operator avatar. + ; A UUID alone never grants access to the Master Bank. + ; Binding syntax: objectUUID/scriptInventoryItemUUID;... + ; The script owner must be MasterBankOperatorId and have granted + ; PERMISSION_DEBIT; payments use central BankingTransfer policy/limits. + MasterBankEnabled = false + MasterBankAccountId = "" + MasterBankOperatorId = "" + MasterBankAuthorizedScripts = "" + MasterBankMaxPayout = 100 + ; Optional secure web portal opened/recommended by the legacy Firestorm ; buy-currency helper. No currency is minted by unauthenticated XML-RPC. CurrencyPurchasePortalUrl = "" diff --git a/doc/NexVerse/ECONOMY_LEDGER.md b/doc/NexVerse/ECONOMY_LEDGER.md index f2c5a303..cfc47ac1 100644 --- a/doc/NexVerse/ECONOMY_LEDGER.md +++ b/doc/NexVerse/ECONOMY_LEDGER.md @@ -177,3 +177,76 @@ durch einen normalen LSL-`llGiveMoney`-Trick simuliert werden. Ein Test mit mindestens zwei fremden Home-Grids, identischen Original-UUIDs auf unterschiedlichen Home-Grids und getrennten Sim-Prozessen ist fuer produktive Aktivierung Pflicht. + +## Zentrale NV$-Masterbank fuer freigegebene LSL-Skripte (11.10.2026) + +Die **Masterbank** ist ein vom Betreiber eingerichtetes, dauerhaftes +`Business`-Wallet mit frei waehlbarer UUID. Das Guthaben verbleibt +ausschliesslich im NexVerse-Ledger; die Bank ist **keine Geldschoepfungs-API**. +Sie kann gegenueber lokalen und **angemeldeten HG-Gast-Wallets** +dieselben virtuellen NV$ auszahlen. + +**Sicherheitsmodell:** Die Bankkonto-UUID allein darf nie eine Auszahlung +freigeben. Der Simulator prueft vor *jedem* Vorgang: +- `MasterBankEnabled = true` und vorhandene getrennte Bank- und + Betreiber-UUID; das empfangende Ziel muss aktuell in NexVerse + angemeldet sein. +- Nur exakt erlaubte Paare aus **Root-Objekt-UUID und + LSL-Skript-Inventaritem-UUID** erhalten Zugriff. Skriptkopien + und neu gerezzte Objekte haben normalerweise neue IDs und bleiben gesperrt. +- Das Objekt gehoert dem eingetragenen `MasterBankOperatorId`. + Der Betreiber hat dem Skript `PERMISSION_DEBIT` erteilt. +- `MasterBankMaxPayout` begrenzt jede einzelne Auszahlung. + Zusatzeinschraenkungen wie Tageslimits koennen ueber die zentrale + Banking-Transferpolicy fuer das Bankkonto gesetzt werden. +- Die Umbuchung geht ueber `POST /api/v1/banking/transfers`, + mit Idempotency-Key, autoritativer Deckungspruefung und + Double-Entry-Journal. Der Auszahlungscode nutzt ausschliesslich + die getrennte Bankkonto-UUID als Quelle. +- Keine Schluessel, HTTP-API-Tokens oder privilegierten UUID-Claims + werden an das LSL-Skript ausgegeben. Das Skript ruft die vorhandenen + `llGiveMoney` oder besser `llTransferLindenDollars`-Funktionen auf. + `transaction_result` liefert bei letzterem Erfolg oder Fehler. + +**Konfiguration:** In der geladenen Simulator-`OpenSim.ini`: + +```ini +[NexEconomyViewer] + MasterBankEnabled = false + MasterBankAccountId = "" + MasterBankOperatorId = "" + MasterBankAuthorizedScripts = "" + MasterBankMaxPayout = 100 +``` + +Die Bank darf erst nach kontrollierter Einrichtung aktiviert werden. +`MasterBankAccountId` ist eine fest gewaehlte **neue, unbenutzte UUID** +und darf nicht der UUID eines vorhandenen Avatars, Gruppenwallets oder +Systemkontos entsprechen. Der Server legt das Konto beim ersten +autorisierten Einsatz als Business-Wallet mit **0 NV$** an. + +**Beispiel fuer mehrere Skripte:** +`MasterBankAuthorizedScripts = "OBJEKT-UUID-1/SKRIPT-INVENTAR-UUID-1;OBJEKT-UUID-2/SKRIPT-INVENTAR-UUID-2"` + +Die `SKRIPT-INVENTAR-UUID` ist die **Task-Inventory-Item-ID**, nicht +die Skript-Asset-UUID von `llGetInventoryKey()`. Der Administrator +muss das Objekt und sein Task-Inventar ueber vertrauenswuerdige +Simulator-/Inventardiagnose identifizieren. Der Demo-Code liegt unter +[`tools/diagnostics/ogl_master_bank_payout_test.lsl`](../../tools/diagnostics/ogl_master_bank_payout_test.lsl). + +**Wichtig:** Das vorhandene `economy:transfer`-Service-Credential ist +allgemein fuer die World-API uebertragungsberechtigt. Die neue +Skriptdelegation haertet die *Inworld-Aufrufer* ab, sie ersetzt +nicht die Absicherung vertrauenswuerdiger Simulatoren und ihrer +Maschinenkeys. Kein ungepruefter LSL-HTTP-Endpunkt darf dieses +Credential nutzen. Konten und Tokens bleiben zentral durch den Betreiber +verwaltet. + +HG-Bewohner duerfen NV$ **nur innerhalb NexVerse** verwenden. Sie +koennen dort kaufen, verkaufen und bei spaeteren Bankfunktionen +einzahlen, auszahlen und Zinsen auf virtuelle NV$ erhalten. +Das Guthaben bleibt auch nach dem Ausloggen im zentralen Ledger, +wird aber nicht in Heimatgrid-Waehrung exportiert. +Zinsen/ATM-Buchungen werden spaeter als gedeckte Ledger-Transaktionen +mit eigenem Reservekonto, Freigaben und Limits implementiert. +Noch **keine** automatische Zinszahlung oder ATM-Live-Freigabe. diff --git a/tools/ci/NexEconomyPolicyRegression/NexEconomyPolicyRegression.csproj b/tools/ci/NexEconomyPolicyRegression/NexEconomyPolicyRegression.csproj index 823c806b..91934b5b 100644 --- a/tools/ci/NexEconomyPolicyRegression/NexEconomyPolicyRegression.csproj +++ b/tools/ci/NexEconomyPolicyRegression/NexEconomyPolicyRegression.csproj @@ -26,5 +26,6 @@ + diff --git a/tools/ci/NexEconomyPolicyRegression/Program.cs b/tools/ci/NexEconomyPolicyRegression/Program.cs index 06991553..6b94b70b 100644 --- a/tools/ci/NexEconomyPolicyRegression/Program.cs +++ b/tools/ci/NexEconomyPolicyRegression/Program.cs @@ -122,6 +122,67 @@ internal static class Program 9999, "HG overdraft"), label + ": HG account allowed overdraft"); + + // The Master Bank is an opt-in, prefunded Business wallet. Its UUID + // does not grant authority: both exact script binding and operator + // ownership are necessary for every delegated payout. + Guid bankId = Guid.NewGuid(); + Guid operatorId = Guid.NewGuid(); + Guid payoutObject1 = Guid.NewGuid(); + Guid payoutScript1 = Guid.NewGuid(); + Guid payoutObject2 = Guid.NewGuid(); + Guid payoutScript2 = Guid.NewGuid(); + NexMasterBankPayoutPolicy disabled = new NexMasterBankPayoutPolicy( + bankId, operatorId, 100, ""); + Require(!disabled.Enabled && !disabled.IsAuthorized( + payoutObject1, payoutScript1, operatorId), + label + ": Master Bank was enabled without explicit scripts"); + + NexMasterBankPayoutPolicy master = new NexMasterBankPayoutPolicy( + bankId, operatorId, 50, + payoutObject1.ToString("D") + "/" + payoutScript1.ToString("D") + + ";" + payoutObject2.ToString("D") + "/" + payoutScript2.ToString("D")); + Require(master.Enabled && + master.IsAuthorized(payoutObject1, payoutScript1, operatorId) && + master.IsAuthorized(payoutObject2, payoutScript2, operatorId) && + !master.IsAuthorized(payoutObject1, payoutScript2, operatorId) && + !master.IsAuthorized(payoutObject1, payoutScript1, Guid.NewGuid()) && + master.CanPayout(payoutObject1, payoutScript1, operatorId, + foreignAvatar, 25) && + !master.CanPayout(payoutObject1, payoutScript1, operatorId, + foreignAvatar, 51) && + !master.CanPayout(payoutObject1, payoutScript1, operatorId, + foreignAvatar, 0) && + !master.CanPayout(payoutObject1, payoutScript1, operatorId, + bankId, 5), + label + ": unauthorized Master Bank payout delegation accepted"); + RequireThrows( + () => new NexMasterBankPayoutPolicy(bankId, operatorId, 10, + payoutObject1.ToString("D")), + label + ": unqualified Master Bank script ID accepted"); + RequireThrows( + () => new NexMasterBankPayoutPolicy(operatorId, operatorId, 10, + payoutObject1.ToString("D") + "/" + payoutScript1.ToString("D")), + label + ": Master Bank account indistinguishable from operator"); + NexLedgerAccount bank = economy.EnsureWalletAccount(bankId, + NexLedgerAccountClass.Business, "NexVerse CI Master Bank"); + Require(bank.AccountClass == NexLedgerAccountClass.Business && + economy.GetBalance(bankId) == 0, + label + ": Master Bank created with a non-zero balance"); + // Only a *separate explicit* funding adjustment credits the bank. + economy.AdministrativeAdjustment(bankId, systemId, 100, + "ci-admin", "explicit prefunding of master bank"); + NexLedgerAppendResult masterPayout = economy.BankingTransfer( + bankId, guestWallet.AccountId, 25, "CI bank reward"); + Require(masterPayout.Created && + economy.GetBalance(bankId) == 75 && + economy.GetBalance(guestWallet.AccountId) == 29, + label + ": master bank could not payout to HG resident wallet"); + RequireThrows( + () => economy.BankingTransfer(bankId, guestWallet.AccountId, + 9999, "unfunded master payout"), + label + ": master bank created unbacked money"); + NexLedgerAccount resident = economy.EnsureResidentAccount( residentId, diff --git a/tools/ci/verify_economy_api_viewer.py b/tools/ci/verify_economy_api_viewer.py index 8d72cf7b..a7472403 100644 --- a/tools/ci/verify_economy_api_viewer.py +++ b/tools/ci/verify_economy_api_viewer.py @@ -190,3 +190,34 @@ for marker in ("HG origin isolation/canonicalization failed", "HG transfer ledger balance mismatch", "HG account allowed overdraft"): assert marker in hg_tests, "Missing HG wallet regression: " + marker + +# Master Bank: object/script authority, prefunded separate wallet, +# explicit operator debit grant, no LSL-side API key or minting. +master_policy = Path("NexVerse/Core/Economy/NexMasterBankPayoutPolicy.cs").read_text() +master_intf = Path("OpenSim/Region/Framework/Interfaces/INexMasterBankPayoutModule.cs").read_text() +lsl = Path("OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs").read_text() +regression = Path("tools/ci/NexEconomyPolicyRegression/Program.cs").read_text() +for marker in ("IsAuthorized(", "CanPayout(", "objectUUID/scriptItemUUID", + "ownerId == OperatorId", "amount <= MaxAmount"): + assert marker in master_policy, "Master Bank policy missing: " + marker +for marker in ("INexMasterBankPayoutModule", "IsAuthorizedBankScript(", + "TryBankPayout("): + assert marker in master_intf and marker in viewer, "Missing native bank script boundary: " + marker +for marker in ("MasterBankEnabled", "MasterBankAccountId", "MasterBankOperatorId", + "MasterBankAuthorizedScripts", "MasterBankMaxPayout", + '"/api/v1/banking/transfers"', "EnsureMasterBankAccount(", + "GetAgentCircuitData(avatarId)", "IsAuthorizedBankScript(objectId"): + assert marker in viewer, "Incomplete bank payout implementation: " + marker +for marker in ("INexMasterBankPayoutModule", "bank.TryBankPayout(", + "m_item.PermsGranter != rootOwner"): + assert marker in lsl, "Master bank not bound to LSL debit permission: " + marker +for marker in ("unauthorized Master Bank payout delegation accepted", + "master bank could not payout to HG resident wallet", + "master bank created unbacked money"): + assert marker in regression, "Missing bank payout regression: " + marker +for p in ("bin/OpenSim.ini", "bin/OpenSim.ini.example"): + config = Path(p).read_text() + assert "MasterBankEnabled = false" in config + assert 'MasterBankAccountId = ""' in config + assert 'MasterBankAuthorizedScripts = ""' in config +assert "NEXVERSE_ECONOMY_API_KEY" not in Path("tools/diagnostics/ogl_master_bank_payout_test.lsl").read_text() diff --git a/tools/diagnostics/ogl_master_bank_payout_test.lsl b/tools/diagnostics/ogl_master_bank_payout_test.lsl new file mode 100644 index 00000000..87977625 --- /dev/null +++ b/tools/diagnostics/ogl_master_bank_payout_test.lsl @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: MPL-2.0 +// OGL 0.9.3.10 Master Bank - NUR MANUELLER OWNER-TEST. +// 1. Dieses Script in ein bewusst registriertes Bank-Root-Prim legen. +// 2. Admin registriert Root-Objekt-UUID / SCRIPT-INVENTARITEM-UUID. +// 3. Bankoperator erteilt PERMISSION_DEBIT nach bewusstem Dialog. +// 4. TARGET_AVATAR mit echter lokalen oder anwesenden HG-Avatar-UUID ersetzen. +// Kein API-Key, kein freier Touch-Faucet, kein unlimitierter Timer. +key TARGET_AVATAR = NULL_KEY; +integer AMOUNT_NV = 1; + +default +{ + state_entry() + { + llOwnerSay("Masterbank-Test: Owner beruehrt Prim fuer Debit-Freigabe " + + "oder kontrollierte Testauszahlung."); + } + + touch_start(integer total) + { + if (llDetectedKey(0) != llGetOwner()) + return; + if ((llGetPermissions() & PERMISSION_DEBIT) == 0 || + llGetPermissionsKey() != llGetOwner()) + { + llOwnerSay("Bankoperator muss PERMISSION_DEBIT ausdruecklich bestaetigen."); + llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); + return; + } + if (TARGET_AVATAR == NULL_KEY || AMOUNT_NV <= 0) + { + llOwnerSay("TEST NICHT GESTARTET: TARGET_AVATAR und Betrag konfigurieren."); + return; + } + key txn = llTransferLindenDollars(TARGET_AVATAR, AMOUNT_NV); + llOwnerSay("Masterbank-Transaktion angefragt: " + (string)txn); + } + + run_time_permissions(integer permissions) + { + if (permissions & PERMISSION_DEBIT) + llOwnerSay("Debit-Freigabe erteilt. Owner kann Test erneut ausloesen."); + else + llOwnerSay("Debit-Freigabe verweigert, keine Auszahlung."); + } + + transaction_result(key txn, integer success, string data) + { + if (success) + llOwnerSay("NV$ Auszahlung bestaetigt: " + data + + " (Transaktion " + (string)txn + ")"); + else + llOwnerSay("NV$ Auszahlung verweigert: " + data + + " (Transaktion " + (string)txn + ")"); + } +}