@nibgate/sdk 0.2.23 → 0.2.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/nibgate.js +671 -762
- package/dist/nibgate.js.map +4 -4
- package/dist/nibgate.min.js +75 -75
- package/dist/nibgate.min.js.map +4 -4
- package/package.json +1 -1
- package/src/browser/default-ui.js +1 -65
package/dist/nibgate.js
CHANGED
|
@@ -423,211 +423,6 @@ var Nibgate = (() => {
|
|
|
423
423
|
}
|
|
424
424
|
});
|
|
425
425
|
|
|
426
|
-
// src/browser/track.js
|
|
427
|
-
function trackResourcePage(resource, options = {}) {
|
|
428
|
-
const item = createGate(resource, options.gateOptions || {});
|
|
429
|
-
const validation = validateResourceMetadata(item.resource, options.validation || {});
|
|
430
|
-
if ((validation.warnings.length || validation.errors.length) && options.warn !== false && browserWindow()?.console?.warn) {
|
|
431
|
-
browserWindow().console.warn("Nibgate content metadata needs attention", validation);
|
|
432
|
-
}
|
|
433
|
-
item.content({ source: options.source, metadataQuality: { score: validation.score, warnings: validation.warnings, errors: validation.errors }, ...options.content || {} });
|
|
434
|
-
item.view({
|
|
435
|
-
source: options.source,
|
|
436
|
-
path: options.path || browserWindow()?.location?.pathname || item.resource.path,
|
|
437
|
-
referrer: options.referrer ?? browserWindow()?.document?.referrer ?? "",
|
|
438
|
-
...options.view || {}
|
|
439
|
-
});
|
|
440
|
-
return item;
|
|
441
|
-
}
|
|
442
|
-
function setupResourcePage(resource, options = {}) {
|
|
443
|
-
const item = trackResourcePage(resource, options);
|
|
444
|
-
const win = browserWindow();
|
|
445
|
-
if (!win) return item;
|
|
446
|
-
const button = typeof options.button === "string" ? win.document.querySelector(options.button) : options.button;
|
|
447
|
-
const statusElement = typeof options.status === "string" ? win.document.querySelector(options.status) : options.status;
|
|
448
|
-
const setStatus = options.onStatus || ((message) => {
|
|
449
|
-
if (statusElement) statusElement.textContent = message || "";
|
|
450
|
-
});
|
|
451
|
-
if (button) {
|
|
452
|
-
button.addEventListener("click", async () => {
|
|
453
|
-
button.disabled = true;
|
|
454
|
-
try {
|
|
455
|
-
await checkResourceAccess(resource, { ...options, onStatus: setStatus });
|
|
456
|
-
} finally {
|
|
457
|
-
button.disabled = false;
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
return item;
|
|
462
|
-
}
|
|
463
|
-
var init_track = __esm({
|
|
464
|
-
"src/browser/track.js"() {
|
|
465
|
-
init_resource();
|
|
466
|
-
init_env();
|
|
467
|
-
init_gate();
|
|
468
|
-
init_access();
|
|
469
|
-
}
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
// src/browser/access.js
|
|
473
|
-
async function checkResourceAccess(resource, options = {}) {
|
|
474
|
-
const item = createGate(resource, options.gateOptions || {});
|
|
475
|
-
const accessPath = options.accessPath || item.resource.accessPath || "/api/nibgate/access";
|
|
476
|
-
const status2 = typeof options.onStatus === "function" ? options.onStatus : () => {
|
|
477
|
-
};
|
|
478
|
-
status2(options.checkingMessage || "Checking access route...");
|
|
479
|
-
item.unlockStarted({ source: options.source, paymentProvider: options.paymentProvider || "nibgate-access-route" });
|
|
480
|
-
const response = await fetch(accessPath, {
|
|
481
|
-
method: options.method || "GET",
|
|
482
|
-
headers: {
|
|
483
|
-
accept: "application/json",
|
|
484
|
-
...getPaymentProof(item.resource) ? { "x-nibgate-payment-proof": getPaymentProof(item.resource) } : {},
|
|
485
|
-
...options.headers || {}
|
|
486
|
-
},
|
|
487
|
-
body: options.body
|
|
488
|
-
});
|
|
489
|
-
const payload = await response.json().catch(() => ({}));
|
|
490
|
-
if (response.status === 402) {
|
|
491
|
-
item.track("payment_challenge_returned", { source: options.source, challenge: payload, resource: item.resource });
|
|
492
|
-
status2(options.challengeMessage || "Payment challenge returned. Continue with checkout.");
|
|
493
|
-
if (typeof options.createPaymentSignature === "function" || typeof options.checkout === "function") {
|
|
494
|
-
return payWithPaymentSignature(resource, {
|
|
495
|
-
...options,
|
|
496
|
-
challenge: payload,
|
|
497
|
-
paymentRequiredHeader: response.headers.get("PAYMENT-REQUIRED") || response.headers.get("payment-required") || ""
|
|
498
|
-
});
|
|
499
|
-
}
|
|
500
|
-
if (options.autoPay && options.payPath) {
|
|
501
|
-
const paymentResult = await payAndUnlockResource(resource, options);
|
|
502
|
-
if (paymentResult.ok && options.retryAfterPay !== false) {
|
|
503
|
-
return checkResourceAccess(resource, { ...options, autoPay: false });
|
|
504
|
-
}
|
|
505
|
-
return paymentResult;
|
|
506
|
-
}
|
|
507
|
-
return { ok: false, status: response.status, challenge: payload, resource: item.resource, response };
|
|
508
|
-
}
|
|
509
|
-
if (!response.ok) {
|
|
510
|
-
status2(payload.error || options.errorMessage || "Access check failed");
|
|
511
|
-
return { ok: false, status: response.status, error: payload.error || "Access check failed", payload, resource: item.resource, response };
|
|
512
|
-
}
|
|
513
|
-
const payment = options.payment || payload.payment || null;
|
|
514
|
-
if (payment) {
|
|
515
|
-
item.unlockCompleted(payment);
|
|
516
|
-
item.paymentCompleted(payment);
|
|
517
|
-
}
|
|
518
|
-
status2(options.successMessage || "Access allowed and Nibgate events emitted.");
|
|
519
|
-
return { ok: true, status: response.status, payload, payment, resource: item.resource, response };
|
|
520
|
-
}
|
|
521
|
-
async function payWithPaymentSignature(resource, options = {}) {
|
|
522
|
-
const item = createGate(resource, options.gateOptions || {});
|
|
523
|
-
const accessPath = options.accessPath || item.resource.accessPath || "/api/nibgate/access";
|
|
524
|
-
const status2 = typeof options.onStatus === "function" ? options.onStatus : () => {
|
|
525
|
-
};
|
|
526
|
-
status2(options.paymentMessage || "Waiting for wallet payment approval...");
|
|
527
|
-
item.unlockStarted({ source: options.source, paymentProvider: options.paymentProvider || "wallet-gateway" });
|
|
528
|
-
let paymentSignature = options.paymentSignature || "";
|
|
529
|
-
let paymentMemo = options.memo || "";
|
|
530
|
-
let paymentMetadata = options.payment || {};
|
|
531
|
-
if (!paymentSignature) {
|
|
532
|
-
const paymentRequiredHeader = options.paymentRequiredHeader || "";
|
|
533
|
-
const challenge2 = options.challenge || null;
|
|
534
|
-
const checkout = options.createPaymentSignature || options.checkout;
|
|
535
|
-
const result = await checkout({
|
|
536
|
-
resource: item.resource,
|
|
537
|
-
challenge: challenge2,
|
|
538
|
-
paymentRequiredHeader,
|
|
539
|
-
accessPath
|
|
540
|
-
});
|
|
541
|
-
paymentSignature = result?.paymentSignature || result?.signature || result?.payment || "";
|
|
542
|
-
paymentMemo = result?.memo || result?.paymentMemo || "";
|
|
543
|
-
paymentMetadata = result?.metadata || result?.paymentMetadata || result || {};
|
|
544
|
-
}
|
|
545
|
-
if (!paymentSignature) {
|
|
546
|
-
const error = "Wallet did not return a payment signature.";
|
|
547
|
-
item.track("payment_failed", { source: options.source, error });
|
|
548
|
-
status2(error);
|
|
549
|
-
return { ok: false, status: 400, error, resource: item.resource };
|
|
550
|
-
}
|
|
551
|
-
const response = await fetch(accessPath, {
|
|
552
|
-
method: options.method || "GET",
|
|
553
|
-
headers: {
|
|
554
|
-
accept: "application/json",
|
|
555
|
-
"payment-signature": paymentSignature,
|
|
556
|
-
...paymentMemo ? { "payment-memo": paymentMemo } : {},
|
|
557
|
-
...options.headers || {}
|
|
558
|
-
}
|
|
559
|
-
});
|
|
560
|
-
const responseText = await response.text();
|
|
561
|
-
let payload = {};
|
|
562
|
-
try {
|
|
563
|
-
payload = responseText ? JSON.parse(responseText) : {};
|
|
564
|
-
} catch (_error) {
|
|
565
|
-
payload = { error: responseText || "Payment verification failed" };
|
|
566
|
-
}
|
|
567
|
-
if (!response.ok) {
|
|
568
|
-
const detail = payload.detail || payload.reason || payload.invalidReason || payload.error || responseText || "Payment verification failed";
|
|
569
|
-
const error = typeof detail === "string" ? detail : stringifyJson(detail);
|
|
570
|
-
item.track("payment_failed", { source: options.source, status: response.status, error, ...paymentMetadata });
|
|
571
|
-
status2(options.paymentErrorMessage || error);
|
|
572
|
-
return { ok: false, status: response.status, error, payload, resource: item.resource, response };
|
|
573
|
-
}
|
|
574
|
-
const payment = payload.payment || {
|
|
575
|
-
paymentProvider: options.paymentProvider || "wallet-gateway",
|
|
576
|
-
paymentId: paymentSignature,
|
|
577
|
-
memo: paymentMemo,
|
|
578
|
-
amount: Number(item.resource.price || 0),
|
|
579
|
-
revenue: Number(item.resource.price || 0),
|
|
580
|
-
currency: item.resource.currency || "USDC",
|
|
581
|
-
...paymentMetadata
|
|
582
|
-
};
|
|
583
|
-
storePaymentProof(item.resource, payload.unlockProof);
|
|
584
|
-
item.markUnlocked(payment);
|
|
585
|
-
status2(options.paymentSuccessMessage || "Payment verified. Content unlocked.");
|
|
586
|
-
return { ok: true, status: response.status, payload, payment, resource: item.resource, response };
|
|
587
|
-
}
|
|
588
|
-
async function payAndUnlockResource(resource, options = {}) {
|
|
589
|
-
const item = createGate(resource, options.gateOptions || {});
|
|
590
|
-
const payPath = options.payPath || item.resource.payPath || "/api/nibgate/pay";
|
|
591
|
-
const status2 = typeof options.onStatus === "function" ? options.onStatus : () => {
|
|
592
|
-
};
|
|
593
|
-
status2(options.paymentMessage || "Starting payment...");
|
|
594
|
-
item.unlockStarted({ source: options.source, paymentProvider: options.paymentProvider || "circle-gateway" });
|
|
595
|
-
const response = await fetch(payPath, {
|
|
596
|
-
method: options.payMethod || "POST",
|
|
597
|
-
headers: {
|
|
598
|
-
accept: "application/json",
|
|
599
|
-
"content-type": "application/json",
|
|
600
|
-
...options.payHeaders || {}
|
|
601
|
-
},
|
|
602
|
-
body: JSON.stringify({ resource: item.resource, ...options.payPayload || {} })
|
|
603
|
-
});
|
|
604
|
-
const payload = await response.json().catch(() => ({}));
|
|
605
|
-
if (!response.ok || !payload.ok) {
|
|
606
|
-
item.track("payment_failed", { source: options.source, status: response.status, error: payload.error || "Payment failed", detail: payload.detail || "" });
|
|
607
|
-
status2(payload.detail || payload.error || options.paymentErrorMessage || "Payment failed.");
|
|
608
|
-
return { ok: false, status: response.status, payload, resource: item.resource, response };
|
|
609
|
-
}
|
|
610
|
-
const payment = payload.payment || {
|
|
611
|
-
paymentProvider: options.paymentProvider || "circle-gateway",
|
|
612
|
-
paymentId: payload.paymentId || `nibgate_payment_${Date.now()}`,
|
|
613
|
-
amount: Number(item.resource.price || 0),
|
|
614
|
-
revenue: Number(item.resource.price || 0),
|
|
615
|
-
currency: item.resource.currency || "USDC"
|
|
616
|
-
};
|
|
617
|
-
storePaymentProof(item.resource, payload.unlockProof);
|
|
618
|
-
item.markUnlocked(payment);
|
|
619
|
-
status2(options.paymentSuccessMessage || "Payment verified. Content unlocked.");
|
|
620
|
-
return { ok: true, status: response.status, payload, payment, resource: item.resource, response };
|
|
621
|
-
}
|
|
622
|
-
var init_access = __esm({
|
|
623
|
-
"src/browser/access.js"() {
|
|
624
|
-
init_events();
|
|
625
|
-
init_storage();
|
|
626
|
-
init_json();
|
|
627
|
-
init_gate();
|
|
628
|
-
}
|
|
629
|
-
});
|
|
630
|
-
|
|
631
426
|
// src/core/rating.js
|
|
632
427
|
function normalizeRating(input = {}) {
|
|
633
428
|
const value = typeof input === "number" ? input : input.rating ?? input.stars ?? input.ratingValue ?? input.score;
|
|
@@ -26806,232 +26601,34 @@ ${prettyStateOverride(stateOverride)}`;
|
|
|
26806
26601
|
}
|
|
26807
26602
|
});
|
|
26808
26603
|
|
|
26809
|
-
// src/browser/
|
|
26810
|
-
|
|
26811
|
-
|
|
26812
|
-
return gateway.createCircleGatewayBrowserAdapter(options);
|
|
26604
|
+
// src/browser/reputation.js
|
|
26605
|
+
function stripHex(value = "") {
|
|
26606
|
+
return String(value || "").replace(/^0x/i, "").replace(/[^0-9a-fA-F]/g, "").toLowerCase();
|
|
26813
26607
|
}
|
|
26814
|
-
function
|
|
26815
|
-
|
|
26816
|
-
|
|
26608
|
+
function wordRight(hex = "") {
|
|
26609
|
+
const clean2 = stripHex(hex);
|
|
26610
|
+
if (clean2.length > 64) throw new Error("ABI word is too long.");
|
|
26611
|
+
return clean2.padEnd(64, "0");
|
|
26817
26612
|
}
|
|
26818
|
-
function
|
|
26819
|
-
|
|
26820
|
-
|
|
26821
|
-
|
|
26822
|
-
|
|
26823
|
-
|
|
26824
|
-
|
|
26825
|
-
const
|
|
26826
|
-
const
|
|
26827
|
-
const
|
|
26828
|
-
|
|
26829
|
-
|
|
26830
|
-
|
|
26831
|
-
|
|
26832
|
-
|
|
26833
|
-
|
|
26834
|
-
|
|
26835
|
-
|
|
26836
|
-
|
|
26837
|
-
function shortAddress(address) {
|
|
26838
|
-
return address ? `${address.slice(0, 6)}...${address.slice(-4)}` : "";
|
|
26839
|
-
}
|
|
26840
|
-
function provider() {
|
|
26841
|
-
return win?.ethereum || options.provider || null;
|
|
26842
|
-
}
|
|
26843
|
-
function setBusy(value) {
|
|
26844
|
-
busy = Boolean(value);
|
|
26845
|
-
[connectButton, disconnectButton, unlockButton, clearButton].forEach((button) => {
|
|
26846
|
-
if (button && "disabled" in button) {
|
|
26847
|
-
button.disabled = busy || button === connectButton && !provider() || button === disconnectButton && !walletAddress;
|
|
26848
|
-
}
|
|
26849
|
-
});
|
|
26850
|
-
}
|
|
26851
|
-
function renderWallet() {
|
|
26852
|
-
const hasProvider = Boolean(provider());
|
|
26853
|
-
if (walletLabel) walletLabel.textContent = walletAddress ? shortAddress(walletAddress) : hasProvider ? "Ready to connect" : "No wallet detected";
|
|
26854
|
-
if (connectButton) connectButton.textContent = walletAddress ? "Connected" : "Connect wallet";
|
|
26855
|
-
if (disconnectButton) disconnectButton.textContent = "Disconnect";
|
|
26856
|
-
if (connectButton && "disabled" in connectButton) connectButton.disabled = busy || !hasProvider;
|
|
26857
|
-
if (disconnectButton && "disabled" in disconnectButton) disconnectButton.disabled = busy || !walletAddress;
|
|
26858
|
-
}
|
|
26859
|
-
function setUnlocked(isUnlocked, payment = {}) {
|
|
26860
|
-
if (unlockButton) unlockButton.textContent = isUnlocked ? "Unlocked" : `Unlock for ${item.resource.price} ${item.resource.currency || "USDC"}`;
|
|
26861
|
-
if (unlockedTarget) {
|
|
26862
|
-
if ("hidden" in unlockedTarget) unlockedTarget.hidden = !isUnlocked;
|
|
26863
|
-
unlockedTarget.setAttribute("aria-hidden", isUnlocked ? "false" : "true");
|
|
26864
|
-
}
|
|
26865
|
-
if (isUnlocked) item.markUnlocked(payment);
|
|
26866
|
-
}
|
|
26867
|
-
async function connect() {
|
|
26868
|
-
setBusy(true);
|
|
26869
|
-
setStatus("Opening wallet connection...");
|
|
26870
|
-
try {
|
|
26871
|
-
const evm = provider();
|
|
26872
|
-
if (!evm) throw new Error(options.noWalletMessage || "Install or open an EVM wallet to continue.");
|
|
26873
|
-
const accounts = await evm.request({ method: "eth_requestAccounts" });
|
|
26874
|
-
walletAddress = Array.isArray(accounts) ? accounts[0] || "" : "";
|
|
26875
|
-
if (!walletAddress) throw new Error("No wallet account selected.");
|
|
26876
|
-
renderWallet();
|
|
26877
|
-
setStatus("Wallet connected. You can unlock now.");
|
|
26878
|
-
return walletAddress;
|
|
26879
|
-
} finally {
|
|
26880
|
-
setBusy(false);
|
|
26881
|
-
}
|
|
26882
|
-
}
|
|
26883
|
-
async function disconnect() {
|
|
26884
|
-
setBusy(true);
|
|
26885
|
-
try {
|
|
26886
|
-
const evm = provider();
|
|
26887
|
-
if (evm?.request && walletAddress) {
|
|
26888
|
-
try {
|
|
26889
|
-
await evm.request({ method: "wallet_revokePermissions", params: [{ eth_accounts: {} }] });
|
|
26890
|
-
} catch (_error) {
|
|
26891
|
-
}
|
|
26892
|
-
}
|
|
26893
|
-
walletAddress = "";
|
|
26894
|
-
renderWallet();
|
|
26895
|
-
setStatus(options.disconnectMessage || "Wallet disconnected for this page.");
|
|
26896
|
-
return true;
|
|
26897
|
-
} finally {
|
|
26898
|
-
setBusy(false);
|
|
26899
|
-
}
|
|
26900
|
-
}
|
|
26901
|
-
async function checkout(input) {
|
|
26902
|
-
const evm = provider();
|
|
26903
|
-
if (!evm) throw new Error(options.noWalletMessage || "Install or open an EVM wallet to continue.");
|
|
26904
|
-
const currentAccounts = await evm.request({ method: "eth_accounts" }).catch(() => walletAddress ? [walletAddress] : []);
|
|
26905
|
-
const currentAddress = Array.isArray(currentAccounts) && currentAccounts[0] ? currentAccounts[0] : walletAddress || await connect();
|
|
26906
|
-
if (currentAddress !== walletAddress) walletAddress = currentAddress;
|
|
26907
|
-
const gatewayWallet = await createCircleGatewayBrowserAdapter2({
|
|
26908
|
-
network,
|
|
26909
|
-
signer: {
|
|
26910
|
-
address: currentAddress,
|
|
26911
|
-
signTypedData: async (typedData) => {
|
|
26912
|
-
const { createWalletClient: createWalletClient2, custom: custom2 } = await Promise.resolve().then(() => (init_esm(), esm_exports));
|
|
26913
|
-
const wc = createWalletClient2({ transport: custom2(evm) });
|
|
26914
|
-
return wc.signTypedData({
|
|
26915
|
-
account: currentAddress,
|
|
26916
|
-
domain: typedData.domain,
|
|
26917
|
-
types: typedData.types,
|
|
26918
|
-
primaryType: typedData.primaryType,
|
|
26919
|
-
message: typedData.message
|
|
26920
|
-
});
|
|
26921
|
-
}
|
|
26922
|
-
},
|
|
26923
|
-
clientModule: options.circleClientModule
|
|
26924
|
-
});
|
|
26925
|
-
return gatewayWallet.pay(input);
|
|
26926
|
-
}
|
|
26927
|
-
async function unlock() {
|
|
26928
|
-
setBusy(true);
|
|
26929
|
-
try {
|
|
26930
|
-
if (!walletAddress) await connect();
|
|
26931
|
-
setBusy(true);
|
|
26932
|
-
setStatus("Requesting Gateway unlock...");
|
|
26933
|
-
const result = await checkResourceAccess(item.resource, {
|
|
26934
|
-
accessPath,
|
|
26935
|
-
source,
|
|
26936
|
-
paymentProvider: options.paymentProvider || "circle-gateway-browser",
|
|
26937
|
-
challengeMessage: options.challengeMessage || "Gateway payment required. Connect your wallet to continue...",
|
|
26938
|
-
paymentMessage: options.paymentMessage || "Approve the Gateway payment proof in your wallet...",
|
|
26939
|
-
successMessage: options.successMessage || `Unlocked ${item.resource.title || "content"}.`,
|
|
26940
|
-
method: options.method,
|
|
26941
|
-
headers: options.headers,
|
|
26942
|
-
body: options.body,
|
|
26943
|
-
checkout,
|
|
26944
|
-
onStatus: setStatus
|
|
26945
|
-
});
|
|
26946
|
-
if (result.ok) {
|
|
26947
|
-
setUnlocked(true, result.payment || {});
|
|
26948
|
-
if (typeof options.onUnlock === "function") options.onUnlock(result);
|
|
26949
|
-
}
|
|
26950
|
-
return result;
|
|
26951
|
-
} catch (error) {
|
|
26952
|
-
const message = error?.message || "Unlock failed. Please try again.";
|
|
26953
|
-
setStatus(message);
|
|
26954
|
-
return { ok: false, status: 0, error: message, resource: item.resource };
|
|
26955
|
-
} finally {
|
|
26956
|
-
setBusy(false);
|
|
26957
|
-
renderWallet();
|
|
26958
|
-
}
|
|
26959
|
-
}
|
|
26960
|
-
function clear() {
|
|
26961
|
-
clearPaymentProof(item.resource);
|
|
26962
|
-
setUnlocked(false);
|
|
26963
|
-
setStatus("Local payment proof cleared. The next unlock will require Gateway payment again.");
|
|
26964
|
-
}
|
|
26965
|
-
async function hydrate() {
|
|
26966
|
-
const evm = provider();
|
|
26967
|
-
try {
|
|
26968
|
-
const accounts = evm ? await evm.request({ method: "eth_accounts" }) : [];
|
|
26969
|
-
walletAddress = Array.isArray(accounts) ? accounts[0] || "" : "";
|
|
26970
|
-
} catch {
|
|
26971
|
-
}
|
|
26972
|
-
renderWallet();
|
|
26973
|
-
setUnlocked(false);
|
|
26974
|
-
}
|
|
26975
|
-
function mount() {
|
|
26976
|
-
connectButton?.addEventListener?.("click", () => connect().catch((error) => setStatus(error?.message || "Could not connect wallet.")));
|
|
26977
|
-
disconnectButton?.addEventListener?.("click", () => disconnect().catch((error) => setStatus(error?.message || "Could not disconnect wallet.")));
|
|
26978
|
-
unlockButton?.addEventListener?.("click", () => unlock());
|
|
26979
|
-
clearButton?.addEventListener?.("click", clear);
|
|
26980
|
-
hydrate();
|
|
26981
|
-
trackResourcePage(item.resource, { source });
|
|
26982
|
-
return controller;
|
|
26983
|
-
}
|
|
26984
|
-
const controller = { resource: item.resource, connect, disconnect, unlock, clear, hydrate, mount, getWalletAddress: () => walletAddress };
|
|
26985
|
-
if (options.autoMount !== false) mount();
|
|
26986
|
-
return controller;
|
|
26987
|
-
}
|
|
26988
|
-
function createHostedUnlock(resource, options = {}) {
|
|
26989
|
-
return createEvmGatewayUnlock(resource, {
|
|
26990
|
-
...options,
|
|
26991
|
-
hosted: true,
|
|
26992
|
-
noWalletMessage: options.noWalletMessage || "Install MetaMask or another EVM wallet to unlock premium content."
|
|
26993
|
-
});
|
|
26994
|
-
}
|
|
26995
|
-
var HOSTED_PAY_URL;
|
|
26996
|
-
var init_evm_gateway = __esm({
|
|
26997
|
-
"src/browser/evm-gateway.js"() {
|
|
26998
|
-
init_env();
|
|
26999
|
-
init_storage();
|
|
27000
|
-
init_gate();
|
|
27001
|
-
init_access();
|
|
27002
|
-
init_track();
|
|
27003
|
-
HOSTED_PAY_URL = "https://api.nibgate.xyz/api/hub/pay";
|
|
27004
|
-
}
|
|
27005
|
-
});
|
|
27006
|
-
|
|
27007
|
-
// src/browser/reputation.js
|
|
27008
|
-
function stripHex(value = "") {
|
|
27009
|
-
return String(value || "").replace(/^0x/i, "").replace(/[^0-9a-fA-F]/g, "").toLowerCase();
|
|
27010
|
-
}
|
|
27011
|
-
function wordRight(hex = "") {
|
|
27012
|
-
const clean2 = stripHex(hex);
|
|
27013
|
-
if (clean2.length > 64) throw new Error("ABI word is too long.");
|
|
27014
|
-
return clean2.padEnd(64, "0");
|
|
27015
|
-
}
|
|
27016
|
-
function numberWord(value = 0) {
|
|
27017
|
-
return Number(value || 0).toString(16).padStart(64, "0");
|
|
27018
|
-
}
|
|
27019
|
-
function utf8Hex(value = "") {
|
|
27020
|
-
return Array.from(new TextEncoder().encode(String(value || ""))).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
27021
|
-
}
|
|
27022
|
-
function encodeString3(value = "") {
|
|
27023
|
-
const hex = utf8Hex(value);
|
|
27024
|
-
const byteLength = hex.length / 2;
|
|
27025
|
-
const paddedLength = Math.ceil(byteLength / 32) * 64;
|
|
27026
|
-
return numberWord(byteLength) + hex.padEnd(paddedLength, "0");
|
|
27027
|
-
}
|
|
27028
|
-
function encodeRateContent({ contentId, ratingValue, reviewHash, unlockRef }) {
|
|
27029
|
-
return RATE_CONTENT_SELECTOR + wordRight(contentId) + numberWord(ratingValue) + wordRight(reviewHash || ZERO_HASH) + numberWord(128) + encodeString3(unlockRef || "");
|
|
27030
|
-
}
|
|
27031
|
-
function contentRatingHash(_resource, options = {}) {
|
|
27032
|
-
const contentId = options.contentId || options.contentHash;
|
|
27033
|
-
if (!contentId) {
|
|
27034
|
-
throw new Error("contentId/contentHash is required. Use the Nibgate backend prepare endpoint or pass a known content hash.");
|
|
26613
|
+
function numberWord(value = 0) {
|
|
26614
|
+
return Number(value || 0).toString(16).padStart(64, "0");
|
|
26615
|
+
}
|
|
26616
|
+
function utf8Hex(value = "") {
|
|
26617
|
+
return Array.from(new TextEncoder().encode(String(value || ""))).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
26618
|
+
}
|
|
26619
|
+
function encodeString3(value = "") {
|
|
26620
|
+
const hex = utf8Hex(value);
|
|
26621
|
+
const byteLength = hex.length / 2;
|
|
26622
|
+
const paddedLength = Math.ceil(byteLength / 32) * 64;
|
|
26623
|
+
return numberWord(byteLength) + hex.padEnd(paddedLength, "0");
|
|
26624
|
+
}
|
|
26625
|
+
function encodeRateContent({ contentId, ratingValue, reviewHash, unlockRef }) {
|
|
26626
|
+
return RATE_CONTENT_SELECTOR + wordRight(contentId) + numberWord(ratingValue) + wordRight(reviewHash || ZERO_HASH) + numberWord(128) + encodeString3(unlockRef || "");
|
|
26627
|
+
}
|
|
26628
|
+
function contentRatingHash(_resource, options = {}) {
|
|
26629
|
+
const contentId = options.contentId || options.contentHash;
|
|
26630
|
+
if (!contentId) {
|
|
26631
|
+
throw new Error("contentId/contentHash is required. Use the Nibgate backend prepare endpoint or pass a known content hash.");
|
|
27035
26632
|
}
|
|
27036
26633
|
return contentId;
|
|
27037
26634
|
}
|
|
@@ -27287,13 +26884,654 @@ ${prettyStateOverride(stateOverride)}`;
|
|
|
27287
26884
|
}
|
|
27288
26885
|
});
|
|
27289
26886
|
|
|
27290
|
-
// src/browser/
|
|
27291
|
-
var
|
|
27292
|
-
__export(
|
|
26887
|
+
// src/browser/index.js
|
|
26888
|
+
var index_exports = {};
|
|
26889
|
+
__export(index_exports, {
|
|
26890
|
+
ACCESS_MODES: () => ACCESS_MODES,
|
|
26891
|
+
CONTENT_TYPES: () => CONTENT_TYPES,
|
|
26892
|
+
NIBGATE_CONTENT_HASH_NAMESPACE: () => NIBGATE_CONTENT_HASH_NAMESPACE,
|
|
26893
|
+
NIBGATE_CONTENT_SETTING_FIELDS: () => NIBGATE_CONTENT_SETTING_FIELDS,
|
|
26894
|
+
NIBGATE_REPUTATION_ABI: () => NIBGATE_REPUTATION_ABI,
|
|
26895
|
+
NIBGATE_REPUTATION_CHAIN_ID: () => NIBGATE_REPUTATION_CHAIN_ID,
|
|
26896
|
+
NIBGATE_REPUTATION_CHAIN_NAME: () => NIBGATE_REPUTATION_CHAIN_NAME,
|
|
26897
|
+
NIBGATE_REPUTATION_CONTRACT: () => NIBGATE_REPUTATION_CONTRACT,
|
|
26898
|
+
NIBGATE_REPUTATION_RPC_URL: () => NIBGATE_REPUTATION_RPC_URL,
|
|
26899
|
+
PAYMENT_RAILS: () => PAYMENT_RAILS,
|
|
26900
|
+
UNLOCK_MODES: () => UNLOCK_MODES,
|
|
26901
|
+
checkResourceAccess: () => checkResourceAccess,
|
|
26902
|
+
contentRatingHash: () => contentRatingHash,
|
|
26903
|
+
createCircleGatewayBrowserAdapter: () => createCircleGatewayBrowserAdapter2,
|
|
26904
|
+
createEvmGatewayUnlock: () => createEvmGatewayUnlock,
|
|
26905
|
+
createGate: () => createGate,
|
|
26906
|
+
createHostedUnlock: () => createHostedUnlock,
|
|
26907
|
+
createNibgate: () => createNibgate,
|
|
26908
|
+
createNibgateContentSettings: () => createNibgateContentSettings,
|
|
26909
|
+
createOnchainRating: () => createOnchainRating,
|
|
26910
|
+
createTransferCheckout: () => createTransferCheckout,
|
|
26911
|
+
createWalletCheckout: () => createWalletCheckout,
|
|
26912
|
+
mountRatingUI: () => mountRatingUI,
|
|
26913
|
+
nibgate: () => nibgate,
|
|
26914
|
+
normalizeAccessPolicy: () => normalizeAccessPolicy,
|
|
26915
|
+
normalizeContentType: () => normalizeContentType,
|
|
26916
|
+
normalizePaymentRail: () => normalizePaymentRail,
|
|
26917
|
+
normalizeResource: () => normalizeResource,
|
|
26918
|
+
normalizeUnlockPolicy: () => normalizeUnlockPolicy,
|
|
26919
|
+
payAndUnlockResource: () => payAndUnlockResource,
|
|
26920
|
+
payWithPaymentSignature: () => payWithPaymentSignature,
|
|
26921
|
+
payWithTransfer: () => payWithTransfer,
|
|
26922
|
+
rateContentOnchain: () => rateContentOnchain,
|
|
26923
|
+
rateResource: () => rateResource,
|
|
27293
26924
|
renderDefaultGatewayWalletUI: () => renderDefaultGatewayWalletUI,
|
|
27294
26925
|
renderDefaultRatingUI: () => renderDefaultRatingUI,
|
|
27295
|
-
renderDefaultUnlockUI: () => renderDefaultUnlockUI
|
|
26926
|
+
renderDefaultUnlockUI: () => renderDefaultUnlockUI,
|
|
26927
|
+
reviewTextHash: () => reviewTextHash,
|
|
26928
|
+
settingsToAccessPolicy: () => settingsToAccessPolicy,
|
|
26929
|
+
settingsToUnlockPolicy: () => settingsToUnlockPolicy,
|
|
26930
|
+
setupResourcePage: () => setupResourcePage,
|
|
26931
|
+
trackResourcePage: () => trackResourcePage,
|
|
26932
|
+
validateResourceMetadata: () => validateResourceMetadata
|
|
27296
26933
|
});
|
|
26934
|
+
init_gate();
|
|
26935
|
+
|
|
26936
|
+
// src/browser/access.js
|
|
26937
|
+
init_events();
|
|
26938
|
+
init_storage();
|
|
26939
|
+
init_json();
|
|
26940
|
+
init_gate();
|
|
26941
|
+
|
|
26942
|
+
// src/browser/track.js
|
|
26943
|
+
init_resource();
|
|
26944
|
+
init_env();
|
|
26945
|
+
init_gate();
|
|
26946
|
+
function trackResourcePage(resource, options = {}) {
|
|
26947
|
+
const item = createGate(resource, options.gateOptions || {});
|
|
26948
|
+
const validation = validateResourceMetadata(item.resource, options.validation || {});
|
|
26949
|
+
if ((validation.warnings.length || validation.errors.length) && options.warn !== false && browserWindow()?.console?.warn) {
|
|
26950
|
+
browserWindow().console.warn("Nibgate content metadata needs attention", validation);
|
|
26951
|
+
}
|
|
26952
|
+
item.content({ source: options.source, metadataQuality: { score: validation.score, warnings: validation.warnings, errors: validation.errors }, ...options.content || {} });
|
|
26953
|
+
item.view({
|
|
26954
|
+
source: options.source,
|
|
26955
|
+
path: options.path || browserWindow()?.location?.pathname || item.resource.path,
|
|
26956
|
+
referrer: options.referrer ?? browserWindow()?.document?.referrer ?? "",
|
|
26957
|
+
...options.view || {}
|
|
26958
|
+
});
|
|
26959
|
+
return item;
|
|
26960
|
+
}
|
|
26961
|
+
function setupResourcePage(resource, options = {}) {
|
|
26962
|
+
const item = trackResourcePage(resource, options);
|
|
26963
|
+
const win = browserWindow();
|
|
26964
|
+
if (!win) return item;
|
|
26965
|
+
const button = typeof options.button === "string" ? win.document.querySelector(options.button) : options.button;
|
|
26966
|
+
const statusElement = typeof options.status === "string" ? win.document.querySelector(options.status) : options.status;
|
|
26967
|
+
const setStatus = options.onStatus || ((message) => {
|
|
26968
|
+
if (statusElement) statusElement.textContent = message || "";
|
|
26969
|
+
});
|
|
26970
|
+
if (button) {
|
|
26971
|
+
button.addEventListener("click", async () => {
|
|
26972
|
+
button.disabled = true;
|
|
26973
|
+
try {
|
|
26974
|
+
await checkResourceAccess(resource, { ...options, onStatus: setStatus });
|
|
26975
|
+
} finally {
|
|
26976
|
+
button.disabled = false;
|
|
26977
|
+
}
|
|
26978
|
+
});
|
|
26979
|
+
}
|
|
26980
|
+
return item;
|
|
26981
|
+
}
|
|
26982
|
+
|
|
26983
|
+
// src/browser/access.js
|
|
26984
|
+
async function checkResourceAccess(resource, options = {}) {
|
|
26985
|
+
const item = createGate(resource, options.gateOptions || {});
|
|
26986
|
+
const accessPath = options.accessPath || item.resource.accessPath || "/api/nibgate/access";
|
|
26987
|
+
const status2 = typeof options.onStatus === "function" ? options.onStatus : () => {
|
|
26988
|
+
};
|
|
26989
|
+
status2(options.checkingMessage || "Checking access route...");
|
|
26990
|
+
item.unlockStarted({ source: options.source, paymentProvider: options.paymentProvider || "nibgate-access-route" });
|
|
26991
|
+
const response = await fetch(accessPath, {
|
|
26992
|
+
method: options.method || "GET",
|
|
26993
|
+
headers: {
|
|
26994
|
+
accept: "application/json",
|
|
26995
|
+
...getPaymentProof(item.resource) ? { "x-nibgate-payment-proof": getPaymentProof(item.resource) } : {},
|
|
26996
|
+
...options.headers || {}
|
|
26997
|
+
},
|
|
26998
|
+
body: options.body
|
|
26999
|
+
});
|
|
27000
|
+
const payload = await response.json().catch(() => ({}));
|
|
27001
|
+
if (response.status === 402) {
|
|
27002
|
+
item.track("payment_challenge_returned", { source: options.source, challenge: payload, resource: item.resource });
|
|
27003
|
+
status2(options.challengeMessage || "Payment challenge returned. Continue with checkout.");
|
|
27004
|
+
if (typeof options.createPaymentSignature === "function" || typeof options.checkout === "function") {
|
|
27005
|
+
return payWithPaymentSignature(resource, {
|
|
27006
|
+
...options,
|
|
27007
|
+
challenge: payload,
|
|
27008
|
+
paymentRequiredHeader: response.headers.get("PAYMENT-REQUIRED") || response.headers.get("payment-required") || ""
|
|
27009
|
+
});
|
|
27010
|
+
}
|
|
27011
|
+
if (options.autoPay && options.payPath) {
|
|
27012
|
+
const paymentResult = await payAndUnlockResource(resource, options);
|
|
27013
|
+
if (paymentResult.ok && options.retryAfterPay !== false) {
|
|
27014
|
+
return checkResourceAccess(resource, { ...options, autoPay: false });
|
|
27015
|
+
}
|
|
27016
|
+
return paymentResult;
|
|
27017
|
+
}
|
|
27018
|
+
return { ok: false, status: response.status, challenge: payload, resource: item.resource, response };
|
|
27019
|
+
}
|
|
27020
|
+
if (!response.ok) {
|
|
27021
|
+
status2(payload.error || options.errorMessage || "Access check failed");
|
|
27022
|
+
return { ok: false, status: response.status, error: payload.error || "Access check failed", payload, resource: item.resource, response };
|
|
27023
|
+
}
|
|
27024
|
+
const payment = options.payment || payload.payment || null;
|
|
27025
|
+
if (payment) {
|
|
27026
|
+
item.unlockCompleted(payment);
|
|
27027
|
+
item.paymentCompleted(payment);
|
|
27028
|
+
}
|
|
27029
|
+
status2(options.successMessage || "Access allowed and Nibgate events emitted.");
|
|
27030
|
+
return { ok: true, status: response.status, payload, payment, resource: item.resource, response };
|
|
27031
|
+
}
|
|
27032
|
+
async function payWithPaymentSignature(resource, options = {}) {
|
|
27033
|
+
const item = createGate(resource, options.gateOptions || {});
|
|
27034
|
+
const accessPath = options.accessPath || item.resource.accessPath || "/api/nibgate/access";
|
|
27035
|
+
const status2 = typeof options.onStatus === "function" ? options.onStatus : () => {
|
|
27036
|
+
};
|
|
27037
|
+
status2(options.paymentMessage || "Waiting for wallet payment approval...");
|
|
27038
|
+
item.unlockStarted({ source: options.source, paymentProvider: options.paymentProvider || "wallet-gateway" });
|
|
27039
|
+
let paymentSignature = options.paymentSignature || "";
|
|
27040
|
+
let paymentMemo = options.memo || "";
|
|
27041
|
+
let paymentMetadata = options.payment || {};
|
|
27042
|
+
if (!paymentSignature) {
|
|
27043
|
+
const paymentRequiredHeader = options.paymentRequiredHeader || "";
|
|
27044
|
+
const challenge2 = options.challenge || null;
|
|
27045
|
+
const checkout = options.createPaymentSignature || options.checkout;
|
|
27046
|
+
const result = await checkout({
|
|
27047
|
+
resource: item.resource,
|
|
27048
|
+
challenge: challenge2,
|
|
27049
|
+
paymentRequiredHeader,
|
|
27050
|
+
accessPath
|
|
27051
|
+
});
|
|
27052
|
+
paymentSignature = result?.paymentSignature || result?.signature || result?.payment || "";
|
|
27053
|
+
paymentMemo = result?.memo || result?.paymentMemo || "";
|
|
27054
|
+
paymentMetadata = result?.metadata || result?.paymentMetadata || result || {};
|
|
27055
|
+
}
|
|
27056
|
+
if (!paymentSignature) {
|
|
27057
|
+
const error = "Wallet did not return a payment signature.";
|
|
27058
|
+
item.track("payment_failed", { source: options.source, error });
|
|
27059
|
+
status2(error);
|
|
27060
|
+
return { ok: false, status: 400, error, resource: item.resource };
|
|
27061
|
+
}
|
|
27062
|
+
const response = await fetch(accessPath, {
|
|
27063
|
+
method: options.method || "GET",
|
|
27064
|
+
headers: {
|
|
27065
|
+
accept: "application/json",
|
|
27066
|
+
"payment-signature": paymentSignature,
|
|
27067
|
+
...paymentMemo ? { "payment-memo": paymentMemo } : {},
|
|
27068
|
+
...options.headers || {}
|
|
27069
|
+
}
|
|
27070
|
+
});
|
|
27071
|
+
const responseText = await response.text();
|
|
27072
|
+
let payload = {};
|
|
27073
|
+
try {
|
|
27074
|
+
payload = responseText ? JSON.parse(responseText) : {};
|
|
27075
|
+
} catch (_error) {
|
|
27076
|
+
payload = { error: responseText || "Payment verification failed" };
|
|
27077
|
+
}
|
|
27078
|
+
if (!response.ok) {
|
|
27079
|
+
const detail = payload.detail || payload.reason || payload.invalidReason || payload.error || responseText || "Payment verification failed";
|
|
27080
|
+
const error = typeof detail === "string" ? detail : stringifyJson(detail);
|
|
27081
|
+
item.track("payment_failed", { source: options.source, status: response.status, error, ...paymentMetadata });
|
|
27082
|
+
status2(options.paymentErrorMessage || error);
|
|
27083
|
+
return { ok: false, status: response.status, error, payload, resource: item.resource, response };
|
|
27084
|
+
}
|
|
27085
|
+
const payment = payload.payment || {
|
|
27086
|
+
paymentProvider: options.paymentProvider || "wallet-gateway",
|
|
27087
|
+
paymentId: paymentSignature,
|
|
27088
|
+
memo: paymentMemo,
|
|
27089
|
+
amount: Number(item.resource.price || 0),
|
|
27090
|
+
revenue: Number(item.resource.price || 0),
|
|
27091
|
+
currency: item.resource.currency || "USDC",
|
|
27092
|
+
...paymentMetadata
|
|
27093
|
+
};
|
|
27094
|
+
storePaymentProof(item.resource, payload.unlockProof);
|
|
27095
|
+
item.markUnlocked(payment);
|
|
27096
|
+
status2(options.paymentSuccessMessage || "Payment verified. Content unlocked.");
|
|
27097
|
+
return { ok: true, status: response.status, payload, payment, resource: item.resource, response };
|
|
27098
|
+
}
|
|
27099
|
+
async function payAndUnlockResource(resource, options = {}) {
|
|
27100
|
+
const item = createGate(resource, options.gateOptions || {});
|
|
27101
|
+
const payPath = options.payPath || item.resource.payPath || "/api/nibgate/pay";
|
|
27102
|
+
const status2 = typeof options.onStatus === "function" ? options.onStatus : () => {
|
|
27103
|
+
};
|
|
27104
|
+
status2(options.paymentMessage || "Starting payment...");
|
|
27105
|
+
item.unlockStarted({ source: options.source, paymentProvider: options.paymentProvider || "circle-gateway" });
|
|
27106
|
+
const response = await fetch(payPath, {
|
|
27107
|
+
method: options.payMethod || "POST",
|
|
27108
|
+
headers: {
|
|
27109
|
+
accept: "application/json",
|
|
27110
|
+
"content-type": "application/json",
|
|
27111
|
+
...options.payHeaders || {}
|
|
27112
|
+
},
|
|
27113
|
+
body: JSON.stringify({ resource: item.resource, ...options.payPayload || {} })
|
|
27114
|
+
});
|
|
27115
|
+
const payload = await response.json().catch(() => ({}));
|
|
27116
|
+
if (!response.ok || !payload.ok) {
|
|
27117
|
+
item.track("payment_failed", { source: options.source, status: response.status, error: payload.error || "Payment failed", detail: payload.detail || "" });
|
|
27118
|
+
status2(payload.detail || payload.error || options.paymentErrorMessage || "Payment failed.");
|
|
27119
|
+
return { ok: false, status: response.status, payload, resource: item.resource, response };
|
|
27120
|
+
}
|
|
27121
|
+
const payment = payload.payment || {
|
|
27122
|
+
paymentProvider: options.paymentProvider || "circle-gateway",
|
|
27123
|
+
paymentId: payload.paymentId || `nibgate_payment_${Date.now()}`,
|
|
27124
|
+
amount: Number(item.resource.price || 0),
|
|
27125
|
+
revenue: Number(item.resource.price || 0),
|
|
27126
|
+
currency: item.resource.currency || "USDC"
|
|
27127
|
+
};
|
|
27128
|
+
storePaymentProof(item.resource, payload.unlockProof);
|
|
27129
|
+
item.markUnlocked(payment);
|
|
27130
|
+
status2(options.paymentSuccessMessage || "Payment verified. Content unlocked.");
|
|
27131
|
+
return { ok: true, status: response.status, payload, payment, resource: item.resource, response };
|
|
27132
|
+
}
|
|
27133
|
+
|
|
27134
|
+
// src/browser/checkout.js
|
|
27135
|
+
init_resource();
|
|
27136
|
+
init_env();
|
|
27137
|
+
function setElementText(target, message) {
|
|
27138
|
+
const win = browserWindow();
|
|
27139
|
+
if (!target || !win) return;
|
|
27140
|
+
const element = typeof target === "string" ? win.document.querySelector(target) : target;
|
|
27141
|
+
if (element) element.textContent = message || "";
|
|
27142
|
+
}
|
|
27143
|
+
function setElementDisabled(target, disabled) {
|
|
27144
|
+
const win = browserWindow();
|
|
27145
|
+
if (!target || !win) return;
|
|
27146
|
+
const element = typeof target === "string" ? win.document.querySelector(target) : target;
|
|
27147
|
+
if (element && "disabled" in element) element.disabled = Boolean(disabled);
|
|
27148
|
+
}
|
|
27149
|
+
function createWalletCheckout(resource, options = {}) {
|
|
27150
|
+
const normalized = normalizeResource(resource);
|
|
27151
|
+
const accessPath = options.accessPath || normalized.accessPath || "/api/nibgate/access";
|
|
27152
|
+
const button = options.button || null;
|
|
27153
|
+
const statusTarget = options.status || null;
|
|
27154
|
+
const status2 = typeof options.onStatus === "function" ? options.onStatus : (message) => setElementText(statusTarget, message);
|
|
27155
|
+
const checkout = options.checkout || options.createPaymentSignature || options.pay;
|
|
27156
|
+
if (typeof checkout !== "function") {
|
|
27157
|
+
throw new Error("createWalletCheckout requires checkout/createPaymentSignature/pay callback for the active wallet or Gateway adapter.");
|
|
27158
|
+
}
|
|
27159
|
+
async function unlock(extra = {}) {
|
|
27160
|
+
setElementDisabled(button, true);
|
|
27161
|
+
try {
|
|
27162
|
+
return await checkResourceAccess(normalized, {
|
|
27163
|
+
...options,
|
|
27164
|
+
...extra,
|
|
27165
|
+
accessPath,
|
|
27166
|
+
createPaymentSignature: checkout,
|
|
27167
|
+
onStatus: status2
|
|
27168
|
+
});
|
|
27169
|
+
} finally {
|
|
27170
|
+
setElementDisabled(button, false);
|
|
27171
|
+
}
|
|
27172
|
+
}
|
|
27173
|
+
function mount() {
|
|
27174
|
+
const win = browserWindow();
|
|
27175
|
+
if (!win || !button) return { unlock };
|
|
27176
|
+
const element = typeof button === "string" ? win.document.querySelector(button) : button;
|
|
27177
|
+
if (element) element.addEventListener("click", () => unlock().catch((error) => status2(error.message || "Checkout failed.")));
|
|
27178
|
+
return { unlock };
|
|
27179
|
+
}
|
|
27180
|
+
return { resource: normalized, unlock, mount };
|
|
27181
|
+
}
|
|
27182
|
+
|
|
27183
|
+
// src/browser/client.js
|
|
27184
|
+
init_resource();
|
|
27185
|
+
init_rating();
|
|
27186
|
+
init_events();
|
|
27187
|
+
init_gate();
|
|
27188
|
+
init_gate();
|
|
27189
|
+
|
|
27190
|
+
// src/browser/evm-gateway.js
|
|
27191
|
+
init_env();
|
|
27192
|
+
init_storage();
|
|
27193
|
+
init_gate();
|
|
27194
|
+
async function createCircleGatewayBrowserAdapter2(options = {}) {
|
|
27195
|
+
const gateway = await Promise.resolve().then(() => (init_gateway(), gateway_exports));
|
|
27196
|
+
return gateway.createCircleGatewayBrowserAdapter(options);
|
|
27197
|
+
}
|
|
27198
|
+
var HOSTED_PAY_URL = "https://api.nibgate.xyz/api/hub/pay";
|
|
27199
|
+
function resolveAccessPath(resource, options) {
|
|
27200
|
+
if (options.hosted || options.accessPath === "hosted") return HOSTED_PAY_URL;
|
|
27201
|
+
return options.accessPath || resource.accessPath || "/api/nibgate/access";
|
|
27202
|
+
}
|
|
27203
|
+
function createEvmGatewayUnlock(resource, options = {}) {
|
|
27204
|
+
const item = createGate(resource, options.gateOptions || {});
|
|
27205
|
+
const win = browserWindow();
|
|
27206
|
+
const accessPath = resolveAccessPath(item.resource, options);
|
|
27207
|
+
const source = options.source || "nibgate-evm-gateway";
|
|
27208
|
+
const network = options.network || "eip155:5042002";
|
|
27209
|
+
const statusTarget = typeof options.status === "string" ? win?.document.querySelector(options.status) : options.status;
|
|
27210
|
+
const connectButton = typeof options.connectButton === "string" ? win?.document.querySelector(options.connectButton) : options.connectButton;
|
|
27211
|
+
const disconnectButton = typeof options.disconnectButton === "string" ? win?.document.querySelector(options.disconnectButton) : options.disconnectButton;
|
|
27212
|
+
const unlockButton = typeof options.unlockButton === "string" ? win?.document.querySelector(options.unlockButton) : options.unlockButton;
|
|
27213
|
+
const clearButton = typeof options.clearButton === "string" ? win?.document.querySelector(options.clearButton) : options.clearButton;
|
|
27214
|
+
const walletLabel = typeof options.walletLabel === "string" ? win?.document.querySelector(options.walletLabel) : options.walletLabel;
|
|
27215
|
+
const unlockedTarget = typeof options.unlockedTarget === "string" ? win?.document.querySelector(options.unlockedTarget) : options.unlockedTarget;
|
|
27216
|
+
let walletAddress = "";
|
|
27217
|
+
let busy = false;
|
|
27218
|
+
function setStatus(message) {
|
|
27219
|
+
if (typeof options.onStatus === "function") options.onStatus(message);
|
|
27220
|
+
if (statusTarget) statusTarget.textContent = message || "";
|
|
27221
|
+
}
|
|
27222
|
+
function shortAddress(address) {
|
|
27223
|
+
return address ? `${address.slice(0, 6)}...${address.slice(-4)}` : "";
|
|
27224
|
+
}
|
|
27225
|
+
function provider() {
|
|
27226
|
+
return win?.ethereum || options.provider || null;
|
|
27227
|
+
}
|
|
27228
|
+
function setBusy(value) {
|
|
27229
|
+
busy = Boolean(value);
|
|
27230
|
+
[connectButton, disconnectButton, unlockButton, clearButton].forEach((button) => {
|
|
27231
|
+
if (button && "disabled" in button) {
|
|
27232
|
+
button.disabled = busy || button === connectButton && !provider() || button === disconnectButton && !walletAddress;
|
|
27233
|
+
}
|
|
27234
|
+
});
|
|
27235
|
+
}
|
|
27236
|
+
function renderWallet() {
|
|
27237
|
+
const hasProvider = Boolean(provider());
|
|
27238
|
+
if (walletLabel) walletLabel.textContent = walletAddress ? shortAddress(walletAddress) : hasProvider ? "Ready to connect" : "No wallet detected";
|
|
27239
|
+
if (connectButton) connectButton.textContent = walletAddress ? "Connected" : "Connect wallet";
|
|
27240
|
+
if (disconnectButton) disconnectButton.textContent = "Disconnect";
|
|
27241
|
+
if (connectButton && "disabled" in connectButton) connectButton.disabled = busy || !hasProvider;
|
|
27242
|
+
if (disconnectButton && "disabled" in disconnectButton) disconnectButton.disabled = busy || !walletAddress;
|
|
27243
|
+
}
|
|
27244
|
+
function setUnlocked(isUnlocked, payment = {}) {
|
|
27245
|
+
if (unlockButton) unlockButton.textContent = isUnlocked ? "Unlocked" : `Unlock for ${item.resource.price} ${item.resource.currency || "USDC"}`;
|
|
27246
|
+
if (unlockedTarget) {
|
|
27247
|
+
if ("hidden" in unlockedTarget) unlockedTarget.hidden = !isUnlocked;
|
|
27248
|
+
unlockedTarget.setAttribute("aria-hidden", isUnlocked ? "false" : "true");
|
|
27249
|
+
}
|
|
27250
|
+
if (isUnlocked) item.markUnlocked(payment);
|
|
27251
|
+
}
|
|
27252
|
+
async function connect() {
|
|
27253
|
+
setBusy(true);
|
|
27254
|
+
setStatus("Opening wallet connection...");
|
|
27255
|
+
try {
|
|
27256
|
+
const evm = provider();
|
|
27257
|
+
if (!evm) throw new Error(options.noWalletMessage || "Install or open an EVM wallet to continue.");
|
|
27258
|
+
const accounts = await evm.request({ method: "eth_requestAccounts" });
|
|
27259
|
+
walletAddress = Array.isArray(accounts) ? accounts[0] || "" : "";
|
|
27260
|
+
if (!walletAddress) throw new Error("No wallet account selected.");
|
|
27261
|
+
renderWallet();
|
|
27262
|
+
setStatus("Wallet connected. You can unlock now.");
|
|
27263
|
+
return walletAddress;
|
|
27264
|
+
} finally {
|
|
27265
|
+
setBusy(false);
|
|
27266
|
+
}
|
|
27267
|
+
}
|
|
27268
|
+
async function disconnect() {
|
|
27269
|
+
setBusy(true);
|
|
27270
|
+
try {
|
|
27271
|
+
const evm = provider();
|
|
27272
|
+
if (evm?.request && walletAddress) {
|
|
27273
|
+
try {
|
|
27274
|
+
await evm.request({ method: "wallet_revokePermissions", params: [{ eth_accounts: {} }] });
|
|
27275
|
+
} catch (_error) {
|
|
27276
|
+
}
|
|
27277
|
+
}
|
|
27278
|
+
walletAddress = "";
|
|
27279
|
+
renderWallet();
|
|
27280
|
+
setStatus(options.disconnectMessage || "Wallet disconnected for this page.");
|
|
27281
|
+
return true;
|
|
27282
|
+
} finally {
|
|
27283
|
+
setBusy(false);
|
|
27284
|
+
}
|
|
27285
|
+
}
|
|
27286
|
+
async function checkout(input) {
|
|
27287
|
+
const evm = provider();
|
|
27288
|
+
if (!evm) throw new Error(options.noWalletMessage || "Install or open an EVM wallet to continue.");
|
|
27289
|
+
const currentAccounts = await evm.request({ method: "eth_accounts" }).catch(() => walletAddress ? [walletAddress] : []);
|
|
27290
|
+
const currentAddress = Array.isArray(currentAccounts) && currentAccounts[0] ? currentAccounts[0] : walletAddress || await connect();
|
|
27291
|
+
if (currentAddress !== walletAddress) walletAddress = currentAddress;
|
|
27292
|
+
const gatewayWallet = await createCircleGatewayBrowserAdapter2({
|
|
27293
|
+
network,
|
|
27294
|
+
signer: {
|
|
27295
|
+
address: currentAddress,
|
|
27296
|
+
signTypedData: async (typedData) => {
|
|
27297
|
+
const { createWalletClient: createWalletClient2, custom: custom2 } = await Promise.resolve().then(() => (init_esm(), esm_exports));
|
|
27298
|
+
const wc = createWalletClient2({ transport: custom2(evm) });
|
|
27299
|
+
return wc.signTypedData({
|
|
27300
|
+
account: currentAddress,
|
|
27301
|
+
domain: typedData.domain,
|
|
27302
|
+
types: typedData.types,
|
|
27303
|
+
primaryType: typedData.primaryType,
|
|
27304
|
+
message: typedData.message
|
|
27305
|
+
});
|
|
27306
|
+
}
|
|
27307
|
+
},
|
|
27308
|
+
clientModule: options.circleClientModule
|
|
27309
|
+
});
|
|
27310
|
+
return gatewayWallet.pay(input);
|
|
27311
|
+
}
|
|
27312
|
+
async function unlock() {
|
|
27313
|
+
setBusy(true);
|
|
27314
|
+
try {
|
|
27315
|
+
if (!walletAddress) await connect();
|
|
27316
|
+
setBusy(true);
|
|
27317
|
+
setStatus("Requesting Gateway unlock...");
|
|
27318
|
+
const result = await checkResourceAccess(item.resource, {
|
|
27319
|
+
accessPath,
|
|
27320
|
+
source,
|
|
27321
|
+
paymentProvider: options.paymentProvider || "circle-gateway-browser",
|
|
27322
|
+
challengeMessage: options.challengeMessage || "Gateway payment required. Connect your wallet to continue...",
|
|
27323
|
+
paymentMessage: options.paymentMessage || "Approve the Gateway payment proof in your wallet...",
|
|
27324
|
+
successMessage: options.successMessage || `Unlocked ${item.resource.title || "content"}.`,
|
|
27325
|
+
method: options.method,
|
|
27326
|
+
headers: options.headers,
|
|
27327
|
+
body: options.body,
|
|
27328
|
+
checkout,
|
|
27329
|
+
onStatus: setStatus
|
|
27330
|
+
});
|
|
27331
|
+
if (result.ok) {
|
|
27332
|
+
setUnlocked(true, result.payment || {});
|
|
27333
|
+
if (typeof options.onUnlock === "function") options.onUnlock(result);
|
|
27334
|
+
}
|
|
27335
|
+
return result;
|
|
27336
|
+
} catch (error) {
|
|
27337
|
+
const message = error?.message || "Unlock failed. Please try again.";
|
|
27338
|
+
setStatus(message);
|
|
27339
|
+
return { ok: false, status: 0, error: message, resource: item.resource };
|
|
27340
|
+
} finally {
|
|
27341
|
+
setBusy(false);
|
|
27342
|
+
renderWallet();
|
|
27343
|
+
}
|
|
27344
|
+
}
|
|
27345
|
+
function clear() {
|
|
27346
|
+
clearPaymentProof(item.resource);
|
|
27347
|
+
setUnlocked(false);
|
|
27348
|
+
setStatus("Local payment proof cleared. The next unlock will require Gateway payment again.");
|
|
27349
|
+
}
|
|
27350
|
+
async function hydrate() {
|
|
27351
|
+
const evm = provider();
|
|
27352
|
+
try {
|
|
27353
|
+
const accounts = evm ? await evm.request({ method: "eth_accounts" }) : [];
|
|
27354
|
+
walletAddress = Array.isArray(accounts) ? accounts[0] || "" : "";
|
|
27355
|
+
} catch {
|
|
27356
|
+
}
|
|
27357
|
+
renderWallet();
|
|
27358
|
+
setUnlocked(false);
|
|
27359
|
+
}
|
|
27360
|
+
function mount() {
|
|
27361
|
+
connectButton?.addEventListener?.("click", () => connect().catch((error) => setStatus(error?.message || "Could not connect wallet.")));
|
|
27362
|
+
disconnectButton?.addEventListener?.("click", () => disconnect().catch((error) => setStatus(error?.message || "Could not disconnect wallet.")));
|
|
27363
|
+
unlockButton?.addEventListener?.("click", () => unlock());
|
|
27364
|
+
clearButton?.addEventListener?.("click", clear);
|
|
27365
|
+
hydrate();
|
|
27366
|
+
trackResourcePage(item.resource, { source });
|
|
27367
|
+
return controller;
|
|
27368
|
+
}
|
|
27369
|
+
const controller = { resource: item.resource, connect, disconnect, unlock, clear, hydrate, mount, getWalletAddress: () => walletAddress };
|
|
27370
|
+
if (options.autoMount !== false) mount();
|
|
27371
|
+
return controller;
|
|
27372
|
+
}
|
|
27373
|
+
function createHostedUnlock(resource, options = {}) {
|
|
27374
|
+
return createEvmGatewayUnlock(resource, {
|
|
27375
|
+
...options,
|
|
27376
|
+
hosted: true,
|
|
27377
|
+
noWalletMessage: options.noWalletMessage || "Install MetaMask or another EVM wallet to unlock premium content."
|
|
27378
|
+
});
|
|
27379
|
+
}
|
|
27380
|
+
|
|
27381
|
+
// src/browser/client.js
|
|
27382
|
+
init_rating_ui();
|
|
27383
|
+
|
|
27384
|
+
// src/browser/transfer.js
|
|
27385
|
+
init_resource();
|
|
27386
|
+
function createTransferCheckout(resource, options = {}) {
|
|
27387
|
+
const normalized = normalizeResource({ ...resource, paymentRail: "transfer" });
|
|
27388
|
+
const sendTransfer = options.sendTransfer || options.transfer;
|
|
27389
|
+
if (typeof sendTransfer !== "function") {
|
|
27390
|
+
throw new Error("createTransferCheckout requires sendTransfer({ resource, recipient, amount, currency, network }) and a server verifyTransfer hook.");
|
|
27391
|
+
}
|
|
27392
|
+
return {
|
|
27393
|
+
resource: normalized,
|
|
27394
|
+
async pay(input = {}) {
|
|
27395
|
+
const recipient = normalized.recipient || normalized.payTo;
|
|
27396
|
+
const amount = String(normalized.price || normalized.amount || "0");
|
|
27397
|
+
const currency = normalized.currency || "USDC";
|
|
27398
|
+
const network = options.network || input.challenge?.accepts?.[0]?.network || "eip155:5042002";
|
|
27399
|
+
const result = await sendTransfer({ resource: normalized, recipient, amount, currency, network, challenge: input.challenge });
|
|
27400
|
+
const txHash = result?.txHash || result?.hash || result?.transactionHash || result?.paymentId || "";
|
|
27401
|
+
if (!txHash) throw new Error("Transfer checkout did not return a txHash.");
|
|
27402
|
+
return {
|
|
27403
|
+
paymentSignature: txHash,
|
|
27404
|
+
signature: txHash,
|
|
27405
|
+
memo: result.memo || "",
|
|
27406
|
+
metadata: {
|
|
27407
|
+
paymentProvider: "direct-transfer",
|
|
27408
|
+
paymentId: txHash,
|
|
27409
|
+
txHash,
|
|
27410
|
+
recipient,
|
|
27411
|
+
amount: Number(amount),
|
|
27412
|
+
currency,
|
|
27413
|
+
network,
|
|
27414
|
+
...result.metadata || result
|
|
27415
|
+
}
|
|
27416
|
+
};
|
|
27417
|
+
}
|
|
27418
|
+
};
|
|
27419
|
+
}
|
|
27420
|
+
async function payWithTransfer(resource, options = {}) {
|
|
27421
|
+
const checkout = options.checkout || createTransferCheckout(resource, options).pay;
|
|
27422
|
+
const result = await checkout({ resource: normalizeResource(resource), challenge: options.challenge || null });
|
|
27423
|
+
const txHash = result?.metadata?.txHash || result?.txHash || result?.paymentSignature || result?.signature || "";
|
|
27424
|
+
if (!txHash) throw new Error("Transfer checkout did not return a txHash.");
|
|
27425
|
+
return checkResourceAccess(resource, {
|
|
27426
|
+
...options,
|
|
27427
|
+
headers: {
|
|
27428
|
+
...options.headers || {},
|
|
27429
|
+
"x-nibgate-transfer-tx": txHash
|
|
27430
|
+
},
|
|
27431
|
+
payment: result.metadata || { paymentProvider: "direct-transfer", txHash, paymentId: txHash }
|
|
27432
|
+
});
|
|
27433
|
+
}
|
|
27434
|
+
|
|
27435
|
+
// src/browser/client.js
|
|
27436
|
+
function createNibgate(defaults = {}) {
|
|
27437
|
+
const defaultResource = defaults.resource ? normalizeResource(defaults.resource) : null;
|
|
27438
|
+
function resourceWithDefaults(resource = {}) {
|
|
27439
|
+
return normalizeResource({
|
|
27440
|
+
...defaultResource || {},
|
|
27441
|
+
...typeof resource === "string" ? { id: resource } : resource
|
|
27442
|
+
});
|
|
27443
|
+
}
|
|
27444
|
+
return {
|
|
27445
|
+
content(resource, extra = {}) {
|
|
27446
|
+
return emit("content_registered", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27447
|
+
},
|
|
27448
|
+
registerContent(resource, extra = {}) {
|
|
27449
|
+
return emit("content_registered", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27450
|
+
},
|
|
27451
|
+
view(resource, extra = {}) {
|
|
27452
|
+
return emit("resource_view", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27453
|
+
},
|
|
27454
|
+
track(eventName, payload = {}) {
|
|
27455
|
+
return emit(eventName || "custom", payload);
|
|
27456
|
+
},
|
|
27457
|
+
unlockStarted(resource, extra = {}) {
|
|
27458
|
+
return emit("unlock_started", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27459
|
+
},
|
|
27460
|
+
unlockCompleted(resource, payment = {}) {
|
|
27461
|
+
return emit("unlock_completed", payloadWithResource(resourceWithDefaults(resource), payment));
|
|
27462
|
+
},
|
|
27463
|
+
paymentCompleted(resource, payment = {}) {
|
|
27464
|
+
return emit("payment_completed", payloadWithResource(resourceWithDefaults(resource), payment));
|
|
27465
|
+
},
|
|
27466
|
+
rateResource(resource, rating = {}, extra = {}) {
|
|
27467
|
+
return rateResource(resourceWithDefaults(resource), rating, extra);
|
|
27468
|
+
},
|
|
27469
|
+
ratingMessage(resource, rating = {}, messageOptions = {}) {
|
|
27470
|
+
return ratingMessage(resourceWithDefaults(resource), rating, messageOptions);
|
|
27471
|
+
},
|
|
27472
|
+
gate(resource, options = {}) {
|
|
27473
|
+
return createGate(resourceWithDefaults(resource), { ...options, client: this });
|
|
27474
|
+
},
|
|
27475
|
+
trackResourcePage(resource, options = {}) {
|
|
27476
|
+
return trackResourcePage(resourceWithDefaults(resource), options);
|
|
27477
|
+
},
|
|
27478
|
+
checkResourceAccess(resource, options = {}) {
|
|
27479
|
+
return checkResourceAccess(resourceWithDefaults(resource), options);
|
|
27480
|
+
},
|
|
27481
|
+
payWithPaymentSignature(resource, options = {}) {
|
|
27482
|
+
return payWithPaymentSignature(resourceWithDefaults(resource), options);
|
|
27483
|
+
},
|
|
27484
|
+
createWalletCheckout(resource, options = {}) {
|
|
27485
|
+
return createWalletCheckout(resourceWithDefaults(resource), options);
|
|
27486
|
+
},
|
|
27487
|
+
createCircleGatewayBrowserAdapter(options = {}) {
|
|
27488
|
+
return createCircleGatewayBrowserAdapter2(options);
|
|
27489
|
+
},
|
|
27490
|
+
createTransferCheckout(resource, options = {}) {
|
|
27491
|
+
return createTransferCheckout(resourceWithDefaults(resource), options);
|
|
27492
|
+
},
|
|
27493
|
+
payWithTransfer(resource, options = {}) {
|
|
27494
|
+
return payWithTransfer(resourceWithDefaults(resource), options);
|
|
27495
|
+
},
|
|
27496
|
+
createEvmGatewayUnlock(resource, options = {}) {
|
|
27497
|
+
return createEvmGatewayUnlock(resourceWithDefaults(resource), options);
|
|
27498
|
+
},
|
|
27499
|
+
createOnchainRating(resource, options = {}) {
|
|
27500
|
+
return createOnchainRating(resourceWithDefaults(resource), options);
|
|
27501
|
+
},
|
|
27502
|
+
mountRatingUI(resource, options = {}) {
|
|
27503
|
+
return mountRatingUI(resourceWithDefaults(resource), options);
|
|
27504
|
+
},
|
|
27505
|
+
payAndUnlockResource(resource, options = {}) {
|
|
27506
|
+
return payAndUnlockResource(resourceWithDefaults(resource), options);
|
|
27507
|
+
},
|
|
27508
|
+
setupResourcePage(resource, options = {}) {
|
|
27509
|
+
return setupResourcePage(resourceWithDefaults(resource), options);
|
|
27510
|
+
},
|
|
27511
|
+
normalizeResource: resourceWithDefaults,
|
|
27512
|
+
normalizeContentType,
|
|
27513
|
+
flush: flushQueue
|
|
27514
|
+
};
|
|
27515
|
+
}
|
|
27516
|
+
var nibgate = createNibgate();
|
|
27517
|
+
setDefaultClient(nibgate);
|
|
27518
|
+
|
|
27519
|
+
// src/browser/index.js
|
|
27520
|
+
init_rating_ui();
|
|
27521
|
+
init_reputation();
|
|
27522
|
+
|
|
27523
|
+
// src/browser/default-ui.js
|
|
27524
|
+
var SID = "nibgate-ui-styles";
|
|
27525
|
+
var theme = {
|
|
27526
|
+
bg: "var(--bg, #f4f4f0)",
|
|
27527
|
+
fg: "var(--fg, #0a0a0a)",
|
|
27528
|
+
muted: "var(--muted, #6b6862)",
|
|
27529
|
+
border: "var(--border, #cecdc3)",
|
|
27530
|
+
accent: "var(--accent, #7c9a6d)",
|
|
27531
|
+
accentSoft: "var(--accent-soft, #d8e8d3)",
|
|
27532
|
+
cardHover: "var(--card-hover, #e0ddd3)"
|
|
27533
|
+
};
|
|
27534
|
+
var css = (s) => Object.entries(s).map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())}:${v}`).join(";");
|
|
27297
27535
|
function h(tag, attrs, children) {
|
|
27298
27536
|
const e = document.createElement(tag);
|
|
27299
27537
|
for (const [k, v] of Object.entries(attrs || {})) {
|
|
@@ -27505,70 +27743,9 @@ ${prettyStateOverride(stateOverride)}`;
|
|
|
27505
27743
|
document.removeEventListener("touchend", cancelHold);
|
|
27506
27744
|
};
|
|
27507
27745
|
card.addEventListener("remove", cleanup);
|
|
27508
|
-
let gwOverlayEl = null;
|
|
27509
|
-
let balTimer = null;
|
|
27510
|
-
let balEl = null;
|
|
27511
|
-
function depositIconHTML() {
|
|
27512
|
-
return '<svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display:inline;vertical-align:baseline"><path d="M12 17V3"/><path d="m6 11 6 6 6-6"/><path d="M19 21H5"/></svg>';
|
|
27513
|
-
}
|
|
27514
|
-
async function showGatewayWallet() {
|
|
27515
|
-
if (gwOverlayEl) return;
|
|
27516
|
-
gwOverlayEl = el("div", { style: "position:fixed;inset:0;z-index:9999;background:rgba(0,0,0,0.5);display:flex;align-items:center;justify-content:center;padding:20px;animation:nfade .15s ease-out" });
|
|
27517
|
-
const modal = el("div", { style: "background:" + theme.bg + ";border-radius:16px;max-width:540px;width:100%;max-height:90vh;overflow:auto;position:relative;box-shadow:0 8px 32px rgba(0,0,0,0.12);animation:nscale .15s ease-out" });
|
|
27518
|
-
const close = el("button", { style: "position:absolute;top:12px;right:16px;z-index:20;background:none;border:none;font-size:28px;cursor:pointer;color:" + theme.muted + ";font-family:inherit;line-height:1" }, "\xD7");
|
|
27519
|
-
close.addEventListener("click", closeGatewayWallet);
|
|
27520
|
-
modal.appendChild(close);
|
|
27521
|
-
gwOverlayEl.appendChild(modal);
|
|
27522
|
-
gwOverlayEl.addEventListener("click", (e) => {
|
|
27523
|
-
if (e.target === gwOverlayEl) closeGatewayWallet();
|
|
27524
|
-
});
|
|
27525
|
-
document.body.appendChild(gwOverlayEl);
|
|
27526
|
-
document.addEventListener("keydown", onGwKey);
|
|
27527
|
-
const gw = await Promise.resolve().then(() => (init_default_ui(), default_ui_exports));
|
|
27528
|
-
gw.renderDefaultGatewayWalletUI(modal, options.gatewayOptions || {});
|
|
27529
|
-
}
|
|
27530
|
-
function closeGatewayWallet() {
|
|
27531
|
-
if (!gwOverlayEl) return;
|
|
27532
|
-
gwOverlayEl.remove();
|
|
27533
|
-
gwOverlayEl = null;
|
|
27534
|
-
document.removeEventListener("keydown", onGwKey);
|
|
27535
|
-
}
|
|
27536
|
-
function onGwKey(e) {
|
|
27537
|
-
if (e.key === "Escape") closeGatewayWallet();
|
|
27538
|
-
}
|
|
27539
|
-
function ensureBalEl() {
|
|
27540
|
-
if (balEl && balEl.isConnected) return balEl;
|
|
27541
|
-
balEl = el("span", { "data-nibgate-bal": "", style: "margin-left:6px;cursor:pointer;white-space:nowrap" }, depositIconHTML() + " <span data-nibgate-bal-text></span>");
|
|
27542
|
-
balEl.addEventListener("click", showGatewayWallet);
|
|
27543
|
-
if (label.parentNode) label.parentNode.insertBefore(balEl, label.nextSibling);
|
|
27544
|
-
return balEl;
|
|
27545
|
-
}
|
|
27546
|
-
async function refreshBalance() {
|
|
27547
|
-
if (!card.isConnected) return;
|
|
27548
|
-
const addr = ctrl.getWalletAddress();
|
|
27549
|
-
if (!addr) return;
|
|
27550
|
-
const txt = ensureBalEl().querySelector("[data-nibgate-bal-text]");
|
|
27551
|
-
if (options.gatewayBalanceUrl) {
|
|
27552
|
-
try {
|
|
27553
|
-
const res = await fetch(options.gatewayBalanceUrl + "?address=" + encodeURIComponent(addr));
|
|
27554
|
-
const data = await res.json();
|
|
27555
|
-
if (txt) txt.textContent = data?.balance || data?.availableBalance || "\u2026";
|
|
27556
|
-
return;
|
|
27557
|
-
} catch {
|
|
27558
|
-
}
|
|
27559
|
-
}
|
|
27560
|
-
if (txt) txt.textContent = "\u2026";
|
|
27561
|
-
}
|
|
27562
|
-
if (window.ethereum) {
|
|
27563
|
-
balTimer = setInterval(refreshBalance, 3e3);
|
|
27564
|
-
setTimeout(refreshBalance, 1e3);
|
|
27565
|
-
window.ethereum.on("accountsChanged", refreshBalance);
|
|
27566
|
-
}
|
|
27567
27746
|
return { ...ctrl, element: card, destroy: () => {
|
|
27568
27747
|
cleanup();
|
|
27569
27748
|
card.remove();
|
|
27570
|
-
if (balTimer) clearInterval(balTimer);
|
|
27571
|
-
closeGatewayWallet();
|
|
27572
27749
|
} };
|
|
27573
27750
|
}
|
|
27574
27751
|
function renderDefaultRatingUI(container, resource, options = {}) {
|
|
@@ -27770,276 +27947,8 @@ ${prettyStateOverride(stateOverride)}`;
|
|
|
27770
27947
|
tabs.forEach((b) => b.addEventListener("click", () => render(b.dataset.tab)));
|
|
27771
27948
|
return { element: wrap3, destroy: () => wrap3.remove(), switchTab: render };
|
|
27772
27949
|
}
|
|
27773
|
-
var SID, theme, css;
|
|
27774
|
-
var init_default_ui = __esm({
|
|
27775
|
-
"src/browser/default-ui.js"() {
|
|
27776
|
-
init_evm_gateway();
|
|
27777
|
-
SID = "nibgate-ui-styles";
|
|
27778
|
-
theme = {
|
|
27779
|
-
bg: "var(--bg, #f4f4f0)",
|
|
27780
|
-
fg: "var(--fg, #0a0a0a)",
|
|
27781
|
-
muted: "var(--muted, #6b6862)",
|
|
27782
|
-
border: "var(--border, #cecdc3)",
|
|
27783
|
-
accent: "var(--accent, #7c9a6d)",
|
|
27784
|
-
accentSoft: "var(--accent-soft, #d8e8d3)",
|
|
27785
|
-
cardHover: "var(--card-hover, #e0ddd3)"
|
|
27786
|
-
};
|
|
27787
|
-
css = (s) => Object.entries(s).map(([k, v]) => `${k.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase())}:${v}`).join(";");
|
|
27788
|
-
}
|
|
27789
|
-
});
|
|
27790
|
-
|
|
27791
|
-
// src/browser/index.js
|
|
27792
|
-
var index_exports = {};
|
|
27793
|
-
__export(index_exports, {
|
|
27794
|
-
ACCESS_MODES: () => ACCESS_MODES,
|
|
27795
|
-
CONTENT_TYPES: () => CONTENT_TYPES,
|
|
27796
|
-
NIBGATE_CONTENT_HASH_NAMESPACE: () => NIBGATE_CONTENT_HASH_NAMESPACE,
|
|
27797
|
-
NIBGATE_CONTENT_SETTING_FIELDS: () => NIBGATE_CONTENT_SETTING_FIELDS,
|
|
27798
|
-
NIBGATE_REPUTATION_ABI: () => NIBGATE_REPUTATION_ABI,
|
|
27799
|
-
NIBGATE_REPUTATION_CHAIN_ID: () => NIBGATE_REPUTATION_CHAIN_ID,
|
|
27800
|
-
NIBGATE_REPUTATION_CHAIN_NAME: () => NIBGATE_REPUTATION_CHAIN_NAME,
|
|
27801
|
-
NIBGATE_REPUTATION_CONTRACT: () => NIBGATE_REPUTATION_CONTRACT,
|
|
27802
|
-
NIBGATE_REPUTATION_RPC_URL: () => NIBGATE_REPUTATION_RPC_URL,
|
|
27803
|
-
PAYMENT_RAILS: () => PAYMENT_RAILS,
|
|
27804
|
-
UNLOCK_MODES: () => UNLOCK_MODES,
|
|
27805
|
-
checkResourceAccess: () => checkResourceAccess,
|
|
27806
|
-
contentRatingHash: () => contentRatingHash,
|
|
27807
|
-
createCircleGatewayBrowserAdapter: () => createCircleGatewayBrowserAdapter2,
|
|
27808
|
-
createEvmGatewayUnlock: () => createEvmGatewayUnlock,
|
|
27809
|
-
createGate: () => createGate,
|
|
27810
|
-
createHostedUnlock: () => createHostedUnlock,
|
|
27811
|
-
createNibgate: () => createNibgate,
|
|
27812
|
-
createNibgateContentSettings: () => createNibgateContentSettings,
|
|
27813
|
-
createOnchainRating: () => createOnchainRating,
|
|
27814
|
-
createTransferCheckout: () => createTransferCheckout,
|
|
27815
|
-
createWalletCheckout: () => createWalletCheckout,
|
|
27816
|
-
mountRatingUI: () => mountRatingUI,
|
|
27817
|
-
nibgate: () => nibgate,
|
|
27818
|
-
normalizeAccessPolicy: () => normalizeAccessPolicy,
|
|
27819
|
-
normalizeContentType: () => normalizeContentType,
|
|
27820
|
-
normalizePaymentRail: () => normalizePaymentRail,
|
|
27821
|
-
normalizeResource: () => normalizeResource,
|
|
27822
|
-
normalizeUnlockPolicy: () => normalizeUnlockPolicy,
|
|
27823
|
-
payAndUnlockResource: () => payAndUnlockResource,
|
|
27824
|
-
payWithPaymentSignature: () => payWithPaymentSignature,
|
|
27825
|
-
payWithTransfer: () => payWithTransfer,
|
|
27826
|
-
rateContentOnchain: () => rateContentOnchain,
|
|
27827
|
-
rateResource: () => rateResource,
|
|
27828
|
-
renderDefaultGatewayWalletUI: () => renderDefaultGatewayWalletUI,
|
|
27829
|
-
renderDefaultRatingUI: () => renderDefaultRatingUI,
|
|
27830
|
-
renderDefaultUnlockUI: () => renderDefaultUnlockUI,
|
|
27831
|
-
reviewTextHash: () => reviewTextHash,
|
|
27832
|
-
settingsToAccessPolicy: () => settingsToAccessPolicy,
|
|
27833
|
-
settingsToUnlockPolicy: () => settingsToUnlockPolicy,
|
|
27834
|
-
setupResourcePage: () => setupResourcePage,
|
|
27835
|
-
trackResourcePage: () => trackResourcePage,
|
|
27836
|
-
validateResourceMetadata: () => validateResourceMetadata
|
|
27837
|
-
});
|
|
27838
|
-
init_gate();
|
|
27839
|
-
init_access();
|
|
27840
|
-
|
|
27841
|
-
// src/browser/checkout.js
|
|
27842
|
-
init_resource();
|
|
27843
|
-
init_env();
|
|
27844
|
-
init_access();
|
|
27845
|
-
function setElementText(target, message) {
|
|
27846
|
-
const win = browserWindow();
|
|
27847
|
-
if (!target || !win) return;
|
|
27848
|
-
const element = typeof target === "string" ? win.document.querySelector(target) : target;
|
|
27849
|
-
if (element) element.textContent = message || "";
|
|
27850
|
-
}
|
|
27851
|
-
function setElementDisabled(target, disabled) {
|
|
27852
|
-
const win = browserWindow();
|
|
27853
|
-
if (!target || !win) return;
|
|
27854
|
-
const element = typeof target === "string" ? win.document.querySelector(target) : target;
|
|
27855
|
-
if (element && "disabled" in element) element.disabled = Boolean(disabled);
|
|
27856
|
-
}
|
|
27857
|
-
function createWalletCheckout(resource, options = {}) {
|
|
27858
|
-
const normalized = normalizeResource(resource);
|
|
27859
|
-
const accessPath = options.accessPath || normalized.accessPath || "/api/nibgate/access";
|
|
27860
|
-
const button = options.button || null;
|
|
27861
|
-
const statusTarget = options.status || null;
|
|
27862
|
-
const status2 = typeof options.onStatus === "function" ? options.onStatus : (message) => setElementText(statusTarget, message);
|
|
27863
|
-
const checkout = options.checkout || options.createPaymentSignature || options.pay;
|
|
27864
|
-
if (typeof checkout !== "function") {
|
|
27865
|
-
throw new Error("createWalletCheckout requires checkout/createPaymentSignature/pay callback for the active wallet or Gateway adapter.");
|
|
27866
|
-
}
|
|
27867
|
-
async function unlock(extra = {}) {
|
|
27868
|
-
setElementDisabled(button, true);
|
|
27869
|
-
try {
|
|
27870
|
-
return await checkResourceAccess(normalized, {
|
|
27871
|
-
...options,
|
|
27872
|
-
...extra,
|
|
27873
|
-
accessPath,
|
|
27874
|
-
createPaymentSignature: checkout,
|
|
27875
|
-
onStatus: status2
|
|
27876
|
-
});
|
|
27877
|
-
} finally {
|
|
27878
|
-
setElementDisabled(button, false);
|
|
27879
|
-
}
|
|
27880
|
-
}
|
|
27881
|
-
function mount() {
|
|
27882
|
-
const win = browserWindow();
|
|
27883
|
-
if (!win || !button) return { unlock };
|
|
27884
|
-
const element = typeof button === "string" ? win.document.querySelector(button) : button;
|
|
27885
|
-
if (element) element.addEventListener("click", () => unlock().catch((error) => status2(error.message || "Checkout failed.")));
|
|
27886
|
-
return { unlock };
|
|
27887
|
-
}
|
|
27888
|
-
return { resource: normalized, unlock, mount };
|
|
27889
|
-
}
|
|
27890
|
-
|
|
27891
|
-
// src/browser/client.js
|
|
27892
|
-
init_resource();
|
|
27893
|
-
init_rating();
|
|
27894
|
-
init_events();
|
|
27895
|
-
init_gate();
|
|
27896
|
-
init_gate();
|
|
27897
|
-
init_access();
|
|
27898
|
-
init_evm_gateway();
|
|
27899
|
-
init_rating_ui();
|
|
27900
|
-
init_track();
|
|
27901
|
-
|
|
27902
|
-
// src/browser/transfer.js
|
|
27903
|
-
init_resource();
|
|
27904
|
-
function createTransferCheckout(resource, options = {}) {
|
|
27905
|
-
const normalized = normalizeResource({ ...resource, paymentRail: "transfer" });
|
|
27906
|
-
const sendTransfer = options.sendTransfer || options.transfer;
|
|
27907
|
-
if (typeof sendTransfer !== "function") {
|
|
27908
|
-
throw new Error("createTransferCheckout requires sendTransfer({ resource, recipient, amount, currency, network }) and a server verifyTransfer hook.");
|
|
27909
|
-
}
|
|
27910
|
-
return {
|
|
27911
|
-
resource: normalized,
|
|
27912
|
-
async pay(input = {}) {
|
|
27913
|
-
const recipient = normalized.recipient || normalized.payTo;
|
|
27914
|
-
const amount = String(normalized.price || normalized.amount || "0");
|
|
27915
|
-
const currency = normalized.currency || "USDC";
|
|
27916
|
-
const network = options.network || input.challenge?.accepts?.[0]?.network || "eip155:5042002";
|
|
27917
|
-
const result = await sendTransfer({ resource: normalized, recipient, amount, currency, network, challenge: input.challenge });
|
|
27918
|
-
const txHash = result?.txHash || result?.hash || result?.transactionHash || result?.paymentId || "";
|
|
27919
|
-
if (!txHash) throw new Error("Transfer checkout did not return a txHash.");
|
|
27920
|
-
return {
|
|
27921
|
-
paymentSignature: txHash,
|
|
27922
|
-
signature: txHash,
|
|
27923
|
-
memo: result.memo || "",
|
|
27924
|
-
metadata: {
|
|
27925
|
-
paymentProvider: "direct-transfer",
|
|
27926
|
-
paymentId: txHash,
|
|
27927
|
-
txHash,
|
|
27928
|
-
recipient,
|
|
27929
|
-
amount: Number(amount),
|
|
27930
|
-
currency,
|
|
27931
|
-
network,
|
|
27932
|
-
...result.metadata || result
|
|
27933
|
-
}
|
|
27934
|
-
};
|
|
27935
|
-
}
|
|
27936
|
-
};
|
|
27937
|
-
}
|
|
27938
|
-
async function payWithTransfer(resource, options = {}) {
|
|
27939
|
-
const checkout = options.checkout || createTransferCheckout(resource, options).pay;
|
|
27940
|
-
const result = await checkout({ resource: normalizeResource(resource), challenge: options.challenge || null });
|
|
27941
|
-
const txHash = result?.metadata?.txHash || result?.txHash || result?.paymentSignature || result?.signature || "";
|
|
27942
|
-
if (!txHash) throw new Error("Transfer checkout did not return a txHash.");
|
|
27943
|
-
return checkResourceAccess(resource, {
|
|
27944
|
-
...options,
|
|
27945
|
-
headers: {
|
|
27946
|
-
...options.headers || {},
|
|
27947
|
-
"x-nibgate-transfer-tx": txHash
|
|
27948
|
-
},
|
|
27949
|
-
payment: result.metadata || { paymentProvider: "direct-transfer", txHash, paymentId: txHash }
|
|
27950
|
-
});
|
|
27951
|
-
}
|
|
27952
|
-
|
|
27953
|
-
// src/browser/client.js
|
|
27954
|
-
function createNibgate(defaults = {}) {
|
|
27955
|
-
const defaultResource = defaults.resource ? normalizeResource(defaults.resource) : null;
|
|
27956
|
-
function resourceWithDefaults(resource = {}) {
|
|
27957
|
-
return normalizeResource({
|
|
27958
|
-
...defaultResource || {},
|
|
27959
|
-
...typeof resource === "string" ? { id: resource } : resource
|
|
27960
|
-
});
|
|
27961
|
-
}
|
|
27962
|
-
return {
|
|
27963
|
-
content(resource, extra = {}) {
|
|
27964
|
-
return emit("content_registered", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27965
|
-
},
|
|
27966
|
-
registerContent(resource, extra = {}) {
|
|
27967
|
-
return emit("content_registered", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27968
|
-
},
|
|
27969
|
-
view(resource, extra = {}) {
|
|
27970
|
-
return emit("resource_view", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27971
|
-
},
|
|
27972
|
-
track(eventName, payload = {}) {
|
|
27973
|
-
return emit(eventName || "custom", payload);
|
|
27974
|
-
},
|
|
27975
|
-
unlockStarted(resource, extra = {}) {
|
|
27976
|
-
return emit("unlock_started", payloadWithResource(resourceWithDefaults(resource), extra));
|
|
27977
|
-
},
|
|
27978
|
-
unlockCompleted(resource, payment = {}) {
|
|
27979
|
-
return emit("unlock_completed", payloadWithResource(resourceWithDefaults(resource), payment));
|
|
27980
|
-
},
|
|
27981
|
-
paymentCompleted(resource, payment = {}) {
|
|
27982
|
-
return emit("payment_completed", payloadWithResource(resourceWithDefaults(resource), payment));
|
|
27983
|
-
},
|
|
27984
|
-
rateResource(resource, rating = {}, extra = {}) {
|
|
27985
|
-
return rateResource(resourceWithDefaults(resource), rating, extra);
|
|
27986
|
-
},
|
|
27987
|
-
ratingMessage(resource, rating = {}, messageOptions = {}) {
|
|
27988
|
-
return ratingMessage(resourceWithDefaults(resource), rating, messageOptions);
|
|
27989
|
-
},
|
|
27990
|
-
gate(resource, options = {}) {
|
|
27991
|
-
return createGate(resourceWithDefaults(resource), { ...options, client: this });
|
|
27992
|
-
},
|
|
27993
|
-
trackResourcePage(resource, options = {}) {
|
|
27994
|
-
return trackResourcePage(resourceWithDefaults(resource), options);
|
|
27995
|
-
},
|
|
27996
|
-
checkResourceAccess(resource, options = {}) {
|
|
27997
|
-
return checkResourceAccess(resourceWithDefaults(resource), options);
|
|
27998
|
-
},
|
|
27999
|
-
payWithPaymentSignature(resource, options = {}) {
|
|
28000
|
-
return payWithPaymentSignature(resourceWithDefaults(resource), options);
|
|
28001
|
-
},
|
|
28002
|
-
createWalletCheckout(resource, options = {}) {
|
|
28003
|
-
return createWalletCheckout(resourceWithDefaults(resource), options);
|
|
28004
|
-
},
|
|
28005
|
-
createCircleGatewayBrowserAdapter(options = {}) {
|
|
28006
|
-
return createCircleGatewayBrowserAdapter2(options);
|
|
28007
|
-
},
|
|
28008
|
-
createTransferCheckout(resource, options = {}) {
|
|
28009
|
-
return createTransferCheckout(resourceWithDefaults(resource), options);
|
|
28010
|
-
},
|
|
28011
|
-
payWithTransfer(resource, options = {}) {
|
|
28012
|
-
return payWithTransfer(resourceWithDefaults(resource), options);
|
|
28013
|
-
},
|
|
28014
|
-
createEvmGatewayUnlock(resource, options = {}) {
|
|
28015
|
-
return createEvmGatewayUnlock(resourceWithDefaults(resource), options);
|
|
28016
|
-
},
|
|
28017
|
-
createOnchainRating(resource, options = {}) {
|
|
28018
|
-
return createOnchainRating(resourceWithDefaults(resource), options);
|
|
28019
|
-
},
|
|
28020
|
-
mountRatingUI(resource, options = {}) {
|
|
28021
|
-
return mountRatingUI(resourceWithDefaults(resource), options);
|
|
28022
|
-
},
|
|
28023
|
-
payAndUnlockResource(resource, options = {}) {
|
|
28024
|
-
return payAndUnlockResource(resourceWithDefaults(resource), options);
|
|
28025
|
-
},
|
|
28026
|
-
setupResourcePage(resource, options = {}) {
|
|
28027
|
-
return setupResourcePage(resourceWithDefaults(resource), options);
|
|
28028
|
-
},
|
|
28029
|
-
normalizeResource: resourceWithDefaults,
|
|
28030
|
-
normalizeContentType,
|
|
28031
|
-
flush: flushQueue
|
|
28032
|
-
};
|
|
28033
|
-
}
|
|
28034
|
-
var nibgate = createNibgate();
|
|
28035
|
-
setDefaultClient(nibgate);
|
|
28036
27950
|
|
|
28037
27951
|
// src/browser/index.js
|
|
28038
|
-
init_evm_gateway();
|
|
28039
|
-
init_rating_ui();
|
|
28040
|
-
init_track();
|
|
28041
|
-
init_reputation();
|
|
28042
|
-
init_default_ui();
|
|
28043
27952
|
init_resource();
|
|
28044
27953
|
|
|
28045
27954
|
// src/core/settings.js
|