@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.js
CHANGED
|
@@ -3002,7 +3002,8 @@ function loadKeypairFromEnv() {
|
|
|
3002
3002
|
async function createSession() {
|
|
3003
3003
|
const kp = loadKeypairFromEnv();
|
|
3004
3004
|
const address = kp.publicKey.toBase58();
|
|
3005
|
-
const
|
|
3005
|
+
const nonce = await genAuthNonce();
|
|
3006
|
+
const message = await genSolanaMessage(address, nonce);
|
|
3006
3007
|
/* sign the message */
|
|
3007
3008
|
const sigBytes = nacl.sign.detached(new TextEncoder().encode(message), kp.secretKey);
|
|
3008
3009
|
const signature = bufferExports.Buffer.from(sigBytes).toString("base64");
|
|
@@ -3405,9 +3406,15 @@ async function setMany(many, options) {
|
|
|
3405
3406
|
clearCacheByPrefix(path);
|
|
3406
3407
|
});
|
|
3407
3408
|
if (setResponse.status === 202) {
|
|
3408
|
-
// This means that the document needs to be set on-chain
|
|
3409
|
-
// required info to run this transaction.
|
|
3410
|
-
const transactions = setResponse.data
|
|
3409
|
+
// This means that the document needs to be set on-chain (or signed for offchain),
|
|
3410
|
+
// the API did nothing and gave us the required info to run this transaction.
|
|
3411
|
+
const { transactions, offchainTransaction } = setResponse.data;
|
|
3412
|
+
// Handle offchain transaction flow (for 'offchain' protocol apps)
|
|
3413
|
+
if (offchainTransaction) {
|
|
3414
|
+
const transactionResult = await handleOffchainTransaction(offchainTransaction, authProvider, options);
|
|
3415
|
+
return Object.assign(Object.assign({}, documents.map(d => d.document)), { transactionId: transactionResult.signature, signedTransaction: transactionResult.signedTransaction });
|
|
3416
|
+
}
|
|
3417
|
+
// Handle Solana on-chain transaction flow
|
|
3411
3418
|
let lastTxSignature = undefined;
|
|
3412
3419
|
let signedTransaction = undefined;
|
|
3413
3420
|
for (let i = 0; i < transactions.length; i++) {
|
|
@@ -3488,6 +3495,40 @@ async function setMany(many, options) {
|
|
|
3488
3495
|
const transactionResult = await authProvider.runTransaction(undefined, solTransaction, options);
|
|
3489
3496
|
return transactionResult;
|
|
3490
3497
|
}
|
|
3498
|
+
async function handleOffchainTransaction(tx, authProvider, options) {
|
|
3499
|
+
const config = await getConfig();
|
|
3500
|
+
// 1. Sign the transaction message using the auth provider
|
|
3501
|
+
const signature = await authProvider.signMessage(tx.message);
|
|
3502
|
+
// 2. Create signed transaction
|
|
3503
|
+
const signedTx = {
|
|
3504
|
+
transaction: tx,
|
|
3505
|
+
signature
|
|
3506
|
+
};
|
|
3507
|
+
// 3. If shouldSubmitTx is false, return signed but not submitted
|
|
3508
|
+
if ((options === null || options === void 0 ? void 0 : options.shouldSubmitTx) === false) {
|
|
3509
|
+
return {
|
|
3510
|
+
signature: '',
|
|
3511
|
+
signedTransaction: bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')
|
|
3512
|
+
};
|
|
3513
|
+
}
|
|
3514
|
+
// 4. Submit to RPC endpoint
|
|
3515
|
+
const rpcUrl = `${config.apiUrl}/app/${config.appId}/rpc`;
|
|
3516
|
+
const rpcResponse = await fetch(rpcUrl, {
|
|
3517
|
+
method: 'POST',
|
|
3518
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3519
|
+
body: JSON.stringify({
|
|
3520
|
+
jsonrpc: '2.0',
|
|
3521
|
+
id: 1,
|
|
3522
|
+
method: 'sendTransaction',
|
|
3523
|
+
params: [bufferExports.Buffer.from(JSON.stringify(signedTx)).toString('base64')]
|
|
3524
|
+
})
|
|
3525
|
+
});
|
|
3526
|
+
const result = await rpcResponse.json();
|
|
3527
|
+
if (result.error) {
|
|
3528
|
+
throw new Error(result.error.message);
|
|
3529
|
+
}
|
|
3530
|
+
return { signature: result.result };
|
|
3531
|
+
}
|
|
3491
3532
|
}
|
|
3492
3533
|
// Helper to clear cache entries by prefix
|
|
3493
3534
|
function clearCacheByPrefix(prefix) {
|