@witnium/witniumchain 0.28.2 → 0.30.0

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/index.mjs CHANGED
@@ -1,3 +1,19 @@
1
+ // src/api-key.ts
2
+ var PREFIXED_FORMAT = /^wcak_(live|sandbox)_[0-9a-f]{64}$/;
3
+ var LEGACY_FORMAT = /^wcak_[0-9a-f]{64}$/;
4
+ function parseApiKey(apiKey) {
5
+ const prefixed = PREFIXED_FORMAT.exec(apiKey);
6
+ if (prefixed) {
7
+ return { environment: prefixed[1], legacyFormat: false };
8
+ }
9
+ if (LEGACY_FORMAT.test(apiKey)) {
10
+ return { environment: "live", legacyFormat: true };
11
+ }
12
+ throw new Error(
13
+ "apiKey must be `wcak_live_` or `wcak_sandbox_` followed by 64 lowercase hex (or a pre-sandbox `wcak_` key)"
14
+ );
15
+ }
16
+
1
17
  // src/errors.ts
2
18
  var WitniumchainApiError = class extends Error {
3
19
  status;
@@ -245,6 +261,13 @@ var WitniumchainClient = class {
245
261
  if (!config.baseUrl) {
246
262
  throw new Error("WitniumchainClient: baseUrl is required");
247
263
  }
264
+ if (config.apiKey !== void 0) {
265
+ try {
266
+ parseApiKey(config.apiKey);
267
+ } catch (err) {
268
+ throw new Error(`WitniumchainClient: ${err.message}`);
269
+ }
270
+ }
248
271
  this.cfg = config;
249
272
  this.baseUrl = config.baseUrl.replace(/\/$/, "");
250
273
  this.chainBaseUrl = config.chainBaseUrl?.replace(/\/$/, "");
@@ -490,19 +513,6 @@ var WitniumchainClient = class {
490
513
  return this.req("POST", "/v1/auth/reset-password", { auth: "Public", body });
491
514
  }
492
515
  // ────────────────────────────────────────────────────────────────────────
493
- // Billing (/v1/billing/*)
494
- // ────────────────────────────────────────────────────────────────────────
495
- createCheckoutSession(body) {
496
- return this.req("POST", "/v1/billing/checkout", {
497
- auth: "SessionOrBearer",
498
- body
499
- });
500
- }
501
- createPortalSession() {
502
- return this.req("GET", "/v1/billing/portal", { auth: "SessionOrBearer" });
503
- }
504
- // Webhook endpoint is intentionally NOT exposed: only Stripe should call it.
505
- // ────────────────────────────────────────────────────────────────────────
506
516
  // Orgs (/v1/orgs/me/*)
507
517
  // ────────────────────────────────────────────────────────────────────────
508
518
  /** The calling API key's own description: its contract and signing key (API key only). */
@@ -757,11 +767,12 @@ var WitniumchainClient = class {
757
767
  // Routing: every method here passes `service: 'chain'` to `req()`. Calls
758
768
  // throw at call time if `chainBaseUrl` wasn't configured.
759
769
  //
760
- // Auth: the contract, witness, transaction and wallet reads are public on
761
- // chain-api (anyone can check a witness), so they send no credential. The
762
- // dashboard reads are BearerJWT: the accounts-issued token already carries
763
- // `aud=https://api.witniumchain.com`, so the same `accessToken` works
764
- // unchanged against both services.
770
+ // Auth: a single witness, its transactions and the contract existence
771
+ // check are public on chain-api (anyone can check a witness), so they send
772
+ // no credential. An org's witness listing and contract info are the
773
+ // registry owner's (BearerJWT): the accounts-issued token already carries
774
+ // the chain-api audience, so the same `accessToken` works unchanged
775
+ // against both services. So do the dashboard reads.
765
776
  //
766
777
  // What's NOT here: chain-api v5 WRITES (propose/sign/finalize/revoke). Those
767
778
  // are proxied by accounts (proposeWitnessV5, etc.) so credits get reserved
@@ -769,11 +780,12 @@ var WitniumchainClient = class {
769
780
  // routing rules; calling chain-api writes directly would burn credits
770
781
  // without billing them.
771
782
  // ════════════════════════════════════════════════════════════════════════
783
+ /** The registry owner's: the token's org must own `contractAddress`. */
772
784
  getContractInfo(contractAddress) {
773
785
  return this.req(
774
786
  "GET",
775
787
  `/v5/contracts/${encodeURIComponent(contractAddress)}/info`,
776
- { auth: "Public", service: "chain" }
788
+ { auth: "BearerJWT", service: "chain" }
777
789
  );
778
790
  }
779
791
  getContractVerification(contractAddress) {
@@ -787,7 +799,7 @@ var WitniumchainClient = class {
787
799
  return this.req(
788
800
  "GET",
789
801
  `/v5/contracts/${encodeURIComponent(contractAddress)}/witnesses`,
790
- { auth: "Public", service: "chain", query: params }
802
+ { auth: "BearerJWT", service: "chain", query: params }
791
803
  );
792
804
  }
793
805
  getWitnessV5(contractAddress, witnessId) {
@@ -811,13 +823,6 @@ var WitniumchainClient = class {
811
823
  { auth: "Public", service: "chain" }
812
824
  );
813
825
  }
814
- getWalletBalance(address) {
815
- return this.req(
816
- "GET",
817
- `/v5/wallets/${encodeURIComponent(address)}/balance`,
818
- { auth: "Public", service: "chain" }
819
- );
820
- }
821
826
  getDashboardContract() {
822
827
  return this.req("GET", "/v5/dashboard/contract", {
823
828
  auth: "BearerJWT",
@@ -1554,22 +1559,6 @@ var Subscriptions = class {
1554
1559
  this.client = client;
1555
1560
  }
1556
1561
  client;
1557
- /**
1558
- * Start a Stripe Checkout session for the supplied price. Returns the
1559
- * hosted Checkout URL; redirect the user to it. Stripe's
1560
- * `checkout.session.completed` webhook grants credits on success.
1561
- */
1562
- subscribe(body) {
1563
- return this.client.createCheckoutSession(body);
1564
- }
1565
- /**
1566
- * Open the Stripe Billing Portal for the calling user's org. Returns the
1567
- * hosted portal URL — redirect the user there for subscription /
1568
- * payment-method management.
1569
- */
1570
- manage() {
1571
- return this.client.createPortalSession();
1572
- }
1573
1562
  /** Recent credit-ledger entries (most recent 200). */
1574
1563
  getLedger() {
1575
1564
  return this.client.getLedger();
@@ -2051,13 +2040,25 @@ function safeParse(text) {
2051
2040
  }
2052
2041
 
2053
2042
  // src/api-key-client.ts
2054
- var API_KEY_FORMAT = /^wcak_[0-9a-f]{64}$/;
2055
2043
  var WitniumchainApiKeyClient = class {
2056
2044
  inner;
2045
+ /**
2046
+ * `live` or `sandbox`, from the key's prefix. Accounts
2047
+ * decides from its own record of the key; this is for the caller's checks
2048
+ * and logs.
2049
+ */
2050
+ environment;
2051
+ /** True for a pre-sandbox `wcak_` + 64 hex key. Rotate it to a `wcak_live_` key before accounts' cutoff. */
2052
+ legacyKeyFormat;
2057
2053
  constructor(config) {
2058
- if (!API_KEY_FORMAT.test(config.apiKey)) {
2059
- throw new Error("WitniumchainApiKeyClient: apiKey must be `wcak_` and 64 lowercase hex");
2054
+ let parsed;
2055
+ try {
2056
+ parsed = parseApiKey(config.apiKey);
2057
+ } catch (err) {
2058
+ throw new Error(`WitniumchainApiKeyClient: ${err.message}`);
2060
2059
  }
2060
+ this.environment = parsed.environment;
2061
+ this.legacyKeyFormat = parsed.legacyFormat;
2061
2062
  this.inner = new WitniumchainClient({
2062
2063
  baseUrl: config.baseUrl,
2063
2064
  apiKey: config.apiKey,
@@ -2220,6 +2221,6 @@ var ownerKeyFile = {
2220
2221
  sign: signWithOwnerKeyFile
2221
2222
  };
2222
2223
 
2223
- export { AccountSecurity, DashboardKey, DelegatedKeys, Enrollment, OWNER_KEY_FILE_FORMAT, OWNER_OP, OauthNamespace, OauthSessions, OrgApiKeys, OrgContract, OrgMembers, Organization, Recovery, SigningKeys, Subscriptions, WitnessProposeError, WitnessScopeConflictError, WitniumchainApiError, WitniumchainApiKeyClient, WitniumchainChainAdminClient, WitniumchainClient, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage, generateOwnerKeyFile, ownerKeyFile, ownerKeyFileName, parseOwnerKeyFile, randomWitnessScope, serializeOwnerKeyFile, signWithOwnerKeyFile, witnessScopeFor };
2224
+ export { AccountSecurity, DashboardKey, DelegatedKeys, Enrollment, OWNER_KEY_FILE_FORMAT, OWNER_OP, OauthNamespace, OauthSessions, OrgApiKeys, OrgContract, OrgMembers, Organization, Recovery, SigningKeys, Subscriptions, WitnessProposeError, WitnessScopeConflictError, WitniumchainApiError, WitniumchainApiKeyClient, WitniumchainChainAdminClient, WitniumchainClient, buildAddSigningKeyPayload, buildPausePayload, buildRevokeSigningKeyPayload, buildUnpausePayload, defaultVerifierStorage, generateOwnerKeyFile, ownerKeyFile, ownerKeyFileName, parseApiKey, parseOwnerKeyFile, randomWitnessScope, serializeOwnerKeyFile, signWithOwnerKeyFile, witnessScopeFor };
2224
2225
  //# sourceMappingURL=index.mjs.map
2225
2226
  //# sourceMappingURL=index.mjs.map