@0block.io/sdk 0.2.0 → 0.3.0

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.d.ts CHANGED
@@ -9,7 +9,7 @@ export { buildPumpfunSwapInstruction, decodeSwapData, randomOrderId, resolveFeeM
9
9
  export { buildTipInstruction, maskTipAccountInTables } from "./tip.js";
10
10
  export { buildComputeBudgetInstructions } from "./computeBudget.js";
11
11
  export { createAtaIdempotentInstruction, syncNativeInstruction, closeAccountInstruction, wrapSolInstructions, unwrapWsolInstruction, } from "./wsol.js";
12
- export { buildPumpfunSwapTransaction, serializeWithSignatures, toLookupTableAccount, } from "./transaction.js";
12
+ export { buildPumpfunSwapTransaction, serializeWithSignatures, buildSubmitTemplate, toLookupTableAccount, type SubmitTemplate, } from "./transaction.js";
13
13
  export { buildLookupTableAddresses, buildInitLookupTableInstructions, type InitLookupTableResult, } from "./alt.js";
14
14
  export { applyPreset, slippagePctToBps, solToLamports, type PresetSwapInputs, type PresetSwapOutputs, } from "./presets.js";
15
15
  export { decodeSwapResultEvents } from "./events.js";
package/dist/index.js CHANGED
@@ -22,7 +22,7 @@ export { buildPumpfunSwapInstruction, decodeSwapData, randomOrderId, resolveFeeM
22
22
  export { buildTipInstruction, maskTipAccountInTables } from "./tip.js";
23
23
  export { buildComputeBudgetInstructions } from "./computeBudget.js";
24
24
  export { createAtaIdempotentInstruction, syncNativeInstruction, closeAccountInstruction, wrapSolInstructions, unwrapWsolInstruction, } from "./wsol.js";
25
- export { buildPumpfunSwapTransaction, serializeWithSignatures, toLookupTableAccount, } from "./transaction.js";
25
+ export { buildPumpfunSwapTransaction, serializeWithSignatures, buildSubmitTemplate, toLookupTableAccount, } from "./transaction.js";
26
26
  export { buildLookupTableAddresses, buildInitLookupTableInstructions, } from "./alt.js";
27
27
  export { applyPreset, slippagePctToBps, solToLamports, } from "./presets.js";
28
28
  export { decodeSwapResultEvents } from "./events.js";
@@ -17,3 +17,34 @@ export declare function buildPumpfunSwapTransaction(params: BuildPumpfunSwapPara
17
17
  * requiredSigners order and return the wire-ready bytes.
18
18
  */
19
19
  export declare function serializeWithSignatures(result: BuildSwapResult, signatures: Uint8Array[]): Uint8Array;
20
+ /**
21
+ * A submit template for a signer-and-submitter that is CHAIN-AGNOSTIC (e.g.
22
+ * sigcore): it signs `payload` and splices the raw signature into
23
+ * `wireTemplate` at `signatureOffset`, then broadcasts the result — with no
24
+ * knowledge of Solana's transaction format.
25
+ *
26
+ * The layout works because a Solana v0 transaction is
27
+ * `[compact-u16 sig count][sig0..sigN-1][message]`, and the bytes that get
28
+ * signed are exactly the `[message]` tail. `wireTemplate` is that full
29
+ * structure with the signature region zeroed; splicing the 64-byte signature
30
+ * over the zeros yields bytes identical to `serializeWithSignatures`.
31
+ *
32
+ * Single-signer only (the RAX flow): exactly one signature at a fixed offset.
33
+ */
34
+ export interface SubmitTemplate {
35
+ /** The bytes the signer must sign (the transaction message). Hex-encoded. */
36
+ payloadHex: string;
37
+ /** Full wire transaction with the signature zeroed. Base64-encoded. */
38
+ wireTemplateBase64: string;
39
+ /** Byte offset in the template where the 64-byte signature is spliced in. */
40
+ signatureOffset: number;
41
+ /** Signature length in bytes (64 for ed25519). */
42
+ signatureLength: number;
43
+ /** The single required signer's base58 address (the user). */
44
+ signer: string;
45
+ }
46
+ /**
47
+ * Emit a chain-agnostic {@link SubmitTemplate} from a built single-signer
48
+ * transaction. The offset is derived from the wire layout, not assumed.
49
+ */
50
+ export declare function buildSubmitTemplate(result: BuildSwapResult): SubmitTemplate;
@@ -137,3 +137,55 @@ export function serializeWithSignatures(result, signatures) {
137
137
  }
138
138
  return result.transaction.serialize();
139
139
  }
140
+ /** compact-u16 (shortvec) encoded length — how Solana prefixes the sig array. */
141
+ function compactU16Length(n) {
142
+ if (n < 0x80)
143
+ return 1;
144
+ if (n < 0x4000)
145
+ return 2;
146
+ return 3;
147
+ }
148
+ /**
149
+ * Emit a chain-agnostic {@link SubmitTemplate} from a built single-signer
150
+ * transaction. The offset is derived from the wire layout, not assumed.
151
+ */
152
+ export function buildSubmitTemplate(result) {
153
+ const header = result.transaction.message.header;
154
+ if (header.numRequiredSignatures !== 1) {
155
+ throw new Error(`submit template supports a single signer; got ${header.numRequiredSignatures}`);
156
+ }
157
+ const SIG_LEN = 64;
158
+ // Zeroed-signature serialization IS the template (web3.js fills missing
159
+ // signatures with 64 zero bytes), so no manual zeroing is needed.
160
+ const wireTemplate = result.transaction.serialize();
161
+ const signatureOffset = compactU16Length(1); // count prefix precedes sig 0
162
+ // Invariant: the payload (message) is the tail after [count][signature].
163
+ const messageStart = signatureOffset + SIG_LEN;
164
+ const templateTail = wireTemplate.slice(messageStart);
165
+ if (templateTail.length !== result.messageBytes.length ||
166
+ !templateTail.every((b, i) => b === result.messageBytes[i])) {
167
+ throw new Error("submit template layout mismatch — message tail differs");
168
+ }
169
+ return {
170
+ payloadHex: bytesToHex(result.messageBytes),
171
+ wireTemplateBase64: toBase64(wireTemplate),
172
+ signatureOffset,
173
+ signatureLength: SIG_LEN,
174
+ signer: result.requiredSigners[0].toBase58(),
175
+ };
176
+ }
177
+ function bytesToHex(bytes) {
178
+ let hex = "";
179
+ for (const b of bytes)
180
+ hex += b.toString(16).padStart(2, "0");
181
+ return hex;
182
+ }
183
+ function toBase64(bytes) {
184
+ // Buffer in Node; btoa fallback in the browser.
185
+ if (typeof Buffer !== "undefined")
186
+ return Buffer.from(bytes).toString("base64");
187
+ let binary = "";
188
+ for (const b of bytes)
189
+ binary += String.fromCharCode(b);
190
+ return btoa(binary);
191
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0block.io/sdk",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Client-side transaction builder for the 0Block DEX router. Builds unsigned v0 swap transactions entirely offline \u2014 tenant-wrapped or direct \u2014 with shared address lookup tables, gateway tips, and on-chain fee-event decoding for accounting.",
5
5
  "keywords": [
6
6
  "solana",