@flashbacktech/flashbackclient 0.2.69 → 0.2.70

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.
@@ -136,11 +136,17 @@ class DealOps {
136
136
  * @returns Promise resolving to the payment result
137
137
  */
138
138
  this.payPendingConsumption = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id) => {
139
- await (0, transaction_1.executeWalletTransaction)(this.context, '', "pay_pending_consumption", [
139
+ const args = [
140
140
  { value: provider_id, type: 'address' },
141
141
  { value: consumer_id, type: 'address' },
142
142
  { value: deal_id, type: 'u32' }
143
- ]);
143
+ ];
144
+ if (this.context.serverSourceAddress) {
145
+ await (0, transaction_1.executeServerTransaction)(this.context, this.context.serverSourceAddress, "pay_pending_consumption", args);
146
+ }
147
+ else {
148
+ await (0, transaction_1.executeWalletTransaction)(this.context, '', "pay_pending_consumption", args);
149
+ }
144
150
  });
145
151
  /**
146
152
  * Updates deal consumption metrics (owner only)
@@ -151,13 +157,19 @@ class DealOps {
151
157
  * @returns Promise resolving to the update result
152
158
  */
153
159
  this.updateDealConsumption = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id, params) => {
154
- await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_consumption", [
160
+ const args = [
155
161
  { value: provider_id, type: 'address' },
156
162
  { value: consumer_id, type: 'address' },
157
163
  { value: deal_id, type: 'u32' },
158
164
  { value: params.storage_mb, type: 'u64' },
159
165
  { value: params.egress_mb, type: 'u64' }
160
- ]);
166
+ ];
167
+ if (this.context.serverSourceAddress) {
168
+ await (0, transaction_1.executeServerTransaction)(this.context, this.context.serverSourceAddress, "update_deal_consumption", args);
169
+ }
170
+ else {
171
+ await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_consumption", args);
172
+ }
161
173
  });
162
174
  /**
163
175
  * Updates deal SLA metrics (owner only)
@@ -168,13 +180,19 @@ class DealOps {
168
180
  * @returns Promise resolving to the update result
169
181
  */
170
182
  this.updateDealSLA = (0, decorator_1.withSignature)(async (provider_id, consumer_id, deal_id, params) => {
171
- await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_sla", [
183
+ const args = [
172
184
  { value: provider_id, type: 'address' },
173
185
  { value: consumer_id, type: 'address' },
174
186
  { value: deal_id, type: 'u32' },
175
187
  { value: params.sla_avg_latency_ms, type: 'u32' },
176
188
  { value: params.sla_avg_uptime_pct, type: 'u32' }
177
- ]);
189
+ ];
190
+ if (this.context.serverSourceAddress) {
191
+ await (0, transaction_1.executeServerTransaction)(this.context, this.context.serverSourceAddress, "update_deal_sla", args);
192
+ }
193
+ else {
194
+ await (0, transaction_1.executeWalletTransaction)(this.context, '', "update_deal_sla", args);
195
+ }
178
196
  });
179
197
  this.context = context;
180
198
  }
@@ -18,6 +18,13 @@ export interface FlashOnStellarClientConfigV2 {
18
18
  signTransaction?: (xdrToSign: string) => Promise<string>;
19
19
  /** Network configuration for Stellar (testnet/public) */
20
20
  network: StellarNetwork;
21
+ /**
22
+ * Stellar public key used as the source account for owner-only
23
+ * server-side operations (e.g. oracle worker calls).
24
+ * When set, owner-only methods use executeServerTransaction
25
+ * which does NOT prepend this address to the contract args.
26
+ */
27
+ serverSourceAddress?: string;
21
28
  }
22
29
  export type ClientContext = FlashOnStellarClientConfigV2;
23
30
  /**
@@ -21,6 +21,16 @@ export interface ContractMethodResponse {
21
21
  result: string | unknown;
22
22
  }
23
23
  export declare const getHorizonServer: (network: string) => Horizon.Server;
24
+ /**
25
+ * Executes a contract call using a server-side source account.
26
+ * Unlike executeWalletTransaction, this does NOT prepend the source address
27
+ * to the contract args — the args are passed as-is to the contract method.
28
+ * Used for owner-only operations invoked from backend workers.
29
+ */
30
+ export declare const executeServerTransaction: (context: ClientContext, sourceAddress: string, method: string, args?: Array<{
31
+ value: string | number | bigint | boolean | null | Array<unknown> | undefined;
32
+ type: "string" | "symbol" | "address" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "bool" | "vec";
33
+ }>) => Promise<ContractMethodResponse>;
24
34
  export declare const executeWalletTransaction: (context: ClientContext, wallet_address: string, method: string, additionalArgs?: Array<{
25
35
  value: string | number | bigint | boolean | null | Array<unknown> | undefined;
26
36
  type: "string" | "symbol" | "address" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "bool" | "vec";
@@ -34,5 +44,10 @@ export declare const executeMultiWalletTransactions: (context: ClientContext, wa
34
44
  }>, extraOperations?: xdr.Operation[]) => Promise<ContractMethodResponse>;
35
45
  declare const prepareTransaction: (context: ClientContext, address: string, contractCalls: ContractMethodCall | ContractMethodCall[], extraOperations?: xdr.Operation[]) => Promise<ContractMethodResponse>;
36
46
  declare const signTransaction: (context: ClientContext, xdrToSign: string, privateKey: string) => Promise<Transaction<Memo<MemoType>, Operation[]> | FeeBumpTransaction>;
47
+ /**
48
+ * Creates a signTransaction callback that signs with a private key.
49
+ * Use this for server-side / backend workers where there is no browser wallet.
50
+ */
51
+ export declare const createPrivateKeySigner: (secretKey: string, networkPassphrase: string) => ((xdrToSign: string) => Promise<string>);
37
52
  declare const sendTransaction: (context: ClientContext, signedTransactionXDR: string, bDebug?: boolean) => Promise<any>;
38
53
  export { prepareTransaction, sendTransaction, signTransaction, getNetwork, getPublicKeyFromPrivateKey, getServer, };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getServer = exports.getPublicKeyFromPrivateKey = exports.getNetwork = exports.signTransaction = exports.sendTransaction = exports.prepareTransaction = exports.executeMultiWalletTransactions = exports.executeWalletTransaction = exports.getHorizonServer = void 0;
3
+ exports.getServer = exports.getPublicKeyFromPrivateKey = exports.getNetwork = exports.signTransaction = exports.sendTransaction = exports.prepareTransaction = exports.createPrivateKeySigner = exports.executeMultiWalletTransactions = exports.executeWalletTransaction = exports.executeServerTransaction = exports.getHorizonServer = void 0;
4
4
  const timing_1 = require("../utils/timing");
5
5
  // Polyfill for BigInt JSON serialization
6
6
  BigInt.prototype.toJSON = function () {
@@ -72,6 +72,38 @@ const getHorizonServer = (network) => {
72
72
  }
73
73
  };
74
74
  exports.getHorizonServer = getHorizonServer;
75
+ /**
76
+ * Executes a contract call using a server-side source account.
77
+ * Unlike executeWalletTransaction, this does NOT prepend the source address
78
+ * to the contract args — the args are passed as-is to the contract method.
79
+ * Used for owner-only operations invoked from backend workers.
80
+ */
81
+ const executeServerTransaction = async (context, sourceAddress, method, args = []) => {
82
+ try {
83
+ const response = await prepareTransaction(context, sourceAddress, {
84
+ method,
85
+ args,
86
+ });
87
+ if (response.isSuccess) {
88
+ if (response.isReadOnly) {
89
+ return response;
90
+ }
91
+ const signedTxXDR = await context.signTransaction(response.result);
92
+ const sendResponse = await sendTransaction(context, signedTxXDR);
93
+ return {
94
+ isSuccess: true,
95
+ isReadOnly: false,
96
+ result: sendResponse,
97
+ };
98
+ }
99
+ return response;
100
+ }
101
+ catch (error) {
102
+ console.error('executeServerTransaction: Error occurred:', error);
103
+ throw error;
104
+ }
105
+ };
106
+ exports.executeServerTransaction = executeServerTransaction;
75
107
  const executeWalletTransaction = async (context, wallet_address, method, additionalArgs = []) => {
76
108
  try {
77
109
  const response = await prepareTransaction(context, wallet_address, {
@@ -225,6 +257,19 @@ const signTransaction = async (context, xdrToSign, privateKey) => {
225
257
  return preparedTransaction;
226
258
  };
227
259
  exports.signTransaction = signTransaction;
260
+ /**
261
+ * Creates a signTransaction callback that signs with a private key.
262
+ * Use this for server-side / backend workers where there is no browser wallet.
263
+ */
264
+ const createPrivateKeySigner = (secretKey, networkPassphrase) => {
265
+ return async (xdrToSign) => {
266
+ const keypair = stellar_sdk_1.Keypair.fromSecret(secretKey);
267
+ const tx = stellar_sdk_1.TransactionBuilder.fromXDR(xdrToSign, networkPassphrase);
268
+ tx.sign(keypair);
269
+ return tx.toXDR();
270
+ };
271
+ };
272
+ exports.createPrivateKeySigner = createPrivateKeySigner;
228
273
  const sendTransaction = async (context, signedTransactionXDR, bDebug = false) => {
229
274
  try {
230
275
  const server = getServer(context.network);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@flashbacktech/flashbackclient",
3
- "version": "0.2.69",
3
+ "version": "0.2.70",
4
4
  "type": "commonjs",
5
5
  "publishConfig": {
6
6
  "access": "public"