@bounded-sh/server 0.0.18 → 0.0.20

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,21 +1,56 @@
1
- import { convertRemainingAccounts, buildSetDocumentsTransaction, getConfig, init as init$1, getIdToken as getIdToken$1, live, set, setMany, setFile, get, getMany, getFiles, search, runQuery, runQueryMany, runExpression, runExpressionMany, count, aggregate, queryAggregate, subscribe, functions, ServerSessionManager, getWebhookKeysUrl } from '@bounded-sh/core';
2
- export * from '@bounded-sh/core';
3
- export { FunctionInvokeError, InsufficientBalanceError, LiveIntentError, aggregate, count, functions, get, getConfig, getFiles, getMany, invokeFunction, live, liveIntent, liveStatus, queryAggregate, runExpression, runExpressionMany, runQuery, runQueryMany, search, set, setFile, setMany, signAndSubmitTransaction, signMessage, signTransaction, subscribe } from '@bounded-sh/core';
1
+ import { init as init$1, convertRemainingAccounts, buildSetDocumentsTransaction, live as live$1, set as set$1, setMany as setMany$1, setFile as setFile$1, get as get$1, getMany as getMany$1, getFiles as getFiles$1, search as search$1, runQuery as runQuery$1, runQueryMany as runQueryMany$1, runExpression as runExpression$1, runExpressionMany as runExpressionMany$1, count as count$1, aggregate as aggregate$1, queryAggregate as queryAggregate$1, subscribe as subscribe$1, functions as functions$1, getConfig, ServerSessionManager, getWebhookKeysUrl } from '@bounded-sh/core';
2
+ export { FunctionInvokeError, InsufficientBalanceError, LiveIntentError, getConfig, getWebhookKeysUrl } from '@bounded-sh/core';
3
+ import { Connection, VersionedTransaction, ComputeBudgetProgram, SystemProgram, Keypair } from '@solana/web3.js';
4
+ import bs58 from 'bs58';
4
5
  import { Buffer as Buffer$1 } from 'buffer';
5
- import { Connection, VersionedTransaction, ComputeBudgetProgram, Keypair, SystemProgram } from '@solana/web3.js';
6
6
  import * as anchor from '@coral-xyz/anchor';
7
7
  import nacl from 'tweetnacl';
8
- import bs58 from 'bs58';
9
- import * as crypto from 'crypto';
10
8
 
11
- /* ------------------------------------------------------------- *
12
- * KEYPAIR ENV-VAR (only consulted when no explicit keypair is given)
13
- *
14
- * Most code should pass a keypair explicitly — `createWalletClient({ keypair })`
15
- * does. The env var is the fallback for the global `set/get` path. `BOUNDED_*`
16
- * is the canonical name (it matches the CLI's `BOUNDED_PRIVATE_KEY`).
17
- * ------------------------------------------------------------- */
18
- const ENV_VARS = ['BOUNDED_PRIVATE_KEY']; // base-58 or JSON array
9
+ async function init(newConfig) {
10
+ await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: null, isServer: true, skipBackendInit: true }));
11
+ }
12
+
13
+ async function getAuthProvider() {
14
+ throw new Error('Server auth providers are not process-global. Use createWalletClient({ keypair }) and call that client\'s methods.');
15
+ }
16
+
17
+ function explicitClientOnly(name) {
18
+ throw new Error(`${name} is not available as a tarobase-server top-level auth operation. ` +
19
+ 'Use createWalletClient({ keypair }) and call the returned client method.');
20
+ }
21
+ async function get(..._args) { explicitClientOnly('get'); }
22
+ async function getMany(..._args) { explicitClientOnly('getMany'); }
23
+ async function set(..._args) { explicitClientOnly('set'); }
24
+ async function setMany(..._args) { explicitClientOnly('setMany'); }
25
+ async function setFile(..._args) { explicitClientOnly('setFile'); }
26
+ async function getFiles(..._args) { explicitClientOnly('getFiles'); }
27
+ async function search(..._args) { explicitClientOnly('search'); }
28
+ async function queryAggregate(..._args) { explicitClientOnly('queryAggregate'); }
29
+ async function runQuery(..._args) { explicitClientOnly('runQuery'); }
30
+ async function runQueryMany(..._args) { explicitClientOnly('runQueryMany'); }
31
+ async function runExpression(..._args) { explicitClientOnly('runExpression'); }
32
+ async function runExpressionMany(..._args) { explicitClientOnly('runExpressionMany'); }
33
+ async function signMessage(..._args) { explicitClientOnly('signMessage'); }
34
+ async function signTransaction(..._args) { explicitClientOnly('signTransaction'); }
35
+ async function signAndSubmitTransaction(..._args) { explicitClientOnly('signAndSubmitTransaction'); }
36
+ async function count(..._args) { explicitClientOnly('count'); }
37
+ async function aggregate(..._args) { explicitClientOnly('aggregate'); }
38
+ async function subscribe(..._args) { explicitClientOnly('subscribe'); }
39
+ async function invokeFunction(..._args) { explicitClientOnly('invokeFunction'); }
40
+ async function liveIntent(..._args) { explicitClientOnly('liveIntent'); }
41
+ async function liveStatus(..._args) { explicitClientOnly('liveStatus'); }
42
+ const functions = {
43
+ invoke: async (..._args) => explicitClientOnly('functions.invoke'),
44
+ };
45
+ const live = {
46
+ intent: async (..._args) => explicitClientOnly('live.intent'),
47
+ status: async (..._args) => explicitClientOnly('live.status'),
48
+ };
49
+
50
+ async function getIdToken() {
51
+ throw new Error('getIdToken is not available as a tarobase-server top-level auth operation. Use createWalletClient({ keypair }) and call the returned client methods.');
52
+ }
53
+
19
54
  const PRESIGNED_BLOCKHASH_ERROR = 'Server signedTransaction blockhash is stale or expired';
20
55
  const BOUNDED_PROGRAM_MAINNET = 'poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp';
21
56
  const BOUNDED_PROGRAM_DEVNET = 'taro6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRu';
@@ -35,32 +70,6 @@ const ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([
35
70
  SET_DOCUMENTS_DISCRIMINATOR,
36
71
  SET_DOCUMENTS_V2_DISCRIMINATOR,
37
72
  ]);
38
- function loadKeypairFromEnv() {
39
- var _a;
40
- let secret;
41
- let found;
42
- for (const name of ENV_VARS) {
43
- const v = (_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a[name];
44
- if (v) {
45
- secret = v;
46
- found = name;
47
- break;
48
- }
49
- }
50
- if (!secret) {
51
- throw new Error(`No server keypair: set ${ENV_VARS[0]} to a base58 secret key (or JSON array), ` +
52
- `or pass one explicitly via createWalletClient({ keypair }).`);
53
- }
54
- try {
55
- const secretKey = secret.trim().startsWith('[')
56
- ? Uint8Array.from(JSON.parse(secret))
57
- : bs58.decode(secret.trim());
58
- return Keypair.fromSecretKey(secretKey);
59
- }
60
- catch (err) {
61
- throw new Error(`Unable to parse ${found}. Ensure it is valid base58 or a JSON array.`);
62
- }
63
- }
64
73
  /* ──────────────────────────────────────────────────────────
65
74
  * Helper – fetch getPriorityFeeEstimate
66
75
  * ──────────────────────────────────────────────────────── */
@@ -289,13 +298,15 @@ function assertAllowedServerPreInstructions(preInstructions) {
289
298
  }
290
299
  }
291
300
  class SolanaKeypairProvider {
292
- constructor(rpcUrl = null, keypair) {
301
+ constructor(rpcUrl, serverKeypair) {
293
302
  this.rpcUrl = rpcUrl;
294
- this.explicitKeypair = keypair;
303
+ this.serverKeypair = serverKeypair;
295
304
  }
296
305
  get keypair() {
297
- var _a, _b;
298
- return ((_a = this.cachedKeypair) !== null && _a !== void 0 ? _a : (this.cachedKeypair = (_b = this.explicitKeypair) !== null && _b !== void 0 ? _b : loadKeypairFromEnv()));
306
+ if (!this.serverKeypair) {
307
+ throw new Error('Server keypair is required; use createWalletClient({ keypair }) or pass a Keypair to SolanaKeypairProvider.');
308
+ }
309
+ return this.serverKeypair;
299
310
  }
300
311
  /* ----------------------------------------------------------- *
301
312
  * (Auth stubs – fill in later if needed)
@@ -610,9 +621,6 @@ class SolanaKeypairProvider {
610
621
 
611
622
  /**
612
623
  * Server-side OffchainAuthProvider wrapper for the poofnet environment.
613
- *
614
- * For signMessage, this generates a mock signature using SHA-256 hashing.
615
- * This is used for offchain transaction signing.
616
624
  */
617
625
  class OffchainAuthProvider {
618
626
  constructor(wrappedProvider) {
@@ -631,15 +639,8 @@ class OffchainAuthProvider {
631
639
  return this.wrappedProvider.getNativeMethods();
632
640
  }
633
641
  async signMessage(message) {
634
- // Delegate to wrapped provider for real signing
635
642
  return this.wrappedProvider.signMessage(message);
636
643
  }
637
- async signMessageMock(message) {
638
- // Generate mock signature (SHA-256 hash of message, base64 encoded)
639
- // This is used for offchain transaction signing
640
- const hash = crypto.createHash('sha256').update(message).digest('base64');
641
- return hash;
642
- }
643
644
  async signTransaction(transaction) {
644
645
  throw new Error('Poofnet does not support real Solana transactions. Deploy your project to mainnet to use this feature.');
645
646
  }
@@ -656,44 +657,6 @@ class OffchainAuthProvider {
656
657
  }
657
658
  }
658
659
 
659
- let currentAuthProvider = null;
660
- async function getAuthProvider() {
661
- var _a;
662
- const config = await getConfig();
663
- if (currentAuthProvider) {
664
- // If provider exists but chain is "offchain" and it's not already wrapped, rewrap it
665
- if (config.chain === "offchain" && !(currentAuthProvider instanceof OffchainAuthProvider)) {
666
- currentAuthProvider = new OffchainAuthProvider(currentAuthProvider);
667
- }
668
- return currentAuthProvider;
669
- }
670
- currentAuthProvider = await matchAuthProvider((_a = config.rpcUrl) !== null && _a !== void 0 ? _a : null);
671
- // Wrap with OffchainAuthProvider for offchain chain
672
- if (config.chain === "offchain") {
673
- currentAuthProvider = new OffchainAuthProvider(currentAuthProvider);
674
- }
675
- return currentAuthProvider;
676
- }
677
- async function matchAuthProvider(rpcUrl) {
678
- return new SolanaKeypairProvider(rpcUrl);
679
- }
680
-
681
- let authProviderInstance = null;
682
- async function init(newConfig) {
683
- // Initialize config first so getAuthProvider can access it
684
- // Server-side skips backend init since it already has all needed config
685
- await init$1(Object.assign(Object.assign({}, newConfig), { isServer: true, skipBackendInit: true }));
686
- // Get the auth provider (which will wrap it if chain is "offchain")
687
- authProviderInstance = await getAuthProvider();
688
- // Update config with the wrapped provider
689
- await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance, isServer: true, skipBackendInit: true }));
690
- }
691
-
692
- // Wrapper for getIdToken - passes isServer=true for server-side usage
693
- async function getIdToken() {
694
- return getIdToken$1(true);
695
- }
696
-
697
660
  var __rest = (undefined && undefined.__rest) || function (s, e) {
698
661
  var t = {};
699
662
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -750,8 +713,8 @@ class WalletClient {
750
713
  this.sessionManager = sessionManager;
751
714
  this.address = address;
752
715
  this.live = {
753
- intent: (roomPath, intent, opts = {}) => live.intent(roomPath, intent, this.mergeLiveIntentOptions(opts)),
754
- status: (roomPath, opts = {}) => live.status(roomPath, Object.assign(Object.assign({}, opts), { headers: this.sanitizeHeaders(opts.headers) })),
716
+ intent: (roomPath, intent, opts = {}) => live$1.intent(roomPath, intent, this.mergeLiveIntentOptions(opts)),
717
+ status: (roomPath, opts = {}) => live$1.status(roomPath, Object.assign(Object.assign({}, opts), { headers: this.sanitizeHeaders(opts.headers) })),
755
718
  };
756
719
  }
757
720
  /* ---- Auth override helpers ---- */
@@ -800,51 +763,50 @@ class WalletClient {
800
763
  }
801
764
  /* ---- Data operations ---- */
802
765
  async set(path, document, options) {
803
- return set(path, document, this.mergeSetOverrides(options));
766
+ return set$1(path, document, this.mergeSetOverrides(options));
804
767
  }
805
768
  async setMany(many, options) {
806
- return setMany(many, this.mergeSetOverrides(options));
769
+ return setMany$1(many, this.mergeSetOverrides(options));
807
770
  }
808
771
  async setFile(path, file, options) {
809
- return setFile(path, file, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
772
+ return setFile$1(path, file, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
810
773
  }
811
774
  async get(path, opts) {
812
- return get(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
775
+ return get$1(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
813
776
  }
814
777
  async getMany(paths, opts) {
815
- return getMany(paths, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides() }));
778
+ return getMany$1(paths, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides() }));
816
779
  }
817
780
  async getFiles(path, options) {
818
- return getFiles(path, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
781
+ return getFiles$1(path, { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) });
819
782
  }
820
783
  async search(path, query, opts = {}) {
821
- return search(path, query, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
784
+ return search$1(path, query, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
822
785
  }
823
786
  async runQuery(absolutePath, queryName, queryArgs, opts) {
824
- return runQuery(absolutePath, queryName, queryArgs, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
787
+ return runQuery$1(absolutePath, queryName, queryArgs, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
825
788
  }
826
789
  async runQueryMany(many, opts) {
827
- return runQueryMany(many, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
790
+ return runQueryMany$1(many, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
828
791
  }
829
792
  async runExpression(expression, queryArgs, options) {
830
- return runExpression(expression, queryArgs, Object.assign(Object.assign({}, options), { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) }));
793
+ return runExpression$1(expression, queryArgs, Object.assign(Object.assign({}, options), { _overrides: this.mergeReadOverrides(options === null || options === void 0 ? void 0 : options._overrides) }));
831
794
  }
832
795
  async runExpressionMany(many) {
833
796
  const ovr = this.mergeReadOverrides();
834
- return runExpressionMany(many.map(m => (Object.assign(Object.assign({}, m), { _overrides: ovr }))));
797
+ return runExpressionMany$1(many.map(m => (Object.assign(Object.assign({}, m), { _overrides: ovr }))));
835
798
  }
836
799
  async count(path, opts = {}) {
837
- return count(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
800
+ return count$1(path, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
838
801
  }
839
802
  async aggregate(path, operation, opts = {}) {
840
- return aggregate(path, operation, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
803
+ return aggregate$1(path, operation, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
841
804
  }
842
805
  async queryAggregate(path, spec, opts = {}) {
843
- return queryAggregate(path, spec, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
806
+ return queryAggregate$1(path, spec, Object.assign(Object.assign({}, opts), { _overrides: this.mergeReadOverrides(opts === null || opts === void 0 ? void 0 : opts._overrides) }));
844
807
  }
845
808
  /**
846
- * Subscribe to real-time updates as THIS wallet's identity. Unlike the global
847
- * `subscribe`, this needs no `BOUNDED_PRIVATE_KEY` env var — the WS connection
809
+ * Subscribe to real-time updates as THIS wallet's identity. The WS connection
848
810
  * authenticates with the wallet's own session (so read rules see the right
849
811
  * principal), and is scoped to its own connection so it never crosses another
850
812
  * identity. Accepts a bare callback or `{ onData, onError, filter, ... }`.
@@ -853,22 +815,21 @@ class WalletClient {
853
815
  async subscribe(path, options) {
854
816
  const opts = typeof options === 'function' ? { onData: options } : Object.assign({}, options);
855
817
  const ovr = this.buildOverrides();
856
- return subscribe(path, Object.assign(Object.assign({}, opts), { _overrides: {
818
+ return subscribe$1(path, Object.assign(Object.assign({}, opts), { _overrides: {
857
819
  _getAuthHeaders: ovr._getAuthHeaders,
858
820
  _clearAuth: ovr._clearAuth,
859
821
  _walletAddress: ovr._walletAddress,
860
822
  } }));
861
823
  }
862
824
  /**
863
- * Invoke a deployed Bounded Function AS this wallet's identity. Unlike the
864
- * top-level `functions.invoke`, this needs no `BOUNDED_PRIVATE_KEY` env var —
865
- * the dispatcher sees the wallet's verified session, so the function's `auth`
866
- * rule + `ctx.user` reflect this client. Returns the function's JSON; throws
825
+ * Invoke a deployed Bounded Function AS this wallet's identity. The dispatcher
826
+ * sees the wallet's verified session, so the function's `auth` rule +
827
+ * `ctx.user` reflect this client. Returns the function's JSON; throws
867
828
  * `FunctionInvokeError` on 401/403/404/503.
868
829
  */
869
830
  async invoke(name, args = {}, opts = {}) {
870
831
  const ovr = this.buildOverrides();
871
- return functions.invoke(name, args, Object.assign(Object.assign({}, opts), { _overrides: { _getAuthHeaders: ovr._getAuthHeaders } }));
832
+ return functions$1.invoke(name, args, Object.assign(Object.assign({}, opts), { _overrides: { _getAuthHeaders: ovr._getAuthHeaders } }));
872
833
  }
873
834
  /* ---- Signing operations (use provider directly) ---- */
874
835
  async signMessage(message) {
@@ -1159,5 +1120,5 @@ async function verifyWebhook(rawBody, headers, opts = {}) {
1159
1120
  return payload;
1160
1121
  }
1161
1122
 
1162
- export { DEFAULT_WEBHOOK_KEYS_URL, InMemoryReplayStore, WalletClient, WebhookVerificationError, clearWebhookKeyCache, clearWebhookReplayCache, createWalletClient, getAuthProvider, getIdToken, init, verifyWebhook };
1123
+ export { DEFAULT_WEBHOOK_KEYS_URL, InMemoryReplayStore, WalletClient, WebhookVerificationError, aggregate, clearWebhookKeyCache, clearWebhookReplayCache, count, createWalletClient, functions, get, getAuthProvider, getFiles, getIdToken, getMany, init, invokeFunction, live, liveIntent, liveStatus, queryAggregate, runExpression, runExpressionMany, runQuery, runQueryMany, search, set, setFile, setMany, signAndSubmitTransaction, signMessage, signTransaction, subscribe, verifyWebhook };
1163
1124
  //# sourceMappingURL=index.mjs.map