@phantom/browser-sdk 0.2.0 → 0.2.1
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.js +13 -138
- package/dist/index.mjs +11 -136
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -235,141 +235,8 @@ var IframeAuth = class {
|
|
|
235
235
|
}
|
|
236
236
|
};
|
|
237
237
|
|
|
238
|
-
// src/parsers/index.ts
|
|
239
|
-
var import_base64url = require("@phantom/base64url");
|
|
240
|
-
|
|
241
|
-
// src/polyfills.ts
|
|
242
|
-
var import_buffer = require("buffer");
|
|
243
|
-
var import_jose = require("jose");
|
|
244
|
-
|
|
245
|
-
// src/parsers/index.ts
|
|
246
|
-
function parseMessage(message) {
|
|
247
|
-
return {
|
|
248
|
-
base64url: (0, import_base64url.stringToBase64url)(message)
|
|
249
|
-
};
|
|
250
|
-
}
|
|
251
|
-
async function parseTransaction(transaction, networkId) {
|
|
252
|
-
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
253
|
-
switch (networkPrefix) {
|
|
254
|
-
case "solana":
|
|
255
|
-
return parseSolanaTransaction(transaction);
|
|
256
|
-
case "ethereum":
|
|
257
|
-
case "polygon":
|
|
258
|
-
return parseEVMTransaction(transaction);
|
|
259
|
-
case "sui":
|
|
260
|
-
return await parseSuiTransaction(transaction);
|
|
261
|
-
case "bitcoin":
|
|
262
|
-
return parseBitcoinTransaction(transaction);
|
|
263
|
-
default:
|
|
264
|
-
throw new Error(`Unsupported network: ${networkPrefix}`);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
function parseSolanaTransaction(transaction) {
|
|
268
|
-
if (transaction?.messageBytes != null) {
|
|
269
|
-
return {
|
|
270
|
-
base64url: (0, import_base64url.base64urlEncode)(transaction.messageBytes),
|
|
271
|
-
originalFormat: "@solana/kit"
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
if (typeof transaction?.serialize === "function") {
|
|
275
|
-
const serialized = transaction.serialize();
|
|
276
|
-
return {
|
|
277
|
-
base64url: (0, import_base64url.base64urlEncode)(serialized),
|
|
278
|
-
originalFormat: "@solana/web3.js"
|
|
279
|
-
};
|
|
280
|
-
}
|
|
281
|
-
if (transaction instanceof Uint8Array) {
|
|
282
|
-
return {
|
|
283
|
-
base64url: (0, import_base64url.base64urlEncode)(transaction),
|
|
284
|
-
originalFormat: "bytes"
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
throw new Error("Unsupported Solana transaction format");
|
|
288
|
-
}
|
|
289
|
-
function parseEVMTransaction(transaction) {
|
|
290
|
-
if (transaction && typeof transaction === "object" && (transaction.to || transaction.data)) {
|
|
291
|
-
const bytes = new TextEncoder().encode(
|
|
292
|
-
JSON.stringify(transaction, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
293
|
-
);
|
|
294
|
-
return {
|
|
295
|
-
base64url: (0, import_base64url.base64urlEncode)(bytes),
|
|
296
|
-
originalFormat: "viem"
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
300
|
-
const serialized = transaction.serialize();
|
|
301
|
-
const bytes = new Uint8Array(import_buffer.Buffer.from(serialized.slice(2), "hex"));
|
|
302
|
-
return {
|
|
303
|
-
base64url: (0, import_base64url.base64urlEncode)(bytes),
|
|
304
|
-
originalFormat: "ethers"
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
if (transaction instanceof Uint8Array) {
|
|
308
|
-
return {
|
|
309
|
-
base64url: (0, import_base64url.base64urlEncode)(transaction),
|
|
310
|
-
originalFormat: "bytes"
|
|
311
|
-
};
|
|
312
|
-
}
|
|
313
|
-
if (typeof transaction === "string" && transaction.startsWith("0x")) {
|
|
314
|
-
const bytes = new Uint8Array(import_buffer.Buffer.from(transaction.slice(2), "hex"));
|
|
315
|
-
return {
|
|
316
|
-
base64url: (0, import_base64url.base64urlEncode)(bytes),
|
|
317
|
-
originalFormat: "hex"
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
throw new Error("Unsupported EVM transaction format");
|
|
321
|
-
}
|
|
322
|
-
async function parseSuiTransaction(transaction) {
|
|
323
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
324
|
-
const serialized = transaction.serialize();
|
|
325
|
-
return {
|
|
326
|
-
base64url: (0, import_base64url.base64urlEncode)(serialized),
|
|
327
|
-
originalFormat: "sui-sdk"
|
|
328
|
-
};
|
|
329
|
-
}
|
|
330
|
-
if (transaction instanceof Uint8Array) {
|
|
331
|
-
return {
|
|
332
|
-
base64url: (0, import_base64url.base64urlEncode)(transaction),
|
|
333
|
-
originalFormat: "bytes"
|
|
334
|
-
};
|
|
335
|
-
}
|
|
336
|
-
if (transaction?.build && typeof transaction.build === "function") {
|
|
337
|
-
const built = await transaction.build();
|
|
338
|
-
if (built?.serialize && typeof built.serialize === "function") {
|
|
339
|
-
const serialized = built.serialize();
|
|
340
|
-
return {
|
|
341
|
-
base64url: (0, import_base64url.base64urlEncode)(serialized),
|
|
342
|
-
originalFormat: "transaction-block"
|
|
343
|
-
};
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
throw new Error("Unsupported Sui transaction format");
|
|
347
|
-
}
|
|
348
|
-
function parseBitcoinTransaction(transaction) {
|
|
349
|
-
if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
|
|
350
|
-
const buffer = transaction.toBuffer();
|
|
351
|
-
return {
|
|
352
|
-
base64url: (0, import_base64url.base64urlEncode)(new Uint8Array(buffer)),
|
|
353
|
-
originalFormat: "bitcoinjs-lib"
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
if (transaction instanceof Uint8Array) {
|
|
357
|
-
return {
|
|
358
|
-
base64url: (0, import_base64url.base64urlEncode)(transaction),
|
|
359
|
-
originalFormat: "bytes"
|
|
360
|
-
};
|
|
361
|
-
}
|
|
362
|
-
if (typeof transaction === "string") {
|
|
363
|
-
const bytes = new Uint8Array(import_buffer.Buffer.from(transaction, "hex"));
|
|
364
|
-
return {
|
|
365
|
-
base64url: (0, import_base64url.base64urlEncode)(bytes),
|
|
366
|
-
originalFormat: "hex"
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
throw new Error("Unsupported Bitcoin transaction format");
|
|
370
|
-
}
|
|
371
|
-
|
|
372
238
|
// src/providers/embedded/index.ts
|
|
239
|
+
var import_parsers = require("@phantom/parsers");
|
|
373
240
|
var EmbeddedProvider = class {
|
|
374
241
|
constructor(config) {
|
|
375
242
|
this.client = null;
|
|
@@ -447,15 +314,23 @@ var EmbeddedProvider = class {
|
|
|
447
314
|
if (!this.client || !this.walletId) {
|
|
448
315
|
throw new Error("Not connected");
|
|
449
316
|
}
|
|
450
|
-
const parsedMessage = parseMessage(params.message);
|
|
451
|
-
return await this.client.signMessage(
|
|
317
|
+
const parsedMessage = (0, import_parsers.parseMessage)(params.message);
|
|
318
|
+
return await this.client.signMessage({
|
|
319
|
+
walletId: this.walletId,
|
|
320
|
+
message: parsedMessage.base64url,
|
|
321
|
+
networkId: params.networkId
|
|
322
|
+
});
|
|
452
323
|
}
|
|
453
324
|
async signAndSendTransaction(params) {
|
|
454
325
|
if (!this.client || !this.walletId) {
|
|
455
326
|
throw new Error("Not connected");
|
|
456
327
|
}
|
|
457
|
-
const parsedTransaction = await parseTransaction(params.transaction, params.networkId);
|
|
458
|
-
return await this.client.signAndSendTransaction(
|
|
328
|
+
const parsedTransaction = await (0, import_parsers.parseTransaction)(params.transaction, params.networkId);
|
|
329
|
+
return await this.client.signAndSendTransaction({
|
|
330
|
+
walletId: this.walletId,
|
|
331
|
+
transaction: parsedTransaction.base64url,
|
|
332
|
+
networkId: params.networkId
|
|
333
|
+
});
|
|
459
334
|
}
|
|
460
335
|
getAddresses() {
|
|
461
336
|
return this.addresses;
|
package/dist/index.mjs
CHANGED
|
@@ -207,141 +207,8 @@ var IframeAuth = class {
|
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
|
|
210
|
-
// src/parsers/index.ts
|
|
211
|
-
import { base64urlEncode, stringToBase64url } from "@phantom/base64url";
|
|
212
|
-
|
|
213
|
-
// src/polyfills.ts
|
|
214
|
-
import { Buffer } from "buffer";
|
|
215
|
-
import { base64url } from "jose";
|
|
216
|
-
|
|
217
|
-
// src/parsers/index.ts
|
|
218
|
-
function parseMessage(message) {
|
|
219
|
-
return {
|
|
220
|
-
base64url: stringToBase64url(message)
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
async function parseTransaction(transaction, networkId) {
|
|
224
|
-
const networkPrefix = networkId.split(":")[0].toLowerCase();
|
|
225
|
-
switch (networkPrefix) {
|
|
226
|
-
case "solana":
|
|
227
|
-
return parseSolanaTransaction(transaction);
|
|
228
|
-
case "ethereum":
|
|
229
|
-
case "polygon":
|
|
230
|
-
return parseEVMTransaction(transaction);
|
|
231
|
-
case "sui":
|
|
232
|
-
return await parseSuiTransaction(transaction);
|
|
233
|
-
case "bitcoin":
|
|
234
|
-
return parseBitcoinTransaction(transaction);
|
|
235
|
-
default:
|
|
236
|
-
throw new Error(`Unsupported network: ${networkPrefix}`);
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
function parseSolanaTransaction(transaction) {
|
|
240
|
-
if (transaction?.messageBytes != null) {
|
|
241
|
-
return {
|
|
242
|
-
base64url: base64urlEncode(transaction.messageBytes),
|
|
243
|
-
originalFormat: "@solana/kit"
|
|
244
|
-
};
|
|
245
|
-
}
|
|
246
|
-
if (typeof transaction?.serialize === "function") {
|
|
247
|
-
const serialized = transaction.serialize();
|
|
248
|
-
return {
|
|
249
|
-
base64url: base64urlEncode(serialized),
|
|
250
|
-
originalFormat: "@solana/web3.js"
|
|
251
|
-
};
|
|
252
|
-
}
|
|
253
|
-
if (transaction instanceof Uint8Array) {
|
|
254
|
-
return {
|
|
255
|
-
base64url: base64urlEncode(transaction),
|
|
256
|
-
originalFormat: "bytes"
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
throw new Error("Unsupported Solana transaction format");
|
|
260
|
-
}
|
|
261
|
-
function parseEVMTransaction(transaction) {
|
|
262
|
-
if (transaction && typeof transaction === "object" && (transaction.to || transaction.data)) {
|
|
263
|
-
const bytes = new TextEncoder().encode(
|
|
264
|
-
JSON.stringify(transaction, (_key, value) => typeof value === "bigint" ? value.toString() : value)
|
|
265
|
-
);
|
|
266
|
-
return {
|
|
267
|
-
base64url: base64urlEncode(bytes),
|
|
268
|
-
originalFormat: "viem"
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
272
|
-
const serialized = transaction.serialize();
|
|
273
|
-
const bytes = new Uint8Array(Buffer.from(serialized.slice(2), "hex"));
|
|
274
|
-
return {
|
|
275
|
-
base64url: base64urlEncode(bytes),
|
|
276
|
-
originalFormat: "ethers"
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
if (transaction instanceof Uint8Array) {
|
|
280
|
-
return {
|
|
281
|
-
base64url: base64urlEncode(transaction),
|
|
282
|
-
originalFormat: "bytes"
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
if (typeof transaction === "string" && transaction.startsWith("0x")) {
|
|
286
|
-
const bytes = new Uint8Array(Buffer.from(transaction.slice(2), "hex"));
|
|
287
|
-
return {
|
|
288
|
-
base64url: base64urlEncode(bytes),
|
|
289
|
-
originalFormat: "hex"
|
|
290
|
-
};
|
|
291
|
-
}
|
|
292
|
-
throw new Error("Unsupported EVM transaction format");
|
|
293
|
-
}
|
|
294
|
-
async function parseSuiTransaction(transaction) {
|
|
295
|
-
if (transaction?.serialize && typeof transaction.serialize === "function") {
|
|
296
|
-
const serialized = transaction.serialize();
|
|
297
|
-
return {
|
|
298
|
-
base64url: base64urlEncode(serialized),
|
|
299
|
-
originalFormat: "sui-sdk"
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
if (transaction instanceof Uint8Array) {
|
|
303
|
-
return {
|
|
304
|
-
base64url: base64urlEncode(transaction),
|
|
305
|
-
originalFormat: "bytes"
|
|
306
|
-
};
|
|
307
|
-
}
|
|
308
|
-
if (transaction?.build && typeof transaction.build === "function") {
|
|
309
|
-
const built = await transaction.build();
|
|
310
|
-
if (built?.serialize && typeof built.serialize === "function") {
|
|
311
|
-
const serialized = built.serialize();
|
|
312
|
-
return {
|
|
313
|
-
base64url: base64urlEncode(serialized),
|
|
314
|
-
originalFormat: "transaction-block"
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
throw new Error("Unsupported Sui transaction format");
|
|
319
|
-
}
|
|
320
|
-
function parseBitcoinTransaction(transaction) {
|
|
321
|
-
if (transaction?.toBuffer && typeof transaction.toBuffer === "function") {
|
|
322
|
-
const buffer = transaction.toBuffer();
|
|
323
|
-
return {
|
|
324
|
-
base64url: base64urlEncode(new Uint8Array(buffer)),
|
|
325
|
-
originalFormat: "bitcoinjs-lib"
|
|
326
|
-
};
|
|
327
|
-
}
|
|
328
|
-
if (transaction instanceof Uint8Array) {
|
|
329
|
-
return {
|
|
330
|
-
base64url: base64urlEncode(transaction),
|
|
331
|
-
originalFormat: "bytes"
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
if (typeof transaction === "string") {
|
|
335
|
-
const bytes = new Uint8Array(Buffer.from(transaction, "hex"));
|
|
336
|
-
return {
|
|
337
|
-
base64url: base64urlEncode(bytes),
|
|
338
|
-
originalFormat: "hex"
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
throw new Error("Unsupported Bitcoin transaction format");
|
|
342
|
-
}
|
|
343
|
-
|
|
344
210
|
// src/providers/embedded/index.ts
|
|
211
|
+
import { parseMessage, parseTransaction } from "@phantom/parsers";
|
|
345
212
|
var EmbeddedProvider = class {
|
|
346
213
|
constructor(config) {
|
|
347
214
|
this.client = null;
|
|
@@ -420,14 +287,22 @@ var EmbeddedProvider = class {
|
|
|
420
287
|
throw new Error("Not connected");
|
|
421
288
|
}
|
|
422
289
|
const parsedMessage = parseMessage(params.message);
|
|
423
|
-
return await this.client.signMessage(
|
|
290
|
+
return await this.client.signMessage({
|
|
291
|
+
walletId: this.walletId,
|
|
292
|
+
message: parsedMessage.base64url,
|
|
293
|
+
networkId: params.networkId
|
|
294
|
+
});
|
|
424
295
|
}
|
|
425
296
|
async signAndSendTransaction(params) {
|
|
426
297
|
if (!this.client || !this.walletId) {
|
|
427
298
|
throw new Error("Not connected");
|
|
428
299
|
}
|
|
429
300
|
const parsedTransaction = await parseTransaction(params.transaction, params.networkId);
|
|
430
|
-
return await this.client.signAndSendTransaction(
|
|
301
|
+
return await this.client.signAndSendTransaction({
|
|
302
|
+
walletId: this.walletId,
|
|
303
|
+
transaction: parsedTransaction.base64url,
|
|
304
|
+
networkId: params.networkId
|
|
305
|
+
});
|
|
431
306
|
}
|
|
432
307
|
getAddresses() {
|
|
433
308
|
return this.addresses;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/browser-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Browser SDK for Phantom Wallet with unified interface",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -27,10 +27,11 @@
|
|
|
27
27
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@phantom/api-key-stamper": "^0.1.
|
|
30
|
+
"@phantom/api-key-stamper": "^0.1.1",
|
|
31
31
|
"@phantom/base64url": "^0.1.0",
|
|
32
32
|
"@phantom/browser-injected-sdk": "^0.0.9",
|
|
33
|
-
"@phantom/client": "^0.1.
|
|
33
|
+
"@phantom/client": "^0.1.1",
|
|
34
|
+
"@phantom/parsers": "^0.0.2",
|
|
34
35
|
"axios": "^1.10.0",
|
|
35
36
|
"bs58": "^6.0.0",
|
|
36
37
|
"buffer": "^6.0.3",
|