@phantom/parsers 1.0.0-beta.4 → 1.0.0-beta.6
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 +3 -5
- package/dist/index.js +13 -10
- package/dist/index.mjs +14 -11
- package/package.json +4 -4
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
|
@@ -145,18 +145,21 @@ function parseBitcoinSignatureResponse(base64Response) {
|
|
|
145
145
|
}
|
|
146
146
|
function parseSolanaSignedTransaction(base64RawTransaction) {
|
|
147
147
|
try {
|
|
148
|
-
const transactionBytes =
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
transaction
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
const transactionBytes = (0, import_base64url.base64urlDecode)(base64RawTransaction);
|
|
149
|
+
try {
|
|
150
|
+
const transaction = import_web3.Transaction.from(transactionBytes);
|
|
151
|
+
return transaction;
|
|
152
|
+
} catch (legacyError) {
|
|
153
|
+
if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
|
|
154
|
+
const versionedTransaction = import_web3.VersionedTransaction.deserialize(transactionBytes);
|
|
155
|
+
return versionedTransaction;
|
|
156
|
+
}
|
|
157
|
+
throw legacyError;
|
|
158
|
+
}
|
|
154
159
|
} catch (error) {
|
|
155
|
-
return
|
|
156
|
-
transaction: null,
|
|
157
|
-
fallback: true
|
|
158
|
-
};
|
|
160
|
+
return null;
|
|
159
161
|
}
|
|
162
|
+
;
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
// src/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { getExplorerUrl } from "@phantom/constants";
|
|
|
8
8
|
import { base64urlDecode } from "@phantom/base64url";
|
|
9
9
|
import { Buffer } from "buffer";
|
|
10
10
|
import bs58 from "bs58";
|
|
11
|
-
import { Transaction } from "@solana/web3.js";
|
|
11
|
+
import { Transaction, VersionedTransaction } from "@solana/web3.js";
|
|
12
12
|
function parseSignMessageResponse(base64Response, networkId) {
|
|
13
13
|
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
14
14
|
switch (networkPrefix) {
|
|
@@ -106,18 +106,21 @@ function parseBitcoinSignatureResponse(base64Response) {
|
|
|
106
106
|
}
|
|
107
107
|
function parseSolanaSignedTransaction(base64RawTransaction) {
|
|
108
108
|
try {
|
|
109
|
-
const transactionBytes =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
transaction
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
const transactionBytes = base64urlDecode(base64RawTransaction);
|
|
110
|
+
try {
|
|
111
|
+
const transaction = Transaction.from(transactionBytes);
|
|
112
|
+
return transaction;
|
|
113
|
+
} catch (legacyError) {
|
|
114
|
+
if (legacyError instanceof Error && legacyError.message.includes("Versioned messages")) {
|
|
115
|
+
const versionedTransaction = VersionedTransaction.deserialize(transactionBytes);
|
|
116
|
+
return versionedTransaction;
|
|
117
|
+
}
|
|
118
|
+
throw legacyError;
|
|
119
|
+
}
|
|
115
120
|
} catch (error) {
|
|
116
|
-
return
|
|
117
|
-
transaction: null,
|
|
118
|
-
fallback: true
|
|
119
|
-
};
|
|
121
|
+
return null;
|
|
120
122
|
}
|
|
123
|
+
;
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
// src/index.ts
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/parsers",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
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.
|
|
33
|
-
"@phantom/constants": "^1.0.0-beta.
|
|
34
|
-
"@phantom/sdk-types": "^1.0.0-beta.
|
|
32
|
+
"@phantom/base64url": "^1.0.0-beta.6",
|
|
33
|
+
"@phantom/constants": "^1.0.0-beta.6",
|
|
34
|
+
"@phantom/sdk-types": "^1.0.0-beta.6",
|
|
35
35
|
"@solana/transactions": "^2.0.0",
|
|
36
36
|
"@solana/web3.js": "^1.95.0",
|
|
37
37
|
"bs58": "^6.0.0",
|