@pooflabs/server 0.0.3 → 0.0.4

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,6 +1,7 @@
1
1
  import axios from 'axios';
2
2
  import { PublicKey, ComputeBudgetProgram, SystemProgram, TransactionInstruction, VersionedTransaction, TransactionMessage, Keypair, Connection, Transaction } from '@solana/web3.js';
3
- import require$$0 from 'crypto';
3
+ import require$$0 from 'buffer';
4
+ import require$$0$1 from 'crypto';
4
5
  import * as anchor from '@coral-xyz/anchor';
5
6
  import { Program } from '@coral-xyz/anchor';
6
7
 
@@ -17,6 +18,15 @@ async function getAxiosAuthClient() {
17
18
  }
18
19
  return axiosClient;
19
20
  }
21
+ async function genAuthNonce() {
22
+ const client = await getAxiosAuthClient();
23
+ const config = await getConfig();
24
+ const appId = config.appId;
25
+ const response = await client.post('/auth/nonce', {
26
+ appId
27
+ });
28
+ return response.data.nonce;
29
+ }
20
30
  async function createSessionWithSignature(address, message, signature) {
21
31
  const client = await getAxiosAuthClient();
22
32
  const config = await getConfig();
@@ -173,137 +183,235 @@ class WebSessionManager {
173
183
  }
174
184
  WebSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
175
185
 
176
- // base-x encoding / decoding
177
- // Copyright (c) 2018 base-x contributors
178
- // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
179
- // Distributed under the MIT software license, see the accompanying
180
- // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
181
- function base (ALPHABET) {
182
- if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
183
- const BASE_MAP = new Uint8Array(256);
184
- for (let j = 0; j < BASE_MAP.length; j++) {
185
- BASE_MAP[j] = 255;
186
- }
187
- for (let i = 0; i < ALPHABET.length; i++) {
188
- const x = ALPHABET.charAt(i);
189
- const xc = x.charCodeAt(0);
190
- if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
191
- BASE_MAP[xc] = i;
192
- }
193
- const BASE = ALPHABET.length;
194
- const LEADER = ALPHABET.charAt(0);
195
- const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
196
- const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
197
- function encode (source) {
198
- // eslint-disable-next-line no-empty
199
- if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
200
- source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
201
- } else if (Array.isArray(source)) {
202
- source = Uint8Array.from(source);
203
- }
204
- if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
205
- if (source.length === 0) { return '' }
206
- // Skip & count leading zeroes.
207
- let zeroes = 0;
208
- let length = 0;
209
- let pbegin = 0;
210
- const pend = source.length;
211
- while (pbegin !== pend && source[pbegin] === 0) {
212
- pbegin++;
213
- zeroes++;
214
- }
215
- // Allocate enough space in big-endian base58 representation.
216
- const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
217
- const b58 = new Uint8Array(size);
218
- // Process the bytes.
219
- while (pbegin !== pend) {
220
- let carry = source[pbegin];
221
- // Apply "b58 = b58 * 256 + ch".
222
- let i = 0;
223
- for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
224
- carry += (256 * b58[it1]) >>> 0;
225
- b58[it1] = (carry % BASE) >>> 0;
226
- carry = (carry / BASE) >>> 0;
227
- }
228
- if (carry !== 0) { throw new Error('Non-zero carry') }
229
- length = i;
230
- pbegin++;
231
- }
232
- // Skip leading zeroes in base58 result.
233
- let it2 = size - length;
234
- while (it2 !== size && b58[it2] === 0) {
235
- it2++;
236
- }
237
- // Translate the result into a string.
238
- let str = LEADER.repeat(zeroes);
239
- for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
240
- return str
241
- }
242
- function decodeUnsafe (source) {
243
- if (typeof source !== 'string') { throw new TypeError('Expected String') }
244
- if (source.length === 0) { return new Uint8Array() }
245
- let psz = 0;
246
- // Skip and count leading '1's.
247
- let zeroes = 0;
248
- let length = 0;
249
- while (source[psz] === LEADER) {
250
- zeroes++;
251
- psz++;
252
- }
253
- // Allocate enough space in big-endian base256 representation.
254
- const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
255
- const b256 = new Uint8Array(size);
256
- // Process the characters.
257
- while (psz < source.length) {
258
- // Find code of next character
259
- const charCode = source.charCodeAt(psz);
260
- // Base map can not be indexed using char code
261
- if (charCode > 255) { return }
262
- // Decode character
263
- let carry = BASE_MAP[charCode];
264
- // Invalid character
265
- if (carry === 255) { return }
266
- let i = 0;
267
- for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
268
- carry += (BASE * b256[it3]) >>> 0;
269
- b256[it3] = (carry % 256) >>> 0;
270
- carry = (carry / 256) >>> 0;
271
- }
272
- if (carry !== 0) { throw new Error('Non-zero carry') }
273
- length = i;
274
- psz++;
275
- }
276
- // Skip leading zeroes in b256.
277
- let it4 = size - length;
278
- while (it4 !== size && b256[it4] === 0) {
279
- it4++;
280
- }
281
- const vch = new Uint8Array(zeroes + (size - it4));
282
- let j = zeroes;
283
- while (it4 !== size) {
284
- vch[j++] = b256[it4++];
285
- }
286
- return vch
287
- }
288
- function decode (string) {
289
- const buffer = decodeUnsafe(string);
290
- if (buffer) { return buffer }
291
- throw new Error('Non-base' + BASE + ' character')
292
- }
293
- return {
294
- encode,
295
- decodeUnsafe,
296
- decode
297
- }
186
+ function getDefaultExportFromCjs$1 (x) {
187
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
298
188
  }
299
189
 
300
- var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
301
- var bs58$2 = base(ALPHABET);
190
+ var safeBuffer = {exports: {}};
302
191
 
303
- function getDefaultExportFromCjs$1 (x) {
304
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
192
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
193
+
194
+ var hasRequiredSafeBuffer;
195
+
196
+ function requireSafeBuffer () {
197
+ if (hasRequiredSafeBuffer) return safeBuffer.exports;
198
+ hasRequiredSafeBuffer = 1;
199
+ (function (module, exports$1) {
200
+ /* eslint-disable node/no-deprecated-api */
201
+ var buffer = require$$0;
202
+ var Buffer = buffer.Buffer;
203
+
204
+ // alternative to using Object.keys for old browsers
205
+ function copyProps (src, dst) {
206
+ for (var key in src) {
207
+ dst[key] = src[key];
208
+ }
209
+ }
210
+ if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) {
211
+ module.exports = buffer;
212
+ } else {
213
+ // Copy properties from require('buffer')
214
+ copyProps(buffer, exports$1);
215
+ exports$1.Buffer = SafeBuffer;
216
+ }
217
+
218
+ function SafeBuffer (arg, encodingOrOffset, length) {
219
+ return Buffer(arg, encodingOrOffset, length)
220
+ }
221
+
222
+ SafeBuffer.prototype = Object.create(Buffer.prototype);
223
+
224
+ // Copy static methods from Buffer
225
+ copyProps(Buffer, SafeBuffer);
226
+
227
+ SafeBuffer.from = function (arg, encodingOrOffset, length) {
228
+ if (typeof arg === 'number') {
229
+ throw new TypeError('Argument must not be a number')
230
+ }
231
+ return Buffer(arg, encodingOrOffset, length)
232
+ };
233
+
234
+ SafeBuffer.alloc = function (size, fill, encoding) {
235
+ if (typeof size !== 'number') {
236
+ throw new TypeError('Argument must be a number')
237
+ }
238
+ var buf = Buffer(size);
239
+ if (fill !== undefined) {
240
+ if (typeof encoding === 'string') {
241
+ buf.fill(fill, encoding);
242
+ } else {
243
+ buf.fill(fill);
244
+ }
245
+ } else {
246
+ buf.fill(0);
247
+ }
248
+ return buf
249
+ };
250
+
251
+ SafeBuffer.allocUnsafe = function (size) {
252
+ if (typeof size !== 'number') {
253
+ throw new TypeError('Argument must be a number')
254
+ }
255
+ return Buffer(size)
256
+ };
257
+
258
+ SafeBuffer.allocUnsafeSlow = function (size) {
259
+ if (typeof size !== 'number') {
260
+ throw new TypeError('Argument must be a number')
261
+ }
262
+ return buffer.SlowBuffer(size)
263
+ };
264
+ } (safeBuffer, safeBuffer.exports));
265
+ return safeBuffer.exports;
305
266
  }
306
267
 
268
+ var src$1;
269
+ var hasRequiredSrc$1;
270
+
271
+ function requireSrc$1 () {
272
+ if (hasRequiredSrc$1) return src$1;
273
+ hasRequiredSrc$1 = 1;
274
+ // base-x encoding / decoding
275
+ // Copyright (c) 2018 base-x contributors
276
+ // Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
277
+ // Distributed under the MIT software license, see the accompanying
278
+ // file LICENSE or http://www.opensource.org/licenses/mit-license.php.
279
+ // @ts-ignore
280
+ var _Buffer = requireSafeBuffer().Buffer;
281
+ function base (ALPHABET) {
282
+ if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
283
+ var BASE_MAP = new Uint8Array(256);
284
+ for (var j = 0; j < BASE_MAP.length; j++) {
285
+ BASE_MAP[j] = 255;
286
+ }
287
+ for (var i = 0; i < ALPHABET.length; i++) {
288
+ var x = ALPHABET.charAt(i);
289
+ var xc = x.charCodeAt(0);
290
+ if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
291
+ BASE_MAP[xc] = i;
292
+ }
293
+ var BASE = ALPHABET.length;
294
+ var LEADER = ALPHABET.charAt(0);
295
+ var FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
296
+ var iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
297
+ function encode (source) {
298
+ if (Array.isArray(source) || source instanceof Uint8Array) { source = _Buffer.from(source); }
299
+ if (!_Buffer.isBuffer(source)) { throw new TypeError('Expected Buffer') }
300
+ if (source.length === 0) { return '' }
301
+ // Skip & count leading zeroes.
302
+ var zeroes = 0;
303
+ var length = 0;
304
+ var pbegin = 0;
305
+ var pend = source.length;
306
+ while (pbegin !== pend && source[pbegin] === 0) {
307
+ pbegin++;
308
+ zeroes++;
309
+ }
310
+ // Allocate enough space in big-endian base58 representation.
311
+ var size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
312
+ var b58 = new Uint8Array(size);
313
+ // Process the bytes.
314
+ while (pbegin !== pend) {
315
+ var carry = source[pbegin];
316
+ // Apply "b58 = b58 * 256 + ch".
317
+ var i = 0;
318
+ for (var it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
319
+ carry += (256 * b58[it1]) >>> 0;
320
+ b58[it1] = (carry % BASE) >>> 0;
321
+ carry = (carry / BASE) >>> 0;
322
+ }
323
+ if (carry !== 0) { throw new Error('Non-zero carry') }
324
+ length = i;
325
+ pbegin++;
326
+ }
327
+ // Skip leading zeroes in base58 result.
328
+ var it2 = size - length;
329
+ while (it2 !== size && b58[it2] === 0) {
330
+ it2++;
331
+ }
332
+ // Translate the result into a string.
333
+ var str = LEADER.repeat(zeroes);
334
+ for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
335
+ return str
336
+ }
337
+ function decodeUnsafe (source) {
338
+ if (typeof source !== 'string') { throw new TypeError('Expected String') }
339
+ if (source.length === 0) { return _Buffer.alloc(0) }
340
+ var psz = 0;
341
+ // Skip and count leading '1's.
342
+ var zeroes = 0;
343
+ var length = 0;
344
+ while (source[psz] === LEADER) {
345
+ zeroes++;
346
+ psz++;
347
+ }
348
+ // Allocate enough space in big-endian base256 representation.
349
+ var size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
350
+ var b256 = new Uint8Array(size);
351
+ // Process the characters.
352
+ while (psz < source.length) {
353
+ // Find code of next character
354
+ var charCode = source.charCodeAt(psz);
355
+ // Base map can not be indexed using char code
356
+ if (charCode > 255) { return }
357
+ // Decode character
358
+ var carry = BASE_MAP[charCode];
359
+ // Invalid character
360
+ if (carry === 255) { return }
361
+ var i = 0;
362
+ for (var it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
363
+ carry += (BASE * b256[it3]) >>> 0;
364
+ b256[it3] = (carry % 256) >>> 0;
365
+ carry = (carry / 256) >>> 0;
366
+ }
367
+ if (carry !== 0) { throw new Error('Non-zero carry') }
368
+ length = i;
369
+ psz++;
370
+ }
371
+ // Skip leading zeroes in b256.
372
+ var it4 = size - length;
373
+ while (it4 !== size && b256[it4] === 0) {
374
+ it4++;
375
+ }
376
+ var vch = _Buffer.allocUnsafe(zeroes + (size - it4));
377
+ vch.fill(0x00, 0, zeroes);
378
+ var j = zeroes;
379
+ while (it4 !== size) {
380
+ vch[j++] = b256[it4++];
381
+ }
382
+ return vch
383
+ }
384
+ function decode (string) {
385
+ var buffer = decodeUnsafe(string);
386
+ if (buffer) { return buffer }
387
+ throw new Error('Non-base' + BASE + ' character')
388
+ }
389
+ return {
390
+ encode: encode,
391
+ decodeUnsafe: decodeUnsafe,
392
+ decode: decode
393
+ }
394
+ }
395
+ src$1 = base;
396
+ return src$1;
397
+ }
398
+
399
+ var bs58$1$1;
400
+ var hasRequiredBs58$1;
401
+
402
+ function requireBs58$1 () {
403
+ if (hasRequiredBs58$1) return bs58$1$1;
404
+ hasRequiredBs58$1 = 1;
405
+ var basex = requireSrc$1();
406
+ var ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
407
+
408
+ bs58$1$1 = basex(ALPHABET);
409
+ return bs58$1$1;
410
+ }
411
+
412
+ var bs58Exports$1 = requireBs58$1();
413
+ var bs58$2 = /*@__PURE__*/getDefaultExportFromCjs$1(bs58Exports$1);
414
+
307
415
  function commonjsRequire$1(path) {
308
416
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
309
417
  }
@@ -2694,7 +2802,7 @@ function requireNaclFast$1 () {
2694
2802
  });
2695
2803
  } else if (typeof commonjsRequire$1 !== 'undefined') {
2696
2804
  // Node.js.
2697
- crypto = require$$0;
2805
+ crypto = require$$0$1;
2698
2806
  if (crypto && crypto.randomBytes) {
2699
2807
  nacl.setPRNG(function(x, n) {
2700
2808
  var i, v = crypto.randomBytes(n);
@@ -2766,7 +2874,7 @@ function requireBn () {
2766
2874
  if (hasRequiredBn) return bn$1.exports;
2767
2875
  hasRequiredBn = 1;
2768
2876
  (function (module) {
2769
- (function (module, exports) {
2877
+ (function (module, exports$1) {
2770
2878
 
2771
2879
  // Utils
2772
2880
  function assert (val, msg) {
@@ -2809,7 +2917,7 @@ function requireBn () {
2809
2917
  if (typeof module === 'object') {
2810
2918
  module.exports = BN;
2811
2919
  } else {
2812
- exports.BN = BN;
2920
+ exports$1.BN = BN;
2813
2921
  }
2814
2922
 
2815
2923
  BN.BN = BN;
@@ -6125,19 +6233,33 @@ var BN = /*@__PURE__*/getDefaultExportFromCjs$1(bnExports);
6125
6233
  /* ------------------------------------------------------------------ */
6126
6234
  /* RFC-4501 message */
6127
6235
  /* ------------------------------------------------------------------ */
6128
- async function genSolanaMessage(address) {
6236
+ async function genSolanaMessage(address, nonce) {
6129
6237
  var _a, _b;
6130
- /* Domain / origin arent available server-side – fall back to envs
6238
+ /* Domain / origin aren't available server-side – fall back to envs
6131
6239
  or simple placeholders. */
6132
6240
  const domain = (_a = process.env.SESSION_DOMAIN) !== null && _a !== void 0 ? _a : "server";
6133
6241
  const origin = (_b = process.env.SESSION_ORIGIN) !== null && _b !== void 0 ? _b : "server";
6134
6242
  const statement = "Sign this message to authenticate with our application.";
6135
- const ISO8601 = new Date().toISOString();
6243
+ const currentDate = new Date();
6244
+ const issuedAt = currentDate.toISOString();
6245
+ // If nonce is provided, include it and expiration time (for secure authentication)
6246
+ if (nonce) {
6247
+ const expirationDate = new Date(currentDate.getTime() + 5 * 60 * 1000);
6248
+ const expirationTime = expirationDate.toISOString();
6249
+ return `${statement}\n\n` +
6250
+ `Wallet address:\n${address}\n\n` +
6251
+ `Domain: ${domain}\n` +
6252
+ `Origin: ${origin}\n` +
6253
+ `Nonce: ${nonce}\n` +
6254
+ `Issued At: ${issuedAt}\n` +
6255
+ `Expiration Time: ${expirationTime}`;
6256
+ }
6257
+ // Backward compatible: without nonce (for server-side usage)
6136
6258
  return `${statement}\n\n` +
6137
6259
  `Wallet address:\n${address}\n\n` +
6138
6260
  `Domain: ${domain}\n` +
6139
6261
  `Origin: ${origin}\n` +
6140
- `Issued At: ${ISO8601}`;
6262
+ `Issued At: ${issuedAt}`;
6141
6263
  }
6142
6264
  // ─────────────────────────────────────────────────────────────
6143
6265
  // Serialization Helpers
@@ -9985,7 +10107,7 @@ function requireNaclFast () {
9985
10107
  });
9986
10108
  } else if (typeof commonjsRequire !== 'undefined') {
9987
10109
  // Node.js.
9988
- crypto = require$$0;
10110
+ crypto = require$$0$1;
9989
10111
  if (crypto && crypto.randomBytes) {
9990
10112
  nacl.setPRNG(function(x, n) {
9991
10113
  var i, v = crypto.randomBytes(n);
@@ -10443,5 +10565,5 @@ async function signTransaction(transaction) {
10443
10565
  return await authProviderInstance.signTransaction(transaction);
10444
10566
  }
10445
10567
 
10446
- export { ServerSessionManager, WebSessionManager, buildSetDocumentsTransaction, convertRemainingAccounts, createSessionWithPrivy, createSessionWithSignature, genSolanaMessage, get, getAuthProvider, getConfig, getFiles, getIdToken, init, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signSessionCreateMessage, signTransaction, subscribe };
10568
+ export { ServerSessionManager, WebSessionManager, buildSetDocumentsTransaction, convertRemainingAccounts, createSessionWithPrivy, createSessionWithSignature, genAuthNonce, genSolanaMessage, get, getAuthProvider, getConfig, getFiles, getIdToken, init, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signSessionCreateMessage, signTransaction, subscribe };
10447
10569
  //# sourceMappingURL=index.mjs.map