@phantom/parsers 1.0.5 → 1.0.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 +22 -1
- package/dist/index.js +22 -2
- package/dist/index.mjs +20 -1
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -44,6 +44,27 @@ interface ParsedTransaction {
|
|
|
44
44
|
originalFormat: string;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
+
/**
|
|
48
|
+
* EIP-712 typed data structure.
|
|
49
|
+
* See: https://eips.ethereum.org/EIPS/eip-712
|
|
50
|
+
*/
|
|
51
|
+
interface Eip712TypedData {
|
|
52
|
+
types: Record<string, {
|
|
53
|
+
name: string;
|
|
54
|
+
type: string;
|
|
55
|
+
}[]>;
|
|
56
|
+
primaryType: string;
|
|
57
|
+
domain: Record<string, unknown>;
|
|
58
|
+
message: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Validate that a value conforms to the EIP-712 typed data structure.
|
|
62
|
+
* Throws a descriptive error if the structure is invalid.
|
|
63
|
+
*
|
|
64
|
+
* @param data - Value to validate
|
|
65
|
+
* @throws Error if data is not a valid EIP-712 typed data object
|
|
66
|
+
*/
|
|
67
|
+
declare function validateEip712TypedData(data: unknown): asserts data is Eip712TypedData;
|
|
47
68
|
/**
|
|
48
69
|
* Parse a transaction to KMS format based on network type
|
|
49
70
|
* - Solana: base64url encoding
|
|
@@ -53,4 +74,4 @@ interface ParsedTransaction {
|
|
|
53
74
|
declare function parseToKmsTransaction(transaction: any, networkId: NetworkId): Promise<ParsedTransaction>;
|
|
54
75
|
declare function parseSolanaKitTransactionToSolanaWeb3js(transaction: Transaction$1): any;
|
|
55
76
|
|
|
56
|
-
export { ParsedSignatureResult, ParsedTransaction, ParsedTransactionResult, deserializeSolanaTransaction, parseSignMessageResponse, parseSolanaKitTransactionToSolanaWeb3js, parseSolanaSignedTransaction, parseToKmsTransaction, parseTransactionResponse };
|
|
77
|
+
export { Eip712TypedData, ParsedSignatureResult, ParsedTransaction, ParsedTransactionResult, deserializeSolanaTransaction, parseSignMessageResponse, parseSolanaKitTransactionToSolanaWeb3js, parseSolanaSignedTransaction, parseToKmsTransaction, parseTransactionResponse, validateEip712TypedData };
|
package/dist/index.js
CHANGED
|
@@ -35,7 +35,8 @@ __export(src_exports, {
|
|
|
35
35
|
parseSolanaKitTransactionToSolanaWeb3js: () => parseSolanaKitTransactionToSolanaWeb3js,
|
|
36
36
|
parseSolanaSignedTransaction: () => parseSolanaSignedTransaction,
|
|
37
37
|
parseToKmsTransaction: () => parseToKmsTransaction,
|
|
38
|
-
parseTransactionResponse: () => parseTransactionResponse
|
|
38
|
+
parseTransactionResponse: () => parseTransactionResponse,
|
|
39
|
+
validateEip712TypedData: () => validateEip712TypedData
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(src_exports);
|
|
41
42
|
var import_base64url2 = require("@phantom/base64url");
|
|
@@ -167,6 +168,24 @@ function deserializeSolanaTransaction(transactionBytes) {
|
|
|
167
168
|
}
|
|
168
169
|
|
|
169
170
|
// src/index.ts
|
|
171
|
+
function validateEip712TypedData(data) {
|
|
172
|
+
if (typeof data !== "object" || data === null) {
|
|
173
|
+
throw new Error("typedData must be an object");
|
|
174
|
+
}
|
|
175
|
+
const obj = data;
|
|
176
|
+
if (typeof obj.types !== "object" || obj.types === null || Array.isArray(obj.types)) {
|
|
177
|
+
throw new Error("typedData.types must be an object mapping type names to field arrays");
|
|
178
|
+
}
|
|
179
|
+
if (typeof obj.primaryType !== "string" || !obj.primaryType) {
|
|
180
|
+
throw new Error("typedData.primaryType must be a non-empty string");
|
|
181
|
+
}
|
|
182
|
+
if (typeof obj.domain !== "object" || obj.domain === null || Array.isArray(obj.domain)) {
|
|
183
|
+
throw new Error("typedData.domain must be an object");
|
|
184
|
+
}
|
|
185
|
+
if (typeof obj.message !== "object" || obj.message === null || Array.isArray(obj.message)) {
|
|
186
|
+
throw new Error("typedData.message must be an object");
|
|
187
|
+
}
|
|
188
|
+
}
|
|
170
189
|
async function parseToKmsTransaction(transaction, networkId) {
|
|
171
190
|
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
172
191
|
switch (networkPrefix) {
|
|
@@ -350,5 +369,6 @@ function parseSolanaKitTransactionToSolanaWeb3js(transaction) {
|
|
|
350
369
|
parseSolanaKitTransactionToSolanaWeb3js,
|
|
351
370
|
parseSolanaSignedTransaction,
|
|
352
371
|
parseToKmsTransaction,
|
|
353
|
-
parseTransactionResponse
|
|
372
|
+
parseTransactionResponse,
|
|
373
|
+
validateEip712TypedData
|
|
354
374
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -128,6 +128,24 @@ function deserializeSolanaTransaction(transactionBytes) {
|
|
|
128
128
|
}
|
|
129
129
|
|
|
130
130
|
// src/index.ts
|
|
131
|
+
function validateEip712TypedData(data) {
|
|
132
|
+
if (typeof data !== "object" || data === null) {
|
|
133
|
+
throw new Error("typedData must be an object");
|
|
134
|
+
}
|
|
135
|
+
const obj = data;
|
|
136
|
+
if (typeof obj.types !== "object" || obj.types === null || Array.isArray(obj.types)) {
|
|
137
|
+
throw new Error("typedData.types must be an object mapping type names to field arrays");
|
|
138
|
+
}
|
|
139
|
+
if (typeof obj.primaryType !== "string" || !obj.primaryType) {
|
|
140
|
+
throw new Error("typedData.primaryType must be a non-empty string");
|
|
141
|
+
}
|
|
142
|
+
if (typeof obj.domain !== "object" || obj.domain === null || Array.isArray(obj.domain)) {
|
|
143
|
+
throw new Error("typedData.domain must be an object");
|
|
144
|
+
}
|
|
145
|
+
if (typeof obj.message !== "object" || obj.message === null || Array.isArray(obj.message)) {
|
|
146
|
+
throw new Error("typedData.message must be an object");
|
|
147
|
+
}
|
|
148
|
+
}
|
|
131
149
|
async function parseToKmsTransaction(transaction, networkId) {
|
|
132
150
|
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
133
151
|
switch (networkPrefix) {
|
|
@@ -310,5 +328,6 @@ export {
|
|
|
310
328
|
parseSolanaKitTransactionToSolanaWeb3js,
|
|
311
329
|
parseSolanaSignedTransaction,
|
|
312
330
|
parseToKmsTransaction,
|
|
313
|
-
parseTransactionResponse
|
|
331
|
+
parseTransactionResponse,
|
|
332
|
+
validateEip712TypedData
|
|
314
333
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/parsers",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Transaction and message parsers for Phantom Wallet SDK",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
"prettier": "prettier --write \"src/**/*.{ts}\""
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@phantom/base64url": "^1.0.
|
|
38
|
-
"@phantom/constants": "^1.0.
|
|
39
|
-
"@phantom/sdk-types": "^1.0.
|
|
40
|
-
"@phantom/utils": "^1.0.
|
|
37
|
+
"@phantom/base64url": "^1.0.7",
|
|
38
|
+
"@phantom/constants": "^1.0.7",
|
|
39
|
+
"@phantom/sdk-types": "^1.0.7",
|
|
40
|
+
"@phantom/utils": "^1.0.7",
|
|
41
41
|
"@solana/transactions": "^2.0.0",
|
|
42
42
|
"@solana/web3.js": "^1.95.0",
|
|
43
43
|
"bs58": "^6.0.0",
|