@pooflabs/core 0.0.10 → 0.0.12
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.js +45 -4
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +45 -4
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +20 -0
- package/dist/utils/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpDevnet-program.d.ts +127 -54
- package/dist/utils/sol/poof4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZpMainnet-program.d.ts +127 -54
- package/package.json +62 -62
package/dist/index.mjs
CHANGED
|
@@ -2982,7 +2982,8 @@ function loadKeypairFromEnv() {
|
|
|
2982
2982
|
async function createSession() {
|
|
2983
2983
|
const kp = loadKeypairFromEnv();
|
|
2984
2984
|
const address = kp.publicKey.toBase58();
|
|
2985
|
-
const
|
|
2985
|
+
const nonce = await genAuthNonce();
|
|
2986
|
+
const message = await genSolanaMessage(address, nonce);
|
|
2986
2987
|
/* sign the message */
|
|
2987
2988
|
const sigBytes = nacl.sign.detached(new TextEncoder().encode(message), kp.secretKey);
|
|
2988
2989
|
const signature = bufferExports.Buffer.from(sigBytes).toString("base64");
|
|
@@ -3385,9 +3386,15 @@ async function setMany(many, options) {
|
|
|
3385
3386
|
clearCacheByPrefix(path);
|
|
3386
3387
|
});
|
|
3387
3388
|
if (setResponse.status === 202) {
|
|
3388
|
-
// This means that the document needs to be set on-chain
|
|
3389
|
-
// required info to run this transaction.
|
|
3390
|
-
const transactions = setResponse.data
|
|
3389
|
+
// This means that the document needs to be set on-chain (or signed for offchain),
|
|
3390
|
+
// the API did nothing and gave us the required info to run this transaction.
|
|
3391
|
+
const { transactions, offchainTransaction } = setResponse.data;
|
|
3392
|
+
// Handle offchain transaction flow (for 'offchain' protocol apps)
|
|
3393
|
+
if (offchainTransaction) {
|
|
3394
|
+
const transactionResult = await handleOffchainTransaction(offchainTransaction, authProvider, options);
|
|
3395
|
+
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: transactionResult.signature, signedTransaction: transactionResult.signedTransaction });
|
|
3396
|
+
}
|
|
3397
|
+
// Handle Solana on-chain transaction flow
|
|
3391
3398
|
let lastTxSignature = undefined;
|
|
3392
3399
|
let signedTransaction = undefined;
|
|
3393
3400
|
for (let i = 0; i < transactions.length; i++) {
|
|
@@ -3468,6 +3475,40 @@ async function setMany(many, options) {
|
|
|
3468
3475
|
const transactionResult = await authProvider.runTransaction(undefined, solTransaction, options);
|
|
3469
3476
|
return transactionResult;
|
|
3470
3477
|
}
|
|
3478
|
+
async function handleOffchainTransaction(tx, authProvider, options) {
|
|
3479
|
+
const config = await getConfig();
|
|
3480
|
+
// 1. Sign the transaction message using the auth provider
|
|
3481
|
+
const signature = await authProvider.signMessage(tx.message);
|
|
3482
|
+
// 2. Create signed transaction
|
|
3483
|
+
const signedTx = {
|
|
3484
|
+
transaction: tx,
|
|
3485
|
+
signature
|
|
3486
|
+
};
|
|
3487
|
+
// 3. If shouldSubmitTx is false, return signed but not submitted
|
|
3488
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
3489
|
+
return {
|
|
3490
|
+
signature: '',
|
|
3491
|
+
signedTransaction: bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')
|
|
3492
|
+
};
|
|
3493
|
+
}
|
|
3494
|
+
// 4. Submit to RPC endpoint
|
|
3495
|
+
const rpcUrl = `${config.apiUrl}/app/${config.appId}/rpc`;
|
|
3496
|
+
const rpcResponse = await fetch(rpcUrl, {
|
|
3497
|
+
method: 'POST',
|
|
3498
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3499
|
+
body: JSON.stringify({
|
|
3500
|
+
jsonrpc: '2.0',
|
|
3501
|
+
id: 1,
|
|
3502
|
+
method: 'sendTransaction',
|
|
3503
|
+
params: [bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')]
|
|
3504
|
+
})
|
|
3505
|
+
});
|
|
3506
|
+
const result = await rpcResponse.json();
|
|
3507
|
+
if (result.error) {
|
|
3508
|
+
throw new Error(result.error.message);
|
|
3509
|
+
}
|
|
3510
|
+
return { signature: result.result };
|
|
3511
|
+
}
|
|
3471
3512
|
}
|
|
3472
3513
|
// Helper to clear cache entries by prefix
|
|
3473
3514
|
function clearCacheByPrefix(prefix) {
|