@pooflabs/server 0.0.2 → 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/auth/providers/solana-keypair-provider.d.ts +2 -1
- package/dist/global.d.ts +2 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +290 -160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +289 -161
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
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 '
|
|
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();
|
|
@@ -88,7 +98,6 @@ class WebSessionManager {
|
|
|
88
98
|
/* ---------- validate app-id ---------- */
|
|
89
99
|
const config = await getConfig();
|
|
90
100
|
if (sessionObj.appId && sessionObj.appId !== config.appId) {
|
|
91
|
-
console.warn("Session appId mismatch. Stored session belongs to a different app. Logging out.");
|
|
92
101
|
this.clearSession();
|
|
93
102
|
return null;
|
|
94
103
|
}
|
|
@@ -113,7 +122,6 @@ class WebSessionManager {
|
|
|
113
122
|
}
|
|
114
123
|
}
|
|
115
124
|
catch (err) {
|
|
116
|
-
console.error("Error decoding access token:", err);
|
|
117
125
|
return null;
|
|
118
126
|
}
|
|
119
127
|
return { address: sessionObj.address, session: sessionObj };
|
|
@@ -164,7 +172,6 @@ class WebSessionManager {
|
|
|
164
172
|
/* ---------- app-id guard ---------- */
|
|
165
173
|
const config = await getConfig();
|
|
166
174
|
if (sessionObj.appId && sessionObj.appId !== config.appId) {
|
|
167
|
-
console.warn("Session appId mismatch during token refresh. Logging out.");
|
|
168
175
|
this.clearSession();
|
|
169
176
|
return;
|
|
170
177
|
}
|
|
@@ -176,137 +183,235 @@ class WebSessionManager {
|
|
|
176
183
|
}
|
|
177
184
|
WebSessionManager.TAROBASE_SESSION_STORAGE_KEY = "tarobase_session_storage";
|
|
178
185
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
182
|
-
// Distributed under the MIT software license, see the accompanying
|
|
183
|
-
// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
|
184
|
-
function base (ALPHABET) {
|
|
185
|
-
if (ALPHABET.length >= 255) { throw new TypeError('Alphabet too long') }
|
|
186
|
-
const BASE_MAP = new Uint8Array(256);
|
|
187
|
-
for (let j = 0; j < BASE_MAP.length; j++) {
|
|
188
|
-
BASE_MAP[j] = 255;
|
|
189
|
-
}
|
|
190
|
-
for (let i = 0; i < ALPHABET.length; i++) {
|
|
191
|
-
const x = ALPHABET.charAt(i);
|
|
192
|
-
const xc = x.charCodeAt(0);
|
|
193
|
-
if (BASE_MAP[xc] !== 255) { throw new TypeError(x + ' is ambiguous') }
|
|
194
|
-
BASE_MAP[xc] = i;
|
|
195
|
-
}
|
|
196
|
-
const BASE = ALPHABET.length;
|
|
197
|
-
const LEADER = ALPHABET.charAt(0);
|
|
198
|
-
const FACTOR = Math.log(BASE) / Math.log(256); // log(BASE) / log(256), rounded up
|
|
199
|
-
const iFACTOR = Math.log(256) / Math.log(BASE); // log(256) / log(BASE), rounded up
|
|
200
|
-
function encode (source) {
|
|
201
|
-
// eslint-disable-next-line no-empty
|
|
202
|
-
if (source instanceof Uint8Array) ; else if (ArrayBuffer.isView(source)) {
|
|
203
|
-
source = new Uint8Array(source.buffer, source.byteOffset, source.byteLength);
|
|
204
|
-
} else if (Array.isArray(source)) {
|
|
205
|
-
source = Uint8Array.from(source);
|
|
206
|
-
}
|
|
207
|
-
if (!(source instanceof Uint8Array)) { throw new TypeError('Expected Uint8Array') }
|
|
208
|
-
if (source.length === 0) { return '' }
|
|
209
|
-
// Skip & count leading zeroes.
|
|
210
|
-
let zeroes = 0;
|
|
211
|
-
let length = 0;
|
|
212
|
-
let pbegin = 0;
|
|
213
|
-
const pend = source.length;
|
|
214
|
-
while (pbegin !== pend && source[pbegin] === 0) {
|
|
215
|
-
pbegin++;
|
|
216
|
-
zeroes++;
|
|
217
|
-
}
|
|
218
|
-
// Allocate enough space in big-endian base58 representation.
|
|
219
|
-
const size = ((pend - pbegin) * iFACTOR + 1) >>> 0;
|
|
220
|
-
const b58 = new Uint8Array(size);
|
|
221
|
-
// Process the bytes.
|
|
222
|
-
while (pbegin !== pend) {
|
|
223
|
-
let carry = source[pbegin];
|
|
224
|
-
// Apply "b58 = b58 * 256 + ch".
|
|
225
|
-
let i = 0;
|
|
226
|
-
for (let it1 = size - 1; (carry !== 0 || i < length) && (it1 !== -1); it1--, i++) {
|
|
227
|
-
carry += (256 * b58[it1]) >>> 0;
|
|
228
|
-
b58[it1] = (carry % BASE) >>> 0;
|
|
229
|
-
carry = (carry / BASE) >>> 0;
|
|
230
|
-
}
|
|
231
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
232
|
-
length = i;
|
|
233
|
-
pbegin++;
|
|
234
|
-
}
|
|
235
|
-
// Skip leading zeroes in base58 result.
|
|
236
|
-
let it2 = size - length;
|
|
237
|
-
while (it2 !== size && b58[it2] === 0) {
|
|
238
|
-
it2++;
|
|
239
|
-
}
|
|
240
|
-
// Translate the result into a string.
|
|
241
|
-
let str = LEADER.repeat(zeroes);
|
|
242
|
-
for (; it2 < size; ++it2) { str += ALPHABET.charAt(b58[it2]); }
|
|
243
|
-
return str
|
|
244
|
-
}
|
|
245
|
-
function decodeUnsafe (source) {
|
|
246
|
-
if (typeof source !== 'string') { throw new TypeError('Expected String') }
|
|
247
|
-
if (source.length === 0) { return new Uint8Array() }
|
|
248
|
-
let psz = 0;
|
|
249
|
-
// Skip and count leading '1's.
|
|
250
|
-
let zeroes = 0;
|
|
251
|
-
let length = 0;
|
|
252
|
-
while (source[psz] === LEADER) {
|
|
253
|
-
zeroes++;
|
|
254
|
-
psz++;
|
|
255
|
-
}
|
|
256
|
-
// Allocate enough space in big-endian base256 representation.
|
|
257
|
-
const size = (((source.length - psz) * FACTOR) + 1) >>> 0; // log(58) / log(256), rounded up.
|
|
258
|
-
const b256 = new Uint8Array(size);
|
|
259
|
-
// Process the characters.
|
|
260
|
-
while (psz < source.length) {
|
|
261
|
-
// Find code of next character
|
|
262
|
-
const charCode = source.charCodeAt(psz);
|
|
263
|
-
// Base map can not be indexed using char code
|
|
264
|
-
if (charCode > 255) { return }
|
|
265
|
-
// Decode character
|
|
266
|
-
let carry = BASE_MAP[charCode];
|
|
267
|
-
// Invalid character
|
|
268
|
-
if (carry === 255) { return }
|
|
269
|
-
let i = 0;
|
|
270
|
-
for (let it3 = size - 1; (carry !== 0 || i < length) && (it3 !== -1); it3--, i++) {
|
|
271
|
-
carry += (BASE * b256[it3]) >>> 0;
|
|
272
|
-
b256[it3] = (carry % 256) >>> 0;
|
|
273
|
-
carry = (carry / 256) >>> 0;
|
|
274
|
-
}
|
|
275
|
-
if (carry !== 0) { throw new Error('Non-zero carry') }
|
|
276
|
-
length = i;
|
|
277
|
-
psz++;
|
|
278
|
-
}
|
|
279
|
-
// Skip leading zeroes in b256.
|
|
280
|
-
let it4 = size - length;
|
|
281
|
-
while (it4 !== size && b256[it4] === 0) {
|
|
282
|
-
it4++;
|
|
283
|
-
}
|
|
284
|
-
const vch = new Uint8Array(zeroes + (size - it4));
|
|
285
|
-
let j = zeroes;
|
|
286
|
-
while (it4 !== size) {
|
|
287
|
-
vch[j++] = b256[it4++];
|
|
288
|
-
}
|
|
289
|
-
return vch
|
|
290
|
-
}
|
|
291
|
-
function decode (string) {
|
|
292
|
-
const buffer = decodeUnsafe(string);
|
|
293
|
-
if (buffer) { return buffer }
|
|
294
|
-
throw new Error('Non-base' + BASE + ' character')
|
|
295
|
-
}
|
|
296
|
-
return {
|
|
297
|
-
encode,
|
|
298
|
-
decodeUnsafe,
|
|
299
|
-
decode
|
|
300
|
-
}
|
|
186
|
+
function getDefaultExportFromCjs$1 (x) {
|
|
187
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
301
188
|
}
|
|
302
189
|
|
|
303
|
-
var
|
|
304
|
-
var bs58$2 = base(ALPHABET);
|
|
190
|
+
var safeBuffer = {exports: {}};
|
|
305
191
|
|
|
306
|
-
|
|
307
|
-
|
|
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;
|
|
308
266
|
}
|
|
309
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
|
+
|
|
310
415
|
function commonjsRequire$1(path) {
|
|
311
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.');
|
|
312
417
|
}
|
|
@@ -2697,7 +2802,7 @@ function requireNaclFast$1 () {
|
|
|
2697
2802
|
});
|
|
2698
2803
|
} else if (typeof commonjsRequire$1 !== 'undefined') {
|
|
2699
2804
|
// Node.js.
|
|
2700
|
-
crypto = require$$0;
|
|
2805
|
+
crypto = require$$0$1;
|
|
2701
2806
|
if (crypto && crypto.randomBytes) {
|
|
2702
2807
|
nacl.setPRNG(function(x, n) {
|
|
2703
2808
|
var i, v = crypto.randomBytes(n);
|
|
@@ -2769,7 +2874,7 @@ function requireBn () {
|
|
|
2769
2874
|
if (hasRequiredBn) return bn$1.exports;
|
|
2770
2875
|
hasRequiredBn = 1;
|
|
2771
2876
|
(function (module) {
|
|
2772
|
-
(function (module, exports) {
|
|
2877
|
+
(function (module, exports$1) {
|
|
2773
2878
|
|
|
2774
2879
|
// Utils
|
|
2775
2880
|
function assert (val, msg) {
|
|
@@ -2812,7 +2917,7 @@ function requireBn () {
|
|
|
2812
2917
|
if (typeof module === 'object') {
|
|
2813
2918
|
module.exports = BN;
|
|
2814
2919
|
} else {
|
|
2815
|
-
exports.BN = BN;
|
|
2920
|
+
exports$1.BN = BN;
|
|
2816
2921
|
}
|
|
2817
2922
|
|
|
2818
2923
|
BN.BN = BN;
|
|
@@ -6128,19 +6233,33 @@ var BN = /*@__PURE__*/getDefaultExportFromCjs$1(bnExports);
|
|
|
6128
6233
|
/* ------------------------------------------------------------------ */
|
|
6129
6234
|
/* RFC-4501 message */
|
|
6130
6235
|
/* ------------------------------------------------------------------ */
|
|
6131
|
-
async function genSolanaMessage(address) {
|
|
6236
|
+
async function genSolanaMessage(address, nonce) {
|
|
6132
6237
|
var _a, _b;
|
|
6133
|
-
/* Domain / origin aren
|
|
6238
|
+
/* Domain / origin aren't available server-side – fall back to envs
|
|
6134
6239
|
or simple placeholders. */
|
|
6135
6240
|
const domain = (_a = process.env.SESSION_DOMAIN) !== null && _a !== void 0 ? _a : "server";
|
|
6136
6241
|
const origin = (_b = process.env.SESSION_ORIGIN) !== null && _b !== void 0 ? _b : "server";
|
|
6137
6242
|
const statement = "Sign this message to authenticate with our application.";
|
|
6138
|
-
const
|
|
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)
|
|
6139
6258
|
return `${statement}\n\n` +
|
|
6140
6259
|
`Wallet address:\n${address}\n\n` +
|
|
6141
6260
|
`Domain: ${domain}\n` +
|
|
6142
6261
|
`Origin: ${origin}\n` +
|
|
6143
|
-
`Issued At: ${
|
|
6262
|
+
`Issued At: ${issuedAt}`;
|
|
6144
6263
|
}
|
|
6145
6264
|
// ─────────────────────────────────────────────────────────────
|
|
6146
6265
|
// Serialization Helpers
|
|
@@ -6257,7 +6376,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
6257
6376
|
const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash("confirmed");
|
|
6258
6377
|
tx.recentBlockhash = blockhash;
|
|
6259
6378
|
if (lutKey == null) {
|
|
6260
|
-
const
|
|
6379
|
+
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
6380
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, []);
|
|
6261
6381
|
const computeBudgetIxOptimized = ComputeBudgetProgram.setComputeUnitLimit({
|
|
6262
6382
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
6263
6383
|
}); // 20% buffer
|
|
@@ -6267,7 +6387,8 @@ async function buildSetDocumentsTransaction(connection, idl, anchorProvider, pay
|
|
|
6267
6387
|
const { value: table } = await connection.getAddressLookupTable(new PublicKey(lutKey));
|
|
6268
6388
|
if (!table)
|
|
6269
6389
|
throw new Error('LUT not found after creation/extend');
|
|
6270
|
-
const
|
|
6390
|
+
const isSurfnet = anchorProvider.connection.rpcEndpoint == "https://surfpool.fly.dev";
|
|
6391
|
+
const computeUnits = isSurfnet ? 1400000 : await getSimulationComputeUnits(connection, tx.instructions, payerPublicKey, [table]);
|
|
6271
6392
|
const computeBudgetIxOptimized = ComputeBudgetProgram.setComputeUnitLimit({
|
|
6272
6393
|
units: computeUnits ? computeUnits * 1.2 : 1400000,
|
|
6273
6394
|
}); // 20% buffer
|
|
@@ -6404,7 +6525,7 @@ function updateIdTokenAndAccessToken(idToken, accessToken) {
|
|
|
6404
6525
|
}
|
|
6405
6526
|
|
|
6406
6527
|
async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
6407
|
-
var _a, _b, _c, _d, _e, _f
|
|
6528
|
+
var _a, _b, _c, _d, _e, _f;
|
|
6408
6529
|
const config = await getConfig();
|
|
6409
6530
|
async function executeRequest() {
|
|
6410
6531
|
const authHeader = await createAuthHeader(config.isServer);
|
|
@@ -6454,8 +6575,7 @@ async function makeApiRequest(method, urlPath, data, _overrides) {
|
|
|
6454
6575
|
return { data: null, status: 404 };
|
|
6455
6576
|
}
|
|
6456
6577
|
if ((_d = (_c = error.response) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.message) {
|
|
6457
|
-
|
|
6458
|
-
throw new Error((_j = (_h = error.response) === null || _h === void 0 ? void 0 : _h.data) === null || _j === void 0 ? void 0 : _j.message);
|
|
6578
|
+
throw new Error((_f = (_e = error.response) === null || _e === void 0 ? void 0 : _e.data) === null || _f === void 0 ? void 0 : _f.message);
|
|
6459
6579
|
}
|
|
6460
6580
|
throw error;
|
|
6461
6581
|
}
|
|
@@ -6496,8 +6616,6 @@ function init$1(newConfig) {
|
|
|
6496
6616
|
isInitialized = true;
|
|
6497
6617
|
resolve();
|
|
6498
6618
|
}).catch((error) => {
|
|
6499
|
-
console.error('Failed to authenticate with API key or fetch config for this app:', error);
|
|
6500
|
-
console.error('Please check your API key and try again.');
|
|
6501
6619
|
reject(new Error("Failed to initialize Tarobase app."));
|
|
6502
6620
|
});
|
|
6503
6621
|
});
|
|
@@ -6601,16 +6719,11 @@ async function get(path, opts = {}) {
|
|
|
6601
6719
|
// Helper to clean up expired cache entries
|
|
6602
6720
|
function cleanupExpiredCache() {
|
|
6603
6721
|
const now = Date.now();
|
|
6604
|
-
let removedCount = 0;
|
|
6605
6722
|
Object.keys(getCache).forEach(key => {
|
|
6606
6723
|
if (getCache[key] && getCache[key].expiresAt < now) {
|
|
6607
6724
|
delete getCache[key];
|
|
6608
|
-
removedCount++;
|
|
6609
6725
|
}
|
|
6610
6726
|
});
|
|
6611
|
-
if (removedCount > 0) {
|
|
6612
|
-
console.debug(`Cleaned up ${removedCount} expired cache entries`);
|
|
6613
|
-
}
|
|
6614
6727
|
lastCacheCleanup = now;
|
|
6615
6728
|
}
|
|
6616
6729
|
async function runQuery(absolutePath, queryName, queryArgs) {
|
|
@@ -6744,7 +6857,6 @@ async function setMany(many, options) {
|
|
|
6744
6857
|
}
|
|
6745
6858
|
}
|
|
6746
6859
|
catch (error) {
|
|
6747
|
-
console.error("Error setting data", error);
|
|
6748
6860
|
throw error;
|
|
6749
6861
|
}
|
|
6750
6862
|
async function handleSolanaTransaction(tx, authProvider, options) {
|
|
@@ -6861,9 +6973,7 @@ async function setFile(path, file) {
|
|
|
6861
6973
|
});
|
|
6862
6974
|
// 3) Check if the upload was successful
|
|
6863
6975
|
if (!uploadResponse.ok) {
|
|
6864
|
-
|
|
6865
|
-
const errorText = await uploadResponse.text();
|
|
6866
|
-
console.error('S3 Error Body:', errorText);
|
|
6976
|
+
await uploadResponse.text();
|
|
6867
6977
|
throw new Error(`Upload failed with status: ${uploadResponse.status}`);
|
|
6868
6978
|
}
|
|
6869
6979
|
// Optionally return the file's public URL or some confirmation
|
|
@@ -7551,10 +7661,9 @@ async function subscribe(path, subscriptionOptions) {
|
|
|
7551
7661
|
}
|
|
7552
7662
|
});
|
|
7553
7663
|
ws.addEventListener('error', (event) => {
|
|
7554
|
-
console.error(`WebSocket error for path: ${connectionKey}`, event);
|
|
7555
7664
|
notifyError(connectionKey, event);
|
|
7556
7665
|
});
|
|
7557
|
-
ws.addEventListener('close', (
|
|
7666
|
+
ws.addEventListener('close', () => {
|
|
7558
7667
|
// Connection will be recreated on next subscription if needed
|
|
7559
7668
|
});
|
|
7560
7669
|
return async () => await removeSubscription(connectionKey, subscriptionOptions);
|
|
@@ -7595,8 +7704,7 @@ async function removeSubscription(connectionKey, subscription) {
|
|
|
7595
7704
|
ws.addEventListener('close', () => {
|
|
7596
7705
|
resolve();
|
|
7597
7706
|
});
|
|
7598
|
-
ws.addEventListener('error', (
|
|
7599
|
-
console.error(`WebSocket closure error for connection: ${connectionKey}`, err);
|
|
7707
|
+
ws.addEventListener('error', () => {
|
|
7600
7708
|
resolve(); // Resolve even on error to avoid hanging
|
|
7601
7709
|
});
|
|
7602
7710
|
ws.close();
|
|
@@ -9999,7 +10107,7 @@ function requireNaclFast () {
|
|
|
9999
10107
|
});
|
|
10000
10108
|
} else if (typeof commonjsRequire !== 'undefined') {
|
|
10001
10109
|
// Node.js.
|
|
10002
|
-
crypto = require$$0;
|
|
10110
|
+
crypto = require$$0$1;
|
|
10003
10111
|
if (crypto && crypto.randomBytes) {
|
|
10004
10112
|
nacl.setPRNG(function(x, n) {
|
|
10005
10113
|
var i, v = crypto.randomBytes(n);
|
|
@@ -10241,6 +10349,18 @@ class SolanaKeypairProvider {
|
|
|
10241
10349
|
const sig = nacl.sign.detached(new TextEncoder().encode(message), this.keypair.secretKey);
|
|
10242
10350
|
return Buffer.from(sig).toString('base64');
|
|
10243
10351
|
}
|
|
10352
|
+
/* ----------------------------------------------------------- *
|
|
10353
|
+
* Sign transaction
|
|
10354
|
+
* ----------------------------------------------------------- */
|
|
10355
|
+
async signTransaction(transaction) {
|
|
10356
|
+
if (transaction instanceof Transaction) {
|
|
10357
|
+
transaction.partialSign(this.keypair);
|
|
10358
|
+
}
|
|
10359
|
+
else if (transaction instanceof VersionedTransaction) {
|
|
10360
|
+
transaction.sign([this.keypair]);
|
|
10361
|
+
}
|
|
10362
|
+
return transaction;
|
|
10363
|
+
}
|
|
10244
10364
|
/* ----------------------------------------------------------- *
|
|
10245
10365
|
* Transaction runner
|
|
10246
10366
|
* ----------------------------------------------------------- */
|
|
@@ -10394,6 +10514,7 @@ class SolanaKeypairProvider {
|
|
|
10394
10514
|
let currentAuthProvider = null;
|
|
10395
10515
|
const SOLANA_DEVNET_RPC_URL$1 = "https://api.devnet.solana.com";
|
|
10396
10516
|
const SOLANA_MAINNET_RPC_URL$1 = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
10517
|
+
const SURFNET_RPC_URL$1 = "https://surfpool.fly.dev";
|
|
10397
10518
|
async function getAuthProvider() {
|
|
10398
10519
|
var _a;
|
|
10399
10520
|
if (currentAuthProvider) {
|
|
@@ -10409,7 +10530,7 @@ async function getAuthProvider() {
|
|
|
10409
10530
|
rpcUrl = SOLANA_MAINNET_RPC_URL$1;
|
|
10410
10531
|
}
|
|
10411
10532
|
else {
|
|
10412
|
-
rpcUrl =
|
|
10533
|
+
rpcUrl = SURFNET_RPC_URL$1;
|
|
10413
10534
|
}
|
|
10414
10535
|
currentAuthProvider = await matchAuthProvider((_a = config.rpcUrl) !== null && _a !== void 0 ? _a : rpcUrl);
|
|
10415
10536
|
return currentAuthProvider;
|
|
@@ -10421,6 +10542,7 @@ async function matchAuthProvider(rpcUrl) {
|
|
|
10421
10542
|
let authProviderInstance = null;
|
|
10422
10543
|
const SOLANA_DEVNET_RPC_URL = "https://api.devnet.solana.com";
|
|
10423
10544
|
const SOLANA_MAINNET_RPC_URL = "https://celestia-cegncv-fast-mainnet.helius-rpc.com";
|
|
10545
|
+
const SURFNET_RPC_URL = "https://surfpool.fly.dev";
|
|
10424
10546
|
async function init(newConfig) {
|
|
10425
10547
|
var _a;
|
|
10426
10548
|
let defaultRpcUrl = '';
|
|
@@ -10431,11 +10553,17 @@ async function init(newConfig) {
|
|
|
10431
10553
|
defaultRpcUrl = SOLANA_MAINNET_RPC_URL;
|
|
10432
10554
|
}
|
|
10433
10555
|
else {
|
|
10434
|
-
defaultRpcUrl =
|
|
10556
|
+
defaultRpcUrl = SURFNET_RPC_URL;
|
|
10435
10557
|
}
|
|
10436
10558
|
authProviderInstance = await matchAuthProvider((_a = newConfig.rpcUrl) !== null && _a !== void 0 ? _a : defaultRpcUrl);
|
|
10437
10559
|
await init$1(Object.assign(Object.assign({}, newConfig), { authProvider: authProviderInstance, isServer: true }));
|
|
10438
10560
|
}
|
|
10561
|
+
async function signTransaction(transaction) {
|
|
10562
|
+
if (!authProviderInstance) {
|
|
10563
|
+
throw new Error('Auth provider not initialized. Please call init() first.');
|
|
10564
|
+
}
|
|
10565
|
+
return await authProviderInstance.signTransaction(transaction);
|
|
10566
|
+
}
|
|
10439
10567
|
|
|
10440
|
-
export { ServerSessionManager, WebSessionManager, buildSetDocumentsTransaction, convertRemainingAccounts, createSessionWithPrivy, createSessionWithSignature, genSolanaMessage, get, getAuthProvider, getConfig, getFiles, getIdToken, init, refreshSession, runExpression, runExpressionMany, runQuery, runQueryMany, set, setFile, setMany, signSessionCreateMessage, 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 };
|
|
10441
10569
|
//# sourceMappingURL=index.mjs.map
|