@nibgate/sdk 0.2.14 → 0.2.15

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 CHANGED
@@ -1,9 +1,7 @@
1
1
  var Nibgate = (() => {
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
9
7
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
@@ -26,14 +24,6 @@ var Nibgate = (() => {
26
24
  }
27
25
  return to;
28
26
  };
29
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
30
- // If the importer is in node compatibility mode or this is not an ESM
31
- // file that has been converted to a CommonJS file using a Babel-
32
- // compatible transform (i.e. "__esModule" has not been set), then set
33
- // "default" to the CommonJS "module.exports" for node compatibility.
34
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
35
- mod
36
- ));
37
27
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
28
 
39
29
  // src/core/payment.js
@@ -463,159 +453,6 @@ var Nibgate = (() => {
463
453
  }
464
454
  });
465
455
 
466
- // src/browser/schemes/batch-scheme.js
467
- var batch_scheme_exports = {};
468
- __export(batch_scheme_exports, {
469
- BatchEvmScheme: () => BatchEvmScheme,
470
- CIRCLE_BATCHING_NAME: () => CIRCLE_BATCHING_NAME,
471
- CIRCLE_BATCHING_VERSION: () => CIRCLE_BATCHING_VERSION,
472
- GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS: () => GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS,
473
- GATEWAY_MIN_AUTH_VALIDITY_SECONDS: () => GATEWAY_MIN_AUTH_VALIDITY_SECONDS
474
- });
475
- function supportsBatching(requirements) {
476
- const extra = requirements.extra;
477
- if (!extra) return false;
478
- return extra.name === CIRCLE_BATCHING_NAME && extra.version === CIRCLE_BATCHING_VERSION;
479
- }
480
- function getVerifyingContract(requirements) {
481
- if (!supportsBatching(requirements)) return void 0;
482
- return requirements.extra?.verifyingContract;
483
- }
484
- function createNonce() {
485
- const bytes = new Uint8Array(32);
486
- crypto.getRandomValues(bytes);
487
- return "0x" + Array.from(bytes).map((b) => b.toString(16).padStart(2, "0")).join("");
488
- }
489
- function getAddress(value) {
490
- return value && typeof value === "string" && value.startsWith("0x") ? value.toLowerCase() : value;
491
- }
492
- var CIRCLE_BATCHING_NAME, CIRCLE_BATCHING_VERSION, GATEWAY_MIN_AUTH_VALIDITY_SECONDS, GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS, authorizationTypes, BatchEvmScheme;
493
- var init_batch_scheme = __esm({
494
- "src/browser/schemes/batch-scheme.js"() {
495
- CIRCLE_BATCHING_NAME = "GatewayWalletBatched";
496
- CIRCLE_BATCHING_VERSION = "1";
497
- GATEWAY_MIN_AUTH_VALIDITY_SECONDS = 7 * 24 * 60 * 60;
498
- GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS = GATEWAY_MIN_AUTH_VALIDITY_SECONDS + 100;
499
- authorizationTypes = {
500
- TransferWithAuthorization: [
501
- { name: "from", type: "address" },
502
- { name: "to", type: "address" },
503
- { name: "value", type: "uint256" },
504
- { name: "validAfter", type: "uint256" },
505
- { name: "validBefore", type: "uint256" },
506
- { name: "nonce", type: "bytes32" }
507
- ]
508
- };
509
- BatchEvmScheme = class {
510
- constructor(signer) {
511
- this.signer = signer;
512
- this.scheme = CIRCLE_BATCHING_NAME;
513
- this._beforeHooks = [];
514
- this._afterHooks = [];
515
- this._failureHooks = [];
516
- }
517
- onBeforePaymentCreation(hook) {
518
- this._beforeHooks.push(hook);
519
- return this;
520
- }
521
- onAfterPaymentCreation(hook) {
522
- this._afterHooks.push(hook);
523
- return this;
524
- }
525
- onPaymentCreationFailure(hook) {
526
- this._failureHooks.push(hook);
527
- return this;
528
- }
529
- async createPaymentPayload(x402Version, paymentRequirements) {
530
- const context = {
531
- paymentRequired: { x402Version, accepts: [paymentRequirements] },
532
- selectedRequirements: paymentRequirements
533
- };
534
- for (const hook of this._beforeHooks) {
535
- const result = await hook(context);
536
- if (result && result.abort) {
537
- throw new Error("Payment creation aborted: " + result.reason);
538
- }
539
- }
540
- try {
541
- if (!supportsBatching(paymentRequirements)) {
542
- throw new Error(
543
- 'BatchEvmScheme can only handle Circle batching options. Expected extra.name="' + CIRCLE_BATCHING_NAME + '" and extra.version="' + CIRCLE_BATCHING_VERSION + '"'
544
- );
545
- }
546
- const verifyingContract = getVerifyingContract(paymentRequirements);
547
- if (!verifyingContract) {
548
- throw new Error(
549
- "Circle batching option missing extra.verifyingContract (GatewayWallet address)"
550
- );
551
- }
552
- const nonce = createNonce();
553
- const now = Math.floor(Date.now() / 1e3);
554
- const validityWindowSeconds = Math.max(
555
- paymentRequirements.maxTimeoutSeconds || 0,
556
- GATEWAY_AUTH_VALIDITY_WINDOW_SECONDS
557
- );
558
- const authorization = {
559
- from: getAddress(this.signer.address),
560
- to: getAddress(paymentRequirements.payTo),
561
- value: paymentRequirements.amount,
562
- validAfter: String(now - 600),
563
- validBefore: String(now + validityWindowSeconds),
564
- nonce
565
- };
566
- const signature = await this.signAuthorization(authorization, paymentRequirements, verifyingContract);
567
- const payload = { authorization, signature };
568
- const result = { x402Version, payload };
569
- const createdContext = { ...context, paymentPayload: result };
570
- for (const hook of this._afterHooks) {
571
- try {
572
- await hook(createdContext);
573
- } catch {
574
- }
575
- }
576
- return result;
577
- } catch (error) {
578
- const failureContext = { ...context, error };
579
- for (const hook of this._failureHooks) {
580
- const result = await hook(failureContext);
581
- if (result && result.recovered) {
582
- return { x402Version: result.payload.x402Version, payload: result.payload.payload };
583
- }
584
- }
585
- throw error;
586
- }
587
- }
588
- async signAuthorization(authorization, requirements, verifyingContract) {
589
- if (!requirements.network.startsWith("eip155:")) {
590
- throw new Error('BatchEvmScheme: unsupported network format "' + requirements.network + '". Expected "eip155:<chainId>"');
591
- }
592
- const chainId = parseInt(requirements.network.split(":")[1], 10);
593
- const domain = {
594
- name: CIRCLE_BATCHING_NAME,
595
- version: CIRCLE_BATCHING_VERSION,
596
- chainId,
597
- verifyingContract: getAddress(verifyingContract)
598
- };
599
- const message = {
600
- from: getAddress(authorization.from),
601
- to: getAddress(authorization.to),
602
- value: BigInt(authorization.value),
603
- validAfter: BigInt(authorization.validAfter),
604
- validBefore: BigInt(authorization.validBefore),
605
- nonce: authorization.nonce
606
- };
607
- const typedData = {
608
- domain,
609
- types: authorizationTypes,
610
- primaryType: "TransferWithAuthorization",
611
- message
612
- };
613
- return this.signer.signTypedData(typedData);
614
- }
615
- };
616
- }
617
- });
618
-
619
456
  // src/browser/gateway.js
620
457
  var gateway_exports = {};
621
458
  __export(gateway_exports, {
@@ -635,17 +472,7 @@ var Nibgate = (() => {
635
472
  if (!signer?.address || typeof signer.signTypedData !== "function") {
636
473
  throw new Error("Circle Gateway browser adapter requires an EVM signer with address and signTypedData.");
637
474
  }
638
- let BatchEvmScheme2;
639
- try {
640
- const circle = await import("@circle-fin/x402-batching/client");
641
- BatchEvmScheme2 = circle.BatchEvmScheme;
642
- } catch (err) {
643
- console.warn("[nibgate] Failed to import @circle-fin/x402-batching/client:", err.message);
644
- console.warn("[nibgate] Falling back to custom BatchEvmScheme");
645
- const local = await Promise.resolve().then(() => (init_batch_scheme(), batch_scheme_exports));
646
- BatchEvmScheme2 = local.BatchEvmScheme;
647
- }
648
- const scheme = options.clientModule?.BatchEvmScheme ? new options.clientModule.BatchEvmScheme(signer) : new BatchEvmScheme2(signer);
475
+ const scheme = new import_client.BatchEvmScheme(signer);
649
476
  const network = options.network || options.chainId && `eip155:${options.chainId}` || "eip155:5042002";
650
477
  function parsePaymentRequired(input) {
651
478
  if (input && typeof input === "object") return input;
@@ -701,8 +528,10 @@ var Nibgate = (() => {
701
528
  }
702
529
  };
703
530
  }
531
+ var import_client;
704
532
  var init_gateway = __esm({
705
533
  "src/browser/gateway.js"() {
534
+ import_client = __require("@circle-fin/x402-batching/client");
706
535
  init_json();
707
536
  }
708
537
  });