@phantom/parsers 1.0.0-beta.5 → 1.0.0-beta.7

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
@@ -1,6 +1,6 @@
1
1
  import { NetworkId } from '@phantom/constants';
2
2
  import { Transaction as Transaction$1 } from '@solana/transactions';
3
- import { Transaction } from '@solana/web3.js';
3
+ import { Transaction, VersionedTransaction } from '@solana/web3.js';
4
4
 
5
5
  /**
6
6
  * Chain-specific transaction and message response parsing
@@ -27,11 +27,9 @@ declare function parseSignMessageResponse(base64Response: string, networkId: Net
27
27
  declare function parseTransactionResponse(base64RawTransaction: string, networkId: NetworkId, hash?: string): ParsedTransactionResult;
28
28
  /**
29
29
  * Parse Solana signed transaction from base64url encoded transaction bytes
30
+ * Supports both legacy Transaction and VersionedTransaction formats
30
31
  */
31
- declare function parseSolanaSignedTransaction(base64RawTransaction: string): {
32
- transaction: Transaction | null;
33
- fallback: boolean;
34
- };
32
+ declare function parseSolanaSignedTransaction(base64RawTransaction: string): Transaction | VersionedTransaction | null;
35
33
 
36
34
  interface ParsedTransaction {
37
35
  base64url: string;
package/dist/index.js CHANGED
@@ -43,11 +43,11 @@ var import_transactions = require("@solana/transactions");
43
43
  var import_buffer2 = require("buffer");
44
44
 
45
45
  // src/response-parsers.ts
46
- var import_constants = require("@phantom/constants");
47
46
  var import_base64url = require("@phantom/base64url");
48
- var import_buffer = require("buffer");
49
- var import_bs58 = __toESM(require("bs58"));
47
+ var import_constants = require("@phantom/constants");
50
48
  var import_web3 = require("@solana/web3.js");
49
+ var import_bs58 = __toESM(require("bs58"));
50
+ var import_buffer = require("buffer");
51
51
  function parseSignMessageResponse(base64Response, networkId) {
52
52
  const networkPrefix = networkId.split(":")[0].toLowerCase();
53
53
  switch (networkPrefix) {
@@ -99,6 +99,12 @@ function parseSolanaSignatureResponse(base64Response) {
99
99
  function parseEVMSignatureResponse(base64Response) {
100
100
  try {
101
101
  const signatureBytes = (0, import_base64url.base64urlDecode)(base64Response);
102
+ if (signatureBytes.length === 65) {
103
+ const recoveryId = signatureBytes[64];
104
+ if (recoveryId === 0 || recoveryId === 1) {
105
+ signatureBytes[64] = recoveryId + 27;
106
+ }
107
+ }
102
108
  const signature = "0x" + import_buffer.Buffer.from(signatureBytes).toString("hex");
103
109
  return {
104
110
  signature,
@@ -145,17 +151,19 @@ function parseBitcoinSignatureResponse(base64Response) {
145
151
  }
146
152
  function parseSolanaSignedTransaction(base64RawTransaction) {
147
153
  try {
148
- const transactionBytes = import_buffer.Buffer.from(base64RawTransaction, "base64url");
149
- const transaction = import_web3.Transaction.from(transactionBytes);
150
- return {
151
- transaction,
152
- fallback: false
153
- };
154
+ const transactionBytes = (0, import_base64url.base64urlDecode)(base64RawTransaction);
155
+ try {
156
+ const transaction = import_web3.Transaction.from(transactionBytes);
157
+ return transaction;
158
+ } catch (legacyError) {
159
+ if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
160
+ const versionedTransaction = import_web3.VersionedTransaction.deserialize(transactionBytes);
161
+ return versionedTransaction;
162
+ }
163
+ throw legacyError;
164
+ }
154
165
  } catch (error) {
155
- return {
156
- transaction: null,
157
- fallback: true
158
- };
166
+ return null;
159
167
  }
160
168
  }
161
169
 
package/dist/index.mjs CHANGED
@@ -4,11 +4,11 @@ import { getTransactionEncoder } from "@solana/transactions";
4
4
  import { Buffer as Buffer2 } from "buffer";
5
5
 
6
6
  // src/response-parsers.ts
7
- import { getExplorerUrl } from "@phantom/constants";
8
7
  import { base64urlDecode } from "@phantom/base64url";
9
- import { Buffer } from "buffer";
8
+ import { getExplorerUrl } from "@phantom/constants";
9
+ import { Transaction, VersionedTransaction } from "@solana/web3.js";
10
10
  import bs58 from "bs58";
11
- import { Transaction } from "@solana/web3.js";
11
+ import { Buffer } from "buffer";
12
12
  function parseSignMessageResponse(base64Response, networkId) {
13
13
  const networkPrefix = networkId.split(":")[0].toLowerCase();
14
14
  switch (networkPrefix) {
@@ -60,6 +60,12 @@ function parseSolanaSignatureResponse(base64Response) {
60
60
  function parseEVMSignatureResponse(base64Response) {
61
61
  try {
62
62
  const signatureBytes = base64urlDecode(base64Response);
63
+ if (signatureBytes.length === 65) {
64
+ const recoveryId = signatureBytes[64];
65
+ if (recoveryId === 0 || recoveryId === 1) {
66
+ signatureBytes[64] = recoveryId + 27;
67
+ }
68
+ }
63
69
  const signature = "0x" + Buffer.from(signatureBytes).toString("hex");
64
70
  return {
65
71
  signature,
@@ -106,17 +112,19 @@ function parseBitcoinSignatureResponse(base64Response) {
106
112
  }
107
113
  function parseSolanaSignedTransaction(base64RawTransaction) {
108
114
  try {
109
- const transactionBytes = Buffer.from(base64RawTransaction, "base64url");
110
- const transaction = Transaction.from(transactionBytes);
111
- return {
112
- transaction,
113
- fallback: false
114
- };
115
+ const transactionBytes = base64urlDecode(base64RawTransaction);
116
+ try {
117
+ const transaction = Transaction.from(transactionBytes);
118
+ return transaction;
119
+ } catch (legacyError) {
120
+ if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
121
+ const versionedTransaction = VersionedTransaction.deserialize(transactionBytes);
122
+ return versionedTransaction;
123
+ }
124
+ throw legacyError;
125
+ }
115
126
  } catch (error) {
116
- return {
117
- transaction: null,
118
- fallback: true
119
- };
127
+ return null;
120
128
  }
121
129
  }
122
130
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/parsers",
3
- "version": "1.0.0-beta.5",
3
+ "version": "1.0.0-beta.7",
4
4
  "description": "Transaction and message parsers for Phantom Wallet SDK",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -29,9 +29,9 @@
29
29
  "prettier": "prettier --write \"src/**/*.{ts}\""
30
30
  },
31
31
  "dependencies": {
32
- "@phantom/base64url": "^1.0.0-beta.5",
33
- "@phantom/constants": "^1.0.0-beta.5",
34
- "@phantom/sdk-types": "^1.0.0-beta.5",
32
+ "@phantom/base64url": "^1.0.0-beta.7",
33
+ "@phantom/constants": "^1.0.0-beta.7",
34
+ "@phantom/sdk-types": "^1.0.0-beta.7",
35
35
  "@solana/transactions": "^2.0.0",
36
36
  "@solana/web3.js": "^1.95.0",
37
37
  "bs58": "^6.0.0",