@bounded-sh/core 0.0.44 → 0.0.46
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/client/operations.d.ts +4 -2
- package/dist/client/solana-operations.d.ts +9 -0
- package/dist/index-Bq2Zug5X.mjs +8159 -0
- package/dist/index-Bq2Zug5X.mjs.map +1 -0
- package/dist/index-Kn7IIh5d.js +8231 -0
- package/dist/index-Kn7IIh5d.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.js +78 -8656
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -8569
- package/dist/index.mjs.map +1 -1
- package/dist/{realtime-store-Ck_VgTcv.js → realtime-store-DssTn6Nr.js} +3 -5
- package/dist/{realtime-store-Ck_VgTcv.js.map → realtime-store-DssTn6Nr.js.map} +1 -1
- package/dist/{realtime-store-D3t7PyZl.mjs → realtime-store-XKFKDJRA.mjs} +3 -5
- package/dist/{realtime-store-D3t7PyZl.mjs.map → realtime-store-XKFKDJRA.mjs.map} +1 -1
- package/dist/sol-utils-D0Tdlpsc.mjs +243 -0
- package/dist/sol-utils-D0Tdlpsc.mjs.map +1 -0
- package/dist/sol-utils-pVrt7VOx.js +246 -0
- package/dist/sol-utils-pVrt7VOx.js.map +1 -0
- package/dist/solana-message-DSkrhvy8.js +37 -0
- package/dist/solana-message-DSkrhvy8.js.map +1 -0
- package/dist/solana-message-Svo0_paO.mjs +35 -0
- package/dist/solana-message-Svo0_paO.mjs.map +1 -0
- package/dist/solana-operations-4MGSdS1U.mjs +255 -0
- package/dist/solana-operations-4MGSdS1U.mjs.map +1 -0
- package/dist/solana-operations-C_aie1aF.js +258 -0
- package/dist/solana-operations-C_aie1aF.js.map +1 -0
- package/dist/types.d.ts +2 -2
- package/dist/utils/api.d.ts +1 -0
- package/dist/utils/server-session-manager.d.ts +1 -1
- package/dist/utils/sol/sol-accessors.d.ts +29 -0
- package/dist/utils/sol/sol-utils.d.ts +3 -9
- package/dist/utils/sol/solana-message.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { g as getConfig } from './index-Bq2Zug5X.mjs';
|
|
2
|
+
import 'axios';
|
|
3
|
+
import 'tweetnacl';
|
|
4
|
+
import 'reconnecting-websocket';
|
|
5
|
+
import 'bn.js';
|
|
6
|
+
|
|
7
|
+
// NOTE: this message text must stay BYTE-IDENTICAL to what the wallet-auth
|
|
8
|
+
// verifier reconstructs — any drift breaks every SIWS login.
|
|
9
|
+
async function genSolanaMessage(address, nonce) {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
/* Domain / origin aren't available server-side – fall back to envs
|
|
12
|
+
or simple placeholders. */
|
|
13
|
+
const domain = (typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.SESSION_DOMAIN)) || "server";
|
|
14
|
+
const origin = (typeof process !== 'undefined' && ((_b = process.env) === null || _b === void 0 ? void 0 : _b.SESSION_ORIGIN)) || "server";
|
|
15
|
+
// SECURITY (audit-4 CRITICAL-1): bind the signed prompt to the target app.
|
|
16
|
+
// appId is read from the SAME global config that genAuthNonce + /session use,
|
|
17
|
+
// so the signed "App ID" is guaranteed to equal the app the session is minted
|
|
18
|
+
// for; the server verifier rejects any mismatch.
|
|
19
|
+
const appId = (await getConfig()).appId;
|
|
20
|
+
const statement = "Sign this message to authenticate with our application.";
|
|
21
|
+
const currentDate = new Date();
|
|
22
|
+
const issuedAt = currentDate.toISOString();
|
|
23
|
+
const expirationTime = new Date(currentDate.getTime() + 5 * 60 * 1000).toISOString();
|
|
24
|
+
return `${statement}\n\n` +
|
|
25
|
+
`Wallet address:\n${address}\n\n` +
|
|
26
|
+
`App ID: ${appId}\n` +
|
|
27
|
+
`Domain: ${domain}\n` +
|
|
28
|
+
`Origin: ${origin}\n` +
|
|
29
|
+
`Nonce: ${nonce}\n` +
|
|
30
|
+
`Issued At: ${issuedAt}\n` +
|
|
31
|
+
`Expiration Time: ${expirationTime}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { genSolanaMessage };
|
|
35
|
+
//# sourceMappingURL=solana-message-Svo0_paO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-message-Svo0_paO.mjs","sources":["../.rollup-tmp/utils/sol/solana-message.js"],"sourcesContent":["import { getConfig } from \"../../client/config\";\n// NOTE: this message text must stay BYTE-IDENTICAL to what the wallet-auth\n// verifier reconstructs — any drift breaks every SIWS login.\nexport async function genSolanaMessage(address, nonce) {\n var _a, _b;\n /* Domain / origin aren't available server-side – fall back to envs\n or simple placeholders. */\n const domain = (typeof process !== 'undefined' && ((_a = process.env) === null || _a === void 0 ? void 0 : _a.SESSION_DOMAIN)) || \"server\";\n const origin = (typeof process !== 'undefined' && ((_b = process.env) === null || _b === void 0 ? void 0 : _b.SESSION_ORIGIN)) || \"server\";\n // SECURITY (audit-4 CRITICAL-1): bind the signed prompt to the target app.\n // appId is read from the SAME global config that genAuthNonce + /session use,\n // so the signed \"App ID\" is guaranteed to equal the app the session is minted\n // for; the server verifier rejects any mismatch.\n const appId = (await getConfig()).appId;\n const statement = \"Sign this message to authenticate with our application.\";\n const currentDate = new Date();\n const issuedAt = currentDate.toISOString();\n const expirationTime = new Date(currentDate.getTime() + 5 * 60 * 1000).toISOString();\n return `${statement}\\n\\n` +\n `Wallet address:\\n${address}\\n\\n` +\n `App ID: ${appId}\\n` +\n `Domain: ${domain}\\n` +\n `Origin: ${origin}\\n` +\n `Nonce: ${nonce}\\n` +\n `Issued At: ${issuedAt}\\n` +\n `Expiration Time: ${expirationTime}`;\n}\n"],"names":[],"mappings":";;;;;;AACA;AACA;AACO,eAAe,gBAAgB,CAAC,OAAO,EAAE,KAAK,EAAE;AACvD,IAAI,IAAI,EAAE,EAAE,EAAE;AACd;AACA;AACA,IAAI,MAAM,MAAM,GAAG,CAAC,OAAO,OAAO,KAAK,WAAW,KAAK,CAAC,EAAE,GAAG,OAAO,CAAC,GAAG,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 'tweetnacl';
|
|
4
|
+
import 'reconnecting-websocket';
|
|
5
|
+
import 'bn.js';
|
|
6
|
+
|
|
7
|
+
const BOUNDED_PROGRAM_MAINNET = ['poof', '4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp'].join('');
|
|
8
|
+
const BOUNDED_PROGRAM_DEVNET = ['taro', '6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRu'].join('');
|
|
9
|
+
const COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';
|
|
10
|
+
const SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';
|
|
11
|
+
const ALLOWED_SERVER_TX_PROGRAMS = new Set([
|
|
12
|
+
BOUNDED_PROGRAM_MAINNET,
|
|
13
|
+
BOUNDED_PROGRAM_DEVNET,
|
|
14
|
+
COMPUTE_BUDGET_PROGRAM,
|
|
15
|
+
SYSTEM_PROGRAM_ID,
|
|
16
|
+
]);
|
|
17
|
+
const SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';
|
|
18
|
+
const SET_DOCUMENTS_V2_DISCRIMINATOR = '22,236,242,185,145,61,26,39';
|
|
19
|
+
const ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([
|
|
20
|
+
SET_DOCUMENTS_DISCRIMINATOR,
|
|
21
|
+
SET_DOCUMENTS_V2_DISCRIMINATOR,
|
|
22
|
+
]);
|
|
23
|
+
class BorshCursor {
|
|
24
|
+
constructor(data, offset, label) {
|
|
25
|
+
this.data = data;
|
|
26
|
+
this.offset = offset;
|
|
27
|
+
this.label = label;
|
|
28
|
+
}
|
|
29
|
+
requireBytes(length, field) {
|
|
30
|
+
if (this.offset + length > this.data.length) {
|
|
31
|
+
throw new Error(`${this.label} has malformed Bounded instruction data while reading ${field}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
readU8(field) { this.requireBytes(1, field); return this.data[this.offset++]; }
|
|
35
|
+
readU32(field) {
|
|
36
|
+
this.requireBytes(4, field);
|
|
37
|
+
const value = this.data[this.offset] | (this.data[this.offset + 1] << 8) |
|
|
38
|
+
(this.data[this.offset + 2] << 16) | (this.data[this.offset + 3] << 24);
|
|
39
|
+
this.offset += 4;
|
|
40
|
+
return value >>> 0;
|
|
41
|
+
}
|
|
42
|
+
skip(length, field) { this.requireBytes(length, field); this.offset += length; }
|
|
43
|
+
readString(field) {
|
|
44
|
+
const length = this.readU32(`${field} length`);
|
|
45
|
+
this.requireBytes(length, field);
|
|
46
|
+
const raw = this.data.slice(this.offset, this.offset + length);
|
|
47
|
+
this.offset += length;
|
|
48
|
+
return bufferExports.Buffer.from(raw).toString('utf8');
|
|
49
|
+
}
|
|
50
|
+
skipBytes(field) { this.skip(this.readU32(`${field} length`), field); }
|
|
51
|
+
isAtEnd() { return this.offset === this.data.length; }
|
|
52
|
+
}
|
|
53
|
+
function skipBoundedFieldValue(cursor) {
|
|
54
|
+
const option = cursor.readU8('operation value option');
|
|
55
|
+
if (option === 0)
|
|
56
|
+
return;
|
|
57
|
+
if (option !== 1)
|
|
58
|
+
throw new Error('Server transaction has malformed Bounded field value option');
|
|
59
|
+
const variant = cursor.readU8('operation value variant');
|
|
60
|
+
if (variant === 0 || variant === 1)
|
|
61
|
+
cursor.skip(8, 'operation numeric value');
|
|
62
|
+
else if (variant === 2)
|
|
63
|
+
cursor.skip(1, 'operation bool value');
|
|
64
|
+
else if (variant === 3)
|
|
65
|
+
cursor.readString('operation string value');
|
|
66
|
+
else if (variant === 4)
|
|
67
|
+
cursor.skip(32, 'operation address value');
|
|
68
|
+
else
|
|
69
|
+
throw new Error(`Server transaction has unsupported Bounded field value variant: ${variant}`);
|
|
70
|
+
}
|
|
71
|
+
function normalizeOnchainPath(path) {
|
|
72
|
+
let normalized = path.startsWith('/') ? path.slice(1) : path;
|
|
73
|
+
if (normalized.endsWith('*') && normalized.length > 1)
|
|
74
|
+
normalized = normalized.slice(0, -1);
|
|
75
|
+
if (normalized.endsWith('/'))
|
|
76
|
+
normalized = normalized.slice(0, -1);
|
|
77
|
+
return normalized;
|
|
78
|
+
}
|
|
79
|
+
function parseBoundedSetDocumentsInstruction(data, label) {
|
|
80
|
+
if (data.length < 8)
|
|
81
|
+
throw new Error(`${label} has malformed Bounded instruction data`);
|
|
82
|
+
const discriminator = Array.from(data.slice(0, 8)).join(',');
|
|
83
|
+
if (!ALLOWED_BOUNDED_SET_DISCRIMINATORS.has(discriminator)) {
|
|
84
|
+
throw new Error(`${label} contains unsupported Bounded instruction`);
|
|
85
|
+
}
|
|
86
|
+
const isV2 = discriminator === SET_DOCUMENTS_V2_DISCRIMINATOR;
|
|
87
|
+
const cursor = new BorshCursor(data, 8, label);
|
|
88
|
+
const appId = cursor.readString('appId');
|
|
89
|
+
const documentPaths = [];
|
|
90
|
+
const documentCount = cursor.readU32('documents length');
|
|
91
|
+
for (let i = 0; i < documentCount; i++) {
|
|
92
|
+
documentPaths.push(normalizeOnchainPath(cursor.readString('document path')));
|
|
93
|
+
const operationCount = cursor.readU32('operations length');
|
|
94
|
+
for (let j = 0; j < operationCount; j++) {
|
|
95
|
+
cursor.readString('operation key');
|
|
96
|
+
skipBoundedFieldValue(cursor);
|
|
97
|
+
cursor.skip(1, 'operation kind');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const deletePaths = [];
|
|
101
|
+
const deleteCount = cursor.readU32('delete paths length');
|
|
102
|
+
for (let i = 0; i < deleteCount; i++)
|
|
103
|
+
deletePaths.push(normalizeOnchainPath(cursor.readString('delete path')));
|
|
104
|
+
const txDataCount = cursor.readU32('txData length');
|
|
105
|
+
for (let i = 0; i < txDataCount; i++) {
|
|
106
|
+
cursor.readString('txData plugin function key');
|
|
107
|
+
cursor.skipBytes('txData bytes');
|
|
108
|
+
if (isV2)
|
|
109
|
+
cursor.skipBytes('txData raIndices');
|
|
110
|
+
else
|
|
111
|
+
cursor.skip(cursor.readU32('txData raIndices length') * 8, 'txData raIndices');
|
|
112
|
+
}
|
|
113
|
+
const simulate = cursor.readU8('simulate');
|
|
114
|
+
if (simulate !== 0 && simulate !== 1)
|
|
115
|
+
throw new Error(`${label} has malformed Bounded simulate flag`);
|
|
116
|
+
if (!cursor.isAtEnd())
|
|
117
|
+
throw new Error(`${label} has trailing Bounded instruction data`);
|
|
118
|
+
return { appId, documentPaths, deletePaths };
|
|
119
|
+
}
|
|
120
|
+
function assertSamePathSet(label, expectedPaths, actualPaths) {
|
|
121
|
+
const expected = new Set(expectedPaths.map(normalizeOnchainPath).filter(Boolean));
|
|
122
|
+
const actual = new Set(actualPaths.map(normalizeOnchainPath).filter(Boolean));
|
|
123
|
+
const missing = [...expected].filter(path => !actual.has(path));
|
|
124
|
+
const extra = [...actual].filter(path => !expected.has(path));
|
|
125
|
+
if (missing.length || extra.length) {
|
|
126
|
+
const details = [missing.length ? `missing paths: ${missing.join(', ')}` : '', extra.length ? `unexpected paths: ${extra.join(', ')}` : '']
|
|
127
|
+
.filter(Boolean).join('; ');
|
|
128
|
+
throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function deserializeAndValidateServerTransaction(serializedTransaction, VersionedTransactionClass, options) {
|
|
132
|
+
var _a;
|
|
133
|
+
const transaction = VersionedTransactionClass.deserialize(bufferExports.Buffer.from(serializedTransaction, 'base64'));
|
|
134
|
+
const { label, expectedAppId, expectedWritePaths } = options;
|
|
135
|
+
const accountKeys = transaction.message.staticAccountKeys;
|
|
136
|
+
let boundedInstructionCount = 0;
|
|
137
|
+
const actualWritePaths = [];
|
|
138
|
+
for (const ix of transaction.message.compiledInstructions) {
|
|
139
|
+
if (ix.programIdIndex >= accountKeys.length)
|
|
140
|
+
throw new Error(`${label} has program ID in lookup table (not allowed)`);
|
|
141
|
+
const programId = accountKeys[ix.programIdIndex].toBase58();
|
|
142
|
+
if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))
|
|
143
|
+
throw new Error(`${label} contains unauthorized program: ${programId}`);
|
|
144
|
+
const data = ix.data instanceof Uint8Array ? ix.data : bufferExports.Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);
|
|
145
|
+
if (programId === SYSTEM_PROGRAM_ID)
|
|
146
|
+
throw new Error(`${label} contains unauthorized System Program instruction`);
|
|
147
|
+
if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {
|
|
148
|
+
boundedInstructionCount++;
|
|
149
|
+
const parsed = parseBoundedSetDocumentsInstruction(data, label);
|
|
150
|
+
if (parsed.appId !== expectedAppId)
|
|
151
|
+
throw new Error(`${label} Bounded instruction appId does not match configured appId`);
|
|
152
|
+
actualWritePaths.push(...parsed.documentPaths, ...parsed.deletePaths);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
if (boundedInstructionCount !== 1)
|
|
156
|
+
throw new Error(`${label} must contain exactly one Bounded set-documents instruction`);
|
|
157
|
+
assertSamePathSet(label, expectedWritePaths, actualWritePaths);
|
|
158
|
+
return transaction;
|
|
159
|
+
}
|
|
160
|
+
function isHexString(value) {
|
|
161
|
+
if (typeof value !== 'string')
|
|
162
|
+
return false;
|
|
163
|
+
const testValue = value.startsWith('-') ? value.slice(1) : value;
|
|
164
|
+
return /^(0x)?[0-9a-fA-F]+$/.test(testValue);
|
|
165
|
+
}
|
|
166
|
+
async function handleSolanaTransaction(tx, authProvider, options, expectedWritePaths) {
|
|
167
|
+
var _a, _b, _c, _d, _e;
|
|
168
|
+
const chainSdk = await import('@solana/web3.js');
|
|
169
|
+
const { PublicKey, SystemProgram, TransactionInstruction, VersionedTransaction } = chainSdk;
|
|
170
|
+
const solTransactionData = {
|
|
171
|
+
remainingAccounts: tx.remainingAccounts,
|
|
172
|
+
setDocumentData: tx.transactionArgs.setDocumentData,
|
|
173
|
+
deletePaths: tx.transactionArgs.deletePaths,
|
|
174
|
+
idl: tx.idl,
|
|
175
|
+
txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => ({
|
|
176
|
+
pluginFunctionKey: txData.pluginFunctionKey,
|
|
177
|
+
txData: bufferExports.Buffer.from(txData.txData),
|
|
178
|
+
raIndices: (() => {
|
|
179
|
+
const raw = txData.raIndices;
|
|
180
|
+
if (raw == null)
|
|
181
|
+
return bufferExports.Buffer.alloc(0);
|
|
182
|
+
if (bufferExports.Buffer.isBuffer(raw))
|
|
183
|
+
return raw;
|
|
184
|
+
if (raw instanceof Uint8Array)
|
|
185
|
+
return bufferExports.Buffer.from(raw);
|
|
186
|
+
const arrayLike = Array.isArray(raw) ? raw :
|
|
187
|
+
raw && typeof raw === 'object' && Array.isArray(raw.data) ? raw.data :
|
|
188
|
+
(() => { throw new Error(`raIndices has unexpected shape: ${typeof raw}`); })();
|
|
189
|
+
return bufferExports.Buffer.from(arrayLike.map((raIndex) => {
|
|
190
|
+
const value = isHexString(raIndex) ? parseInt(raIndex, 16) : Number(raIndex);
|
|
191
|
+
if (!Number.isInteger(value) || value < 0 || value > 255) {
|
|
192
|
+
throw new Error(`raIndex ${raIndex} is not a valid u8 (must be integer in 0..255)`);
|
|
193
|
+
}
|
|
194
|
+
return value;
|
|
195
|
+
}));
|
|
196
|
+
})(),
|
|
197
|
+
}))) !== null && _b !== void 0 ? _b : [],
|
|
198
|
+
};
|
|
199
|
+
const config = await getConfig();
|
|
200
|
+
if (tx.signedTransaction) {
|
|
201
|
+
deserializeAndValidateServerTransaction(tx.signedTransaction, VersionedTransaction, {
|
|
202
|
+
label: 'Server signedTransaction', expectedAppId: config.appId, expectedWritePaths,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
const solTransaction = {
|
|
206
|
+
appId: config.appId,
|
|
207
|
+
txArgs: [solTransactionData],
|
|
208
|
+
lutKey: (_c = tx.lutAddress) !== null && _c !== void 0 ? _c : null,
|
|
209
|
+
additionalLutAddresses: tx.additionalLutAddresses,
|
|
210
|
+
network: tx.network,
|
|
211
|
+
preInstructions: (_e = (_d = tx.preInstructions) === null || _d === void 0 ? void 0 : _d.map((ix, index) => {
|
|
212
|
+
var _a;
|
|
213
|
+
const keys = (_a = ix.keys) === null || _a === void 0 ? void 0 : _a.map((key) => ({ pubkey: new PublicKey(key.pubkey), isSigner: key.isSigner, isWritable: key.isWritable }));
|
|
214
|
+
const programId = ix.programId === SYSTEM_PROGRAM_ID ? SystemProgram.programId : new PublicKey(ix.programId);
|
|
215
|
+
const instruction = new TransactionInstruction({ keys, programId, data: bufferExports.Buffer.from(ix.data) });
|
|
216
|
+
if (instruction.programId.equals(SystemProgram.programId)) {
|
|
217
|
+
throw new Error(`Server preInstruction[${index}] contains unauthorized System Program preInstruction`);
|
|
218
|
+
}
|
|
219
|
+
return instruction;
|
|
220
|
+
})) !== null && _e !== void 0 ? _e : [],
|
|
221
|
+
signedTransaction: tx.signedTransaction,
|
|
222
|
+
};
|
|
223
|
+
return authProvider.runTransaction(undefined, solTransaction, options);
|
|
224
|
+
}
|
|
225
|
+
async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {
|
|
226
|
+
var _a, _b, _c;
|
|
227
|
+
const { Connection, VersionedTransaction } = await import('@solana/web3.js');
|
|
228
|
+
const config = await getConfig();
|
|
229
|
+
const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, VersionedTransaction, {
|
|
230
|
+
label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,
|
|
231
|
+
});
|
|
232
|
+
const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;
|
|
233
|
+
const rpcUrl = (_a = config.rpcUrl) === null || _a === void 0 ? void 0 : _a.trim();
|
|
234
|
+
if (shouldSubmit && !rpcUrl)
|
|
235
|
+
throw new Error(`Pre-built Solana transaction submission requires init({ rpcUrl }) for ${tx.network}`);
|
|
236
|
+
const signedTx = await authProvider.signTransaction(transaction);
|
|
237
|
+
const rawTx = signedTx.serialize();
|
|
238
|
+
if (!shouldSubmit) {
|
|
239
|
+
return { transactionSignature: '', signedTransaction: bufferExports.Buffer.from(rawTx).toString('base64'), blockNumber: 0, gasUsed: '0' };
|
|
240
|
+
}
|
|
241
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
242
|
+
const signature = await connection.sendRawTransaction(rawTx, { skipPreflight: false, maxRetries: 3 });
|
|
243
|
+
const confirmation = await connection.confirmTransaction({
|
|
244
|
+
signature, blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight,
|
|
245
|
+
}, 'confirmed');
|
|
246
|
+
return {
|
|
247
|
+
transactionSignature: signature,
|
|
248
|
+
signedTransaction: bufferExports.Buffer.from(rawTx).toString('base64'),
|
|
249
|
+
blockNumber: (_c = (_b = confirmation.context) === null || _b === void 0 ? void 0 : _b.slot) !== null && _c !== void 0 ? _c : 0,
|
|
250
|
+
gasUsed: '0',
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
export { handlePreBuiltTransaction, handleSolanaTransaction };
|
|
255
|
+
//# sourceMappingURL=solana-operations-4MGSdS1U.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana-operations-4MGSdS1U.mjs","sources":["../.rollup-tmp/client/solana-operations.js"],"sourcesContent":["import { Buffer } from 'buffer';\nimport { getConfig } from './config';\nconst BOUNDED_PROGRAM_MAINNET = ['poof', '4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp'].join('');\nconst BOUNDED_PROGRAM_DEVNET = ['taro', '6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRu'].join('');\nconst COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';\nconst SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';\nconst ALLOWED_SERVER_TX_PROGRAMS = new Set([\n BOUNDED_PROGRAM_MAINNET,\n BOUNDED_PROGRAM_DEVNET,\n COMPUTE_BUDGET_PROGRAM,\n SYSTEM_PROGRAM_ID,\n]);\nconst SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';\nconst SET_DOCUMENTS_V2_DISCRIMINATOR = '22,236,242,185,145,61,26,39';\nconst ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([\n SET_DOCUMENTS_DISCRIMINATOR,\n SET_DOCUMENTS_V2_DISCRIMINATOR,\n]);\nclass BorshCursor {\n constructor(data, offset, label) {\n this.data = data;\n this.offset = offset;\n this.label = label;\n }\n requireBytes(length, field) {\n if (this.offset + length > this.data.length) {\n throw new Error(`${this.label} has malformed Bounded instruction data while reading ${field}`);\n }\n }\n readU8(field) { this.requireBytes(1, field); return this.data[this.offset++]; }\n readU32(field) {\n this.requireBytes(4, field);\n const value = this.data[this.offset] | (this.data[this.offset + 1] << 8) |\n (this.data[this.offset + 2] << 16) | (this.data[this.offset + 3] << 24);\n this.offset += 4;\n return value >>> 0;\n }\n skip(length, field) { this.requireBytes(length, field); this.offset += length; }\n readString(field) {\n const length = this.readU32(`${field} length`);\n this.requireBytes(length, field);\n const raw = this.data.slice(this.offset, this.offset + length);\n this.offset += length;\n return Buffer.from(raw).toString('utf8');\n }\n skipBytes(field) { this.skip(this.readU32(`${field} length`), field); }\n isAtEnd() { return this.offset === this.data.length; }\n}\nfunction skipBoundedFieldValue(cursor) {\n const option = cursor.readU8('operation value option');\n if (option === 0)\n return;\n if (option !== 1)\n throw new Error('Server transaction has malformed Bounded field value option');\n const variant = cursor.readU8('operation value variant');\n if (variant === 0 || variant === 1)\n cursor.skip(8, 'operation numeric value');\n else if (variant === 2)\n cursor.skip(1, 'operation bool value');\n else if (variant === 3)\n cursor.readString('operation string value');\n else if (variant === 4)\n cursor.skip(32, 'operation address value');\n else\n throw new Error(`Server transaction has unsupported Bounded field value variant: ${variant}`);\n}\nfunction normalizeOnchainPath(path) {\n let normalized = path.startsWith('/') ? path.slice(1) : path;\n if (normalized.endsWith('*') && normalized.length > 1)\n normalized = normalized.slice(0, -1);\n if (normalized.endsWith('/'))\n normalized = normalized.slice(0, -1);\n return normalized;\n}\nfunction parseBoundedSetDocumentsInstruction(data, label) {\n if (data.length < 8)\n throw new Error(`${label} has malformed Bounded instruction data`);\n const discriminator = Array.from(data.slice(0, 8)).join(',');\n if (!ALLOWED_BOUNDED_SET_DISCRIMINATORS.has(discriminator)) {\n throw new Error(`${label} contains unsupported Bounded instruction`);\n }\n const isV2 = discriminator === SET_DOCUMENTS_V2_DISCRIMINATOR;\n const cursor = new BorshCursor(data, 8, label);\n const appId = cursor.readString('appId');\n const documentPaths = [];\n const documentCount = cursor.readU32('documents length');\n for (let i = 0; i < documentCount; i++) {\n documentPaths.push(normalizeOnchainPath(cursor.readString('document path')));\n const operationCount = cursor.readU32('operations length');\n for (let j = 0; j < operationCount; j++) {\n cursor.readString('operation key');\n skipBoundedFieldValue(cursor);\n cursor.skip(1, 'operation kind');\n }\n }\n const deletePaths = [];\n const deleteCount = cursor.readU32('delete paths length');\n for (let i = 0; i < deleteCount; i++)\n deletePaths.push(normalizeOnchainPath(cursor.readString('delete path')));\n const txDataCount = cursor.readU32('txData length');\n for (let i = 0; i < txDataCount; i++) {\n cursor.readString('txData plugin function key');\n cursor.skipBytes('txData bytes');\n if (isV2)\n cursor.skipBytes('txData raIndices');\n else\n cursor.skip(cursor.readU32('txData raIndices length') * 8, 'txData raIndices');\n }\n const simulate = cursor.readU8('simulate');\n if (simulate !== 0 && simulate !== 1)\n throw new Error(`${label} has malformed Bounded simulate flag`);\n if (!cursor.isAtEnd())\n throw new Error(`${label} has trailing Bounded instruction data`);\n return { appId, documentPaths, deletePaths };\n}\nfunction assertSamePathSet(label, expectedPaths, actualPaths) {\n const expected = new Set(expectedPaths.map(normalizeOnchainPath).filter(Boolean));\n const actual = new Set(actualPaths.map(normalizeOnchainPath).filter(Boolean));\n const missing = [...expected].filter(path => !actual.has(path));\n const extra = [...actual].filter(path => !expected.has(path));\n if (missing.length || extra.length) {\n const details = [missing.length ? `missing paths: ${missing.join(', ')}` : '', extra.length ? `unexpected paths: ${extra.join(', ')}` : '']\n .filter(Boolean).join('; ');\n throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);\n }\n}\nfunction deserializeAndValidateServerTransaction(serializedTransaction, VersionedTransactionClass, options) {\n var _a;\n const transaction = VersionedTransactionClass.deserialize(Buffer.from(serializedTransaction, 'base64'));\n const { label, expectedAppId, expectedWritePaths } = options;\n const accountKeys = transaction.message.staticAccountKeys;\n let boundedInstructionCount = 0;\n const actualWritePaths = [];\n for (const ix of transaction.message.compiledInstructions) {\n if (ix.programIdIndex >= accountKeys.length)\n throw new Error(`${label} has program ID in lookup table (not allowed)`);\n const programId = accountKeys[ix.programIdIndex].toBase58();\n if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))\n throw new Error(`${label} contains unauthorized program: ${programId}`);\n const data = ix.data instanceof Uint8Array ? ix.data : Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);\n if (programId === SYSTEM_PROGRAM_ID)\n throw new Error(`${label} contains unauthorized System Program instruction`);\n if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {\n boundedInstructionCount++;\n const parsed = parseBoundedSetDocumentsInstruction(data, label);\n if (parsed.appId !== expectedAppId)\n throw new Error(`${label} Bounded instruction appId does not match configured appId`);\n actualWritePaths.push(...parsed.documentPaths, ...parsed.deletePaths);\n }\n }\n if (boundedInstructionCount !== 1)\n throw new Error(`${label} must contain exactly one Bounded set-documents instruction`);\n assertSamePathSet(label, expectedWritePaths, actualWritePaths);\n return transaction;\n}\nfunction isHexString(value) {\n if (typeof value !== 'string')\n return false;\n const testValue = value.startsWith('-') ? value.slice(1) : value;\n return /^(0x)?[0-9a-fA-F]+$/.test(testValue);\n}\nexport async function handleSolanaTransaction(tx, authProvider, options, expectedWritePaths) {\n var _a, _b, _c, _d, _e;\n const chainSdk = await import(\"@solana/web3.js\");\n const { PublicKey, SystemProgram, TransactionInstruction, VersionedTransaction } = chainSdk;\n const solTransactionData = {\n remainingAccounts: tx.remainingAccounts,\n setDocumentData: tx.transactionArgs.setDocumentData,\n deletePaths: tx.transactionArgs.deletePaths,\n idl: tx.idl,\n txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => ({\n pluginFunctionKey: txData.pluginFunctionKey,\n txData: Buffer.from(txData.txData),\n raIndices: (() => {\n const raw = txData.raIndices;\n if (raw == null)\n return Buffer.alloc(0);\n if (Buffer.isBuffer(raw))\n return raw;\n if (raw instanceof Uint8Array)\n return Buffer.from(raw);\n const arrayLike = Array.isArray(raw) ? raw :\n raw && typeof raw === 'object' && Array.isArray(raw.data) ? raw.data :\n (() => { throw new Error(`raIndices has unexpected shape: ${typeof raw}`); })();\n return Buffer.from(arrayLike.map((raIndex) => {\n const value = isHexString(raIndex) ? parseInt(raIndex, 16) : Number(raIndex);\n if (!Number.isInteger(value) || value < 0 || value > 255) {\n throw new Error(`raIndex ${raIndex} is not a valid u8 (must be integer in 0..255)`);\n }\n return value;\n }));\n })(),\n }))) !== null && _b !== void 0 ? _b : [],\n };\n const config = await getConfig();\n if (tx.signedTransaction) {\n deserializeAndValidateServerTransaction(tx.signedTransaction, VersionedTransaction, {\n label: 'Server signedTransaction', expectedAppId: config.appId, expectedWritePaths,\n });\n }\n const solTransaction = {\n appId: config.appId,\n txArgs: [solTransactionData],\n lutKey: (_c = tx.lutAddress) !== null && _c !== void 0 ? _c : null,\n additionalLutAddresses: tx.additionalLutAddresses,\n network: tx.network,\n preInstructions: (_e = (_d = tx.preInstructions) === null || _d === void 0 ? void 0 : _d.map((ix, index) => {\n var _a;\n const keys = (_a = ix.keys) === null || _a === void 0 ? void 0 : _a.map((key) => ({ pubkey: new PublicKey(key.pubkey), isSigner: key.isSigner, isWritable: key.isWritable }));\n const programId = ix.programId === SYSTEM_PROGRAM_ID ? SystemProgram.programId : new PublicKey(ix.programId);\n const instruction = new TransactionInstruction({ keys, programId, data: Buffer.from(ix.data) });\n if (instruction.programId.equals(SystemProgram.programId)) {\n throw new Error(`Server preInstruction[${index}] contains unauthorized System Program preInstruction`);\n }\n return instruction;\n })) !== null && _e !== void 0 ? _e : [],\n signedTransaction: tx.signedTransaction,\n };\n return authProvider.runTransaction(undefined, solTransaction, options);\n}\nexport async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {\n var _a, _b, _c;\n const { Connection, VersionedTransaction } = await import(\"@solana/web3.js\");\n const config = await getConfig();\n const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, VersionedTransaction, {\n label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,\n });\n const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;\n const rpcUrl = (_a = config.rpcUrl) === null || _a === void 0 ? void 0 : _a.trim();\n if (shouldSubmit && !rpcUrl)\n throw new Error(`Pre-built Solana transaction submission requires init({ rpcUrl }) for ${tx.network}`);\n const signedTx = await authProvider.signTransaction(transaction);\n const rawTx = signedTx.serialize();\n if (!shouldSubmit) {\n return { transactionSignature: '', signedTransaction: Buffer.from(rawTx).toString('base64'), blockNumber: 0, gasUsed: '0' };\n }\n const connection = new Connection(rpcUrl, 'confirmed');\n const signature = await connection.sendRawTransaction(rawTx, { skipPreflight: false, maxRetries: 3 });\n const confirmation = await connection.confirmTransaction({\n signature, blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight,\n }, 'confirmed');\n return {\n transactionSignature: signature,\n signedTransaction: Buffer.from(rawTx).toString('base64'),\n blockNumber: (_c = (_b = confirmation.context) === null || _b === void 0 ? void 0 : _b.slot) !== null && _c !== void 0 ? _c : 0,\n gasUsed: '0',\n };\n}\n"],"names":["Buffer"],"mappings":";;;;;;AAEA,MAAM,uBAAuB,GAAG,CAAC,MAAM,EAAE,yCAAyC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAC5F,MAAM,sBAAsB,GAAG,CAAC,MAAM,EAAE,yCAAyC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;AAC3F,MAAM,sBAAsB,GAAG,6CAA6C;AAC5E,MAAM,iBAAiB,GAAG,kCA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U,CAAC,MAAM,EAAE,WAAW,CAAC;AAC1D,IAAI,MAAM,SAAS,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;AACzG,IAAI,MAAM,YAAY,GAAG,MAAM,UAAU,CAAC,kBAAkB,CAAC;AAC7D,QAAQ,SAAS,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,oBAAoB,EAAE,EAAE,CAAC,oBAAoB;AACzF,KAAK,EAAE,WAAW,CAAC;AACnB,IAAI,OAAO;AACX,QAAQ,oBAAoB,EAAE,SAAS;AACvC,QAAQ,iBAAiB,EAAEA,oBAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC;AAChE,QAAQ,WAAW,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,GAAG,YAAY,CAAC,OAAO,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,MAAM,GAAG,EAAE,CAAC,IAAI,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,EAAE,GAAG,CAAC;AACvI,QAAQ,OAAO,EAAE,GAAG;AACpB,KAAK;AACL;;;;"}
|
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var index = require('./index-Kn7IIh5d.js');
|
|
4
|
+
require('axios');
|
|
5
|
+
require('tweetnacl');
|
|
6
|
+
require('reconnecting-websocket');
|
|
7
|
+
require('bn.js');
|
|
8
|
+
|
|
9
|
+
const BOUNDED_PROGRAM_MAINNET = ['poof', '4b5pk1L9tmThvBmaABjcyjfhFGbMbQP5BXk2QZp'].join('');
|
|
10
|
+
const BOUNDED_PROGRAM_DEVNET = ['taro', '6CvKqwrYrDc16ufYgzQ2NZcyyVKStffbtudrhRu'].join('');
|
|
11
|
+
const COMPUTE_BUDGET_PROGRAM = 'ComputeBudget111111111111111111111111111111';
|
|
12
|
+
const SYSTEM_PROGRAM_ID = '11111111111111111111111111111111';
|
|
13
|
+
const ALLOWED_SERVER_TX_PROGRAMS = new Set([
|
|
14
|
+
BOUNDED_PROGRAM_MAINNET,
|
|
15
|
+
BOUNDED_PROGRAM_DEVNET,
|
|
16
|
+
COMPUTE_BUDGET_PROGRAM,
|
|
17
|
+
SYSTEM_PROGRAM_ID,
|
|
18
|
+
]);
|
|
19
|
+
const SET_DOCUMENTS_DISCRIMINATOR = '79,46,72,73,24,79,66,245';
|
|
20
|
+
const SET_DOCUMENTS_V2_DISCRIMINATOR = '22,236,242,185,145,61,26,39';
|
|
21
|
+
const ALLOWED_BOUNDED_SET_DISCRIMINATORS = new Set([
|
|
22
|
+
SET_DOCUMENTS_DISCRIMINATOR,
|
|
23
|
+
SET_DOCUMENTS_V2_DISCRIMINATOR,
|
|
24
|
+
]);
|
|
25
|
+
class BorshCursor {
|
|
26
|
+
constructor(data, offset, label) {
|
|
27
|
+
this.data = data;
|
|
28
|
+
this.offset = offset;
|
|
29
|
+
this.label = label;
|
|
30
|
+
}
|
|
31
|
+
requireBytes(length, field) {
|
|
32
|
+
if (this.offset + length > this.data.length) {
|
|
33
|
+
throw new Error(`${this.label} has malformed Bounded instruction data while reading ${field}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
readU8(field) { this.requireBytes(1, field); return this.data[this.offset++]; }
|
|
37
|
+
readU32(field) {
|
|
38
|
+
this.requireBytes(4, field);
|
|
39
|
+
const value = this.data[this.offset] | (this.data[this.offset + 1] << 8) |
|
|
40
|
+
(this.data[this.offset + 2] << 16) | (this.data[this.offset + 3] << 24);
|
|
41
|
+
this.offset += 4;
|
|
42
|
+
return value >>> 0;
|
|
43
|
+
}
|
|
44
|
+
skip(length, field) { this.requireBytes(length, field); this.offset += length; }
|
|
45
|
+
readString(field) {
|
|
46
|
+
const length = this.readU32(`${field} length`);
|
|
47
|
+
this.requireBytes(length, field);
|
|
48
|
+
const raw = this.data.slice(this.offset, this.offset + length);
|
|
49
|
+
this.offset += length;
|
|
50
|
+
return index.bufferExports.Buffer.from(raw).toString('utf8');
|
|
51
|
+
}
|
|
52
|
+
skipBytes(field) { this.skip(this.readU32(`${field} length`), field); }
|
|
53
|
+
isAtEnd() { return this.offset === this.data.length; }
|
|
54
|
+
}
|
|
55
|
+
function skipBoundedFieldValue(cursor) {
|
|
56
|
+
const option = cursor.readU8('operation value option');
|
|
57
|
+
if (option === 0)
|
|
58
|
+
return;
|
|
59
|
+
if (option !== 1)
|
|
60
|
+
throw new Error('Server transaction has malformed Bounded field value option');
|
|
61
|
+
const variant = cursor.readU8('operation value variant');
|
|
62
|
+
if (variant === 0 || variant === 1)
|
|
63
|
+
cursor.skip(8, 'operation numeric value');
|
|
64
|
+
else if (variant === 2)
|
|
65
|
+
cursor.skip(1, 'operation bool value');
|
|
66
|
+
else if (variant === 3)
|
|
67
|
+
cursor.readString('operation string value');
|
|
68
|
+
else if (variant === 4)
|
|
69
|
+
cursor.skip(32, 'operation address value');
|
|
70
|
+
else
|
|
71
|
+
throw new Error(`Server transaction has unsupported Bounded field value variant: ${variant}`);
|
|
72
|
+
}
|
|
73
|
+
function normalizeOnchainPath(path) {
|
|
74
|
+
let normalized = path.startsWith('/') ? path.slice(1) : path;
|
|
75
|
+
if (normalized.endsWith('*') && normalized.length > 1)
|
|
76
|
+
normalized = normalized.slice(0, -1);
|
|
77
|
+
if (normalized.endsWith('/'))
|
|
78
|
+
normalized = normalized.slice(0, -1);
|
|
79
|
+
return normalized;
|
|
80
|
+
}
|
|
81
|
+
function parseBoundedSetDocumentsInstruction(data, label) {
|
|
82
|
+
if (data.length < 8)
|
|
83
|
+
throw new Error(`${label} has malformed Bounded instruction data`);
|
|
84
|
+
const discriminator = Array.from(data.slice(0, 8)).join(',');
|
|
85
|
+
if (!ALLOWED_BOUNDED_SET_DISCRIMINATORS.has(discriminator)) {
|
|
86
|
+
throw new Error(`${label} contains unsupported Bounded instruction`);
|
|
87
|
+
}
|
|
88
|
+
const isV2 = discriminator === SET_DOCUMENTS_V2_DISCRIMINATOR;
|
|
89
|
+
const cursor = new BorshCursor(data, 8, label);
|
|
90
|
+
const appId = cursor.readString('appId');
|
|
91
|
+
const documentPaths = [];
|
|
92
|
+
const documentCount = cursor.readU32('documents length');
|
|
93
|
+
for (let i = 0; i < documentCount; i++) {
|
|
94
|
+
documentPaths.push(normalizeOnchainPath(cursor.readString('document path')));
|
|
95
|
+
const operationCount = cursor.readU32('operations length');
|
|
96
|
+
for (let j = 0; j < operationCount; j++) {
|
|
97
|
+
cursor.readString('operation key');
|
|
98
|
+
skipBoundedFieldValue(cursor);
|
|
99
|
+
cursor.skip(1, 'operation kind');
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const deletePaths = [];
|
|
103
|
+
const deleteCount = cursor.readU32('delete paths length');
|
|
104
|
+
for (let i = 0; i < deleteCount; i++)
|
|
105
|
+
deletePaths.push(normalizeOnchainPath(cursor.readString('delete path')));
|
|
106
|
+
const txDataCount = cursor.readU32('txData length');
|
|
107
|
+
for (let i = 0; i < txDataCount; i++) {
|
|
108
|
+
cursor.readString('txData plugin function key');
|
|
109
|
+
cursor.skipBytes('txData bytes');
|
|
110
|
+
if (isV2)
|
|
111
|
+
cursor.skipBytes('txData raIndices');
|
|
112
|
+
else
|
|
113
|
+
cursor.skip(cursor.readU32('txData raIndices length') * 8, 'txData raIndices');
|
|
114
|
+
}
|
|
115
|
+
const simulate = cursor.readU8('simulate');
|
|
116
|
+
if (simulate !== 0 && simulate !== 1)
|
|
117
|
+
throw new Error(`${label} has malformed Bounded simulate flag`);
|
|
118
|
+
if (!cursor.isAtEnd())
|
|
119
|
+
throw new Error(`${label} has trailing Bounded instruction data`);
|
|
120
|
+
return { appId, documentPaths, deletePaths };
|
|
121
|
+
}
|
|
122
|
+
function assertSamePathSet(label, expectedPaths, actualPaths) {
|
|
123
|
+
const expected = new Set(expectedPaths.map(normalizeOnchainPath).filter(Boolean));
|
|
124
|
+
const actual = new Set(actualPaths.map(normalizeOnchainPath).filter(Boolean));
|
|
125
|
+
const missing = [...expected].filter(path => !actual.has(path));
|
|
126
|
+
const extra = [...actual].filter(path => !expected.has(path));
|
|
127
|
+
if (missing.length || extra.length) {
|
|
128
|
+
const details = [missing.length ? `missing paths: ${missing.join(', ')}` : '', extra.length ? `unexpected paths: ${extra.join(', ')}` : '']
|
|
129
|
+
.filter(Boolean).join('; ');
|
|
130
|
+
throw new Error(`${label} Bounded instruction paths do not match requested write paths (${details})`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
function deserializeAndValidateServerTransaction(serializedTransaction, VersionedTransactionClass, options) {
|
|
134
|
+
var _a;
|
|
135
|
+
const transaction = VersionedTransactionClass.deserialize(index.bufferExports.Buffer.from(serializedTransaction, 'base64'));
|
|
136
|
+
const { label, expectedAppId, expectedWritePaths } = options;
|
|
137
|
+
const accountKeys = transaction.message.staticAccountKeys;
|
|
138
|
+
let boundedInstructionCount = 0;
|
|
139
|
+
const actualWritePaths = [];
|
|
140
|
+
for (const ix of transaction.message.compiledInstructions) {
|
|
141
|
+
if (ix.programIdIndex >= accountKeys.length)
|
|
142
|
+
throw new Error(`${label} has program ID in lookup table (not allowed)`);
|
|
143
|
+
const programId = accountKeys[ix.programIdIndex].toBase58();
|
|
144
|
+
if (!ALLOWED_SERVER_TX_PROGRAMS.has(programId))
|
|
145
|
+
throw new Error(`${label} contains unauthorized program: ${programId}`);
|
|
146
|
+
const data = ix.data instanceof Uint8Array ? ix.data : index.bufferExports.Buffer.from((_a = ix.data) !== null && _a !== void 0 ? _a : []);
|
|
147
|
+
if (programId === SYSTEM_PROGRAM_ID)
|
|
148
|
+
throw new Error(`${label} contains unauthorized System Program instruction`);
|
|
149
|
+
if (programId === BOUNDED_PROGRAM_MAINNET || programId === BOUNDED_PROGRAM_DEVNET) {
|
|
150
|
+
boundedInstructionCount++;
|
|
151
|
+
const parsed = parseBoundedSetDocumentsInstruction(data, label);
|
|
152
|
+
if (parsed.appId !== expectedAppId)
|
|
153
|
+
throw new Error(`${label} Bounded instruction appId does not match configured appId`);
|
|
154
|
+
actualWritePaths.push(...parsed.documentPaths, ...parsed.deletePaths);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (boundedInstructionCount !== 1)
|
|
158
|
+
throw new Error(`${label} must contain exactly one Bounded set-documents instruction`);
|
|
159
|
+
assertSamePathSet(label, expectedWritePaths, actualWritePaths);
|
|
160
|
+
return transaction;
|
|
161
|
+
}
|
|
162
|
+
function isHexString(value) {
|
|
163
|
+
if (typeof value !== 'string')
|
|
164
|
+
return false;
|
|
165
|
+
const testValue = value.startsWith('-') ? value.slice(1) : value;
|
|
166
|
+
return /^(0x)?[0-9a-fA-F]+$/.test(testValue);
|
|
167
|
+
}
|
|
168
|
+
async function handleSolanaTransaction(tx, authProvider, options, expectedWritePaths) {
|
|
169
|
+
var _a, _b, _c, _d, _e;
|
|
170
|
+
const chainSdk = await import('@solana/web3.js');
|
|
171
|
+
const { PublicKey, SystemProgram, TransactionInstruction, VersionedTransaction } = chainSdk;
|
|
172
|
+
const solTransactionData = {
|
|
173
|
+
remainingAccounts: tx.remainingAccounts,
|
|
174
|
+
setDocumentData: tx.transactionArgs.setDocumentData,
|
|
175
|
+
deletePaths: tx.transactionArgs.deletePaths,
|
|
176
|
+
idl: tx.idl,
|
|
177
|
+
txData: (_b = (_a = tx.txData) === null || _a === void 0 ? void 0 : _a.map((txData) => ({
|
|
178
|
+
pluginFunctionKey: txData.pluginFunctionKey,
|
|
179
|
+
txData: index.bufferExports.Buffer.from(txData.txData),
|
|
180
|
+
raIndices: (() => {
|
|
181
|
+
const raw = txData.raIndices;
|
|
182
|
+
if (raw == null)
|
|
183
|
+
return index.bufferExports.Buffer.alloc(0);
|
|
184
|
+
if (index.bufferExports.Buffer.isBuffer(raw))
|
|
185
|
+
return raw;
|
|
186
|
+
if (raw instanceof Uint8Array)
|
|
187
|
+
return index.bufferExports.Buffer.from(raw);
|
|
188
|
+
const arrayLike = Array.isArray(raw) ? raw :
|
|
189
|
+
raw && typeof raw === 'object' && Array.isArray(raw.data) ? raw.data :
|
|
190
|
+
(() => { throw new Error(`raIndices has unexpected shape: ${typeof raw}`); })();
|
|
191
|
+
return index.bufferExports.Buffer.from(arrayLike.map((raIndex) => {
|
|
192
|
+
const value = isHexString(raIndex) ? parseInt(raIndex, 16) : Number(raIndex);
|
|
193
|
+
if (!Number.isInteger(value) || value < 0 || value > 255) {
|
|
194
|
+
throw new Error(`raIndex ${raIndex} is not a valid u8 (must be integer in 0..255)`);
|
|
195
|
+
}
|
|
196
|
+
return value;
|
|
197
|
+
}));
|
|
198
|
+
})(),
|
|
199
|
+
}))) !== null && _b !== void 0 ? _b : [],
|
|
200
|
+
};
|
|
201
|
+
const config = await index.getConfig();
|
|
202
|
+
if (tx.signedTransaction) {
|
|
203
|
+
deserializeAndValidateServerTransaction(tx.signedTransaction, VersionedTransaction, {
|
|
204
|
+
label: 'Server signedTransaction', expectedAppId: config.appId, expectedWritePaths,
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
const solTransaction = {
|
|
208
|
+
appId: config.appId,
|
|
209
|
+
txArgs: [solTransactionData],
|
|
210
|
+
lutKey: (_c = tx.lutAddress) !== null && _c !== void 0 ? _c : null,
|
|
211
|
+
additionalLutAddresses: tx.additionalLutAddresses,
|
|
212
|
+
network: tx.network,
|
|
213
|
+
preInstructions: (_e = (_d = tx.preInstructions) === null || _d === void 0 ? void 0 : _d.map((ix, index$1) => {
|
|
214
|
+
var _a;
|
|
215
|
+
const keys = (_a = ix.keys) === null || _a === void 0 ? void 0 : _a.map((key) => ({ pubkey: new PublicKey(key.pubkey), isSigner: key.isSigner, isWritable: key.isWritable }));
|
|
216
|
+
const programId = ix.programId === SYSTEM_PROGRAM_ID ? SystemProgram.programId : new PublicKey(ix.programId);
|
|
217
|
+
const instruction = new TransactionInstruction({ keys, programId, data: index.bufferExports.Buffer.from(ix.data) });
|
|
218
|
+
if (instruction.programId.equals(SystemProgram.programId)) {
|
|
219
|
+
throw new Error(`Server preInstruction[${index$1}] contains unauthorized System Program preInstruction`);
|
|
220
|
+
}
|
|
221
|
+
return instruction;
|
|
222
|
+
})) !== null && _e !== void 0 ? _e : [],
|
|
223
|
+
signedTransaction: tx.signedTransaction,
|
|
224
|
+
};
|
|
225
|
+
return authProvider.runTransaction(undefined, solTransaction, options);
|
|
226
|
+
}
|
|
227
|
+
async function handlePreBuiltTransaction(tx, authProvider, options, expectedWritePaths) {
|
|
228
|
+
var _a, _b, _c;
|
|
229
|
+
const { Connection, VersionedTransaction } = await import('@solana/web3.js');
|
|
230
|
+
const config = await index.getConfig();
|
|
231
|
+
const transaction = deserializeAndValidateServerTransaction(tx.serializedTransaction, VersionedTransaction, {
|
|
232
|
+
label: 'Pre-built transaction', expectedAppId: config.appId, expectedWritePaths,
|
|
233
|
+
});
|
|
234
|
+
const shouldSubmit = (options === null || options === void 0 ? void 0 : options.shouldSubmitTx) !== false;
|
|
235
|
+
const rpcUrl = (_a = config.rpcUrl) === null || _a === void 0 ? void 0 : _a.trim();
|
|
236
|
+
if (shouldSubmit && !rpcUrl)
|
|
237
|
+
throw new Error(`Pre-built Solana transaction submission requires init({ rpcUrl }) for ${tx.network}`);
|
|
238
|
+
const signedTx = await authProvider.signTransaction(transaction);
|
|
239
|
+
const rawTx = signedTx.serialize();
|
|
240
|
+
if (!shouldSubmit) {
|
|
241
|
+
return { transactionSignature: '', signedTransaction: index.bufferExports.Buffer.from(rawTx).toString('base64'), blockNumber: 0, gasUsed: '0' };
|
|
242
|
+
}
|
|
243
|
+
const connection = new Connection(rpcUrl, 'confirmed');
|
|
244
|
+
const signature = await connection.sendRawTransaction(rawTx, { skipPreflight: false, maxRetries: 3 });
|
|
245
|
+
const confirmation = await connection.confirmTransaction({
|
|
246
|
+
signature, blockhash: tx.blockhash, lastValidBlockHeight: tx.lastValidBlockHeight,
|
|
247
|
+
}, 'confirmed');
|
|
248
|
+
return {
|
|
249
|
+
transactionSignature: signature,
|
|
250
|
+
signedTransaction: index.bufferExports.Buffer.from(rawTx).toString('base64'),
|
|
251
|
+
blockNumber: (_c = (_b = confirmation.context) === null || _b === void 0 ? void 0 : _b.slot) !== null && _c !== void 0 ? _c : 0,
|
|
252
|
+
gasUsed: '0',
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
exports.handlePreBuiltTransaction = handlePreBuiltTransaction;
|
|
257
|
+
exports.handleSolanaTransaction = handleSolanaTransaction;
|
|
258
|
+
//# sourceMappingURL=solana-operations-C_aie1aF.js.map
|