@phantom/browser-sdk 0.0.9 → 0.1.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/package.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "name": "@phantom/browser-sdk",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
+ "description": "Browser SDK for Phantom Wallet with unified interface",
4
5
  "main": "dist/index.js",
5
6
  "module": "dist/index.mjs",
6
7
  "types": "dist/index.d.ts",
@@ -9,46 +10,42 @@
9
10
  "import": "./dist/index.mjs",
10
11
  "require": "./dist/index.js",
11
12
  "types": "./dist/index.d.ts"
12
- },
13
- "./solana": {
14
- "import": "./dist/solana/index.mjs",
15
- "require": "./dist/solana/index.js",
16
- "types": "./dist/solana/index.d.ts"
17
- },
18
- "./auto-confirm": {
19
- "import": "./dist/auto-confirm/index.mjs",
20
- "require": "./dist/auto-confirm/index.js",
21
- "types": "./dist/auto-confirm/index.d.ts"
22
13
  }
23
14
  },
24
15
  "files": [
25
16
  "dist"
26
17
  ],
27
- "license": "MIT",
28
18
  "scripts": {
29
- "?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
30
- "pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
31
- "build": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/auto-confirm/index.ts --format cjs,esm --dts",
32
- "build:watch": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/auto-confirm/index.ts --format cjs,esm --dts --watch",
33
- "dev": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/auto-confirm/index.ts --format cjs,esm --dts --watch",
19
+ "build": "rimraf ./dist && tsup",
20
+ "dev": "rimraf ./dist && tsup --watch",
21
+ "clean": "rm -rf dist",
22
+ "test": "jest",
23
+ "test:watch": "jest --watch",
34
24
  "lint": "tsc --noEmit && eslint --cache . --ext .ts,.tsx",
35
- "test": "jest"
25
+ "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
26
+ },
27
+ "dependencies": {
28
+ "@phantom/api-key-stamper": "workspace:^",
29
+ "@phantom/base64url": "workspace:^",
30
+ "@phantom/browser-injected-sdk": "workspace:^",
31
+ "@phantom/client": "workspace:^",
32
+ "axios": "^1.10.0",
33
+ "bs58": "^6.0.0",
34
+ "buffer": "^6.0.3",
35
+ "jose": "^6.0.12",
36
+ "tweetnacl": "^1.0.3"
36
37
  },
37
38
  "devDependencies": {
38
- "@solana/web3.js": "^1.98.2",
39
- "@types/jest": "^29.5.14",
39
+ "@types/jest": "^29.5.12",
40
+ "@types/node": "^20.11.0",
40
41
  "eslint": "8.53.0",
41
- "jest": "^29.7.0",
42
+ "fake-indexeddb": "^4.0.2",
43
+ "jest": "^30.0.5",
44
+ "jest-environment-jsdom": "^30.0.5",
45
+ "prettier": "^3.5.2",
42
46
  "rimraf": "^6.0.1",
47
+ "ts-jest": "^29.1.2",
43
48
  "tsup": "^6.7.0",
44
49
  "typescript": "^5.0.4"
45
- },
46
- "dependencies": {
47
- "@solana/compat": "2.1.1",
48
- "@solana/kit": "^2.1.1",
49
- "@solana/transactions": "^2.1.1"
50
- },
51
- "publishConfig": {
52
- "directory": "_release/package"
53
50
  }
54
- }
51
+ }
@@ -1,37 +0,0 @@
1
- import { Plugin } from '../index.js';
2
-
3
- type NetworkID = "bip122:000000000019d6689c085ae165831e93" | "bip122:000000000933ea01ad0ee984209779ba" | "solana:101" | "solana:102" | "solana:103" | "solana:localnet" | "eip155:1" | "eip155:11155111" | "eip155:137" | "eip155:80002" | "eip155:8453" | "eip155:84532" | "eip155:143" | "eip155:10143" | "eip155:41454" | "eip155:42161" | "eip155:421614" | "hypercore:mainnet" | "hypercore:testnet" | "sui:mainnet" | "sui:testnet";
4
- type AutoConfirmEnableParams = {
5
- chains?: NetworkID[];
6
- };
7
- type AutoConfirmResult = {
8
- enabled: boolean;
9
- chains: NetworkID[];
10
- };
11
- type AutoConfirmSupportedChainsResult = {
12
- chains: NetworkID[];
13
- };
14
-
15
- declare function autoConfirmEnable(params?: AutoConfirmEnableParams): Promise<AutoConfirmResult>;
16
-
17
- declare function autoConfirmDisable(): Promise<AutoConfirmResult>;
18
-
19
- declare function autoConfirmStatus(): Promise<AutoConfirmResult>;
20
-
21
- declare function autoConfirmSupportedChains(): Promise<AutoConfirmSupportedChainsResult>;
22
-
23
- type AutoConfirmPlugin = {
24
- autoConfirmEnable: typeof autoConfirmEnable;
25
- autoConfirmDisable: typeof autoConfirmDisable;
26
- autoConfirmStatus: typeof autoConfirmStatus;
27
- autoConfirmSupportedChains: typeof autoConfirmSupportedChains;
28
- };
29
- declare function createAutoConfirmPlugin(): Plugin<AutoConfirmPlugin>;
30
-
31
- declare module "../index" {
32
- interface Phantom {
33
- autoConfirm: AutoConfirmPlugin;
34
- }
35
- }
36
-
37
- export { AutoConfirmEnableParams, AutoConfirmResult, AutoConfirmSupportedChainsResult, NetworkID, createAutoConfirmPlugin };
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/auto-confirm/index.ts
21
- var auto_confirm_exports = {};
22
- __export(auto_confirm_exports, {
23
- createAutoConfirmPlugin: () => createAutoConfirmPlugin
24
- });
25
- module.exports = __toCommonJS(auto_confirm_exports);
26
-
27
- // src/auto-confirm/getProvider.ts
28
- function getProvider() {
29
- if (typeof window === "undefined") {
30
- return null;
31
- }
32
- const provider = window.phantom?.app;
33
- if (!provider) {
34
- return null;
35
- }
36
- return provider;
37
- }
38
-
39
- // src/auto-confirm/autoConfirmEnable.ts
40
- async function autoConfirmEnable(params) {
41
- const provider = await getProvider();
42
- if (!provider) {
43
- throw new Error("Provider not found.");
44
- }
45
- const result = await provider.request({
46
- method: "phantom_auto_confirm_enable",
47
- params: params || {}
48
- });
49
- return result;
50
- }
51
-
52
- // src/auto-confirm/autoConfirmDisable.ts
53
- async function autoConfirmDisable() {
54
- const provider = await getProvider();
55
- if (!provider) {
56
- throw new Error("Provider not found.");
57
- }
58
- const result = await provider.request({
59
- method: "phantom_auto_confirm_disable",
60
- params: {}
61
- });
62
- return result;
63
- }
64
-
65
- // src/auto-confirm/autoConfirmStatus.ts
66
- async function autoConfirmStatus() {
67
- const provider = await getProvider();
68
- if (!provider) {
69
- throw new Error("Provider not found.");
70
- }
71
- const result = await provider.request({
72
- method: "phantom_auto_confirm_status",
73
- params: {}
74
- });
75
- return result;
76
- }
77
-
78
- // src/auto-confirm/autoConfirmSupportedChains.ts
79
- async function autoConfirmSupportedChains() {
80
- const provider = getProvider();
81
- if (!provider) {
82
- throw new Error("Provider not found.");
83
- }
84
- const result = await provider.request({
85
- method: "phantom_auto_confirm_supported_chains",
86
- params: {}
87
- });
88
- return result;
89
- }
90
-
91
- // src/auto-confirm/plugin.ts
92
- var autoConfirm = {
93
- autoConfirmEnable,
94
- autoConfirmDisable,
95
- autoConfirmStatus,
96
- autoConfirmSupportedChains
97
- };
98
- function createAutoConfirmPlugin() {
99
- return {
100
- name: "autoConfirm",
101
- create: () => autoConfirm
102
- };
103
- }
104
- // Annotate the CommonJS export names for ESM import in node:
105
- 0 && (module.exports = {
106
- createAutoConfirmPlugin
107
- });
@@ -1,82 +0,0 @@
1
- import "../chunk-GV6AIHPN.mjs";
2
-
3
- // src/auto-confirm/getProvider.ts
4
- function getProvider() {
5
- if (typeof window === "undefined") {
6
- return null;
7
- }
8
- const provider = window.phantom?.app;
9
- if (!provider) {
10
- return null;
11
- }
12
- return provider;
13
- }
14
-
15
- // src/auto-confirm/autoConfirmEnable.ts
16
- async function autoConfirmEnable(params) {
17
- const provider = await getProvider();
18
- if (!provider) {
19
- throw new Error("Provider not found.");
20
- }
21
- const result = await provider.request({
22
- method: "phantom_auto_confirm_enable",
23
- params: params || {}
24
- });
25
- return result;
26
- }
27
-
28
- // src/auto-confirm/autoConfirmDisable.ts
29
- async function autoConfirmDisable() {
30
- const provider = await getProvider();
31
- if (!provider) {
32
- throw new Error("Provider not found.");
33
- }
34
- const result = await provider.request({
35
- method: "phantom_auto_confirm_disable",
36
- params: {}
37
- });
38
- return result;
39
- }
40
-
41
- // src/auto-confirm/autoConfirmStatus.ts
42
- async function autoConfirmStatus() {
43
- const provider = await getProvider();
44
- if (!provider) {
45
- throw new Error("Provider not found.");
46
- }
47
- const result = await provider.request({
48
- method: "phantom_auto_confirm_status",
49
- params: {}
50
- });
51
- return result;
52
- }
53
-
54
- // src/auto-confirm/autoConfirmSupportedChains.ts
55
- async function autoConfirmSupportedChains() {
56
- const provider = getProvider();
57
- if (!provider) {
58
- throw new Error("Provider not found.");
59
- }
60
- const result = await provider.request({
61
- method: "phantom_auto_confirm_supported_chains",
62
- params: {}
63
- });
64
- return result;
65
- }
66
-
67
- // src/auto-confirm/plugin.ts
68
- var autoConfirm = {
69
- autoConfirmEnable,
70
- autoConfirmDisable,
71
- autoConfirmStatus,
72
- autoConfirmSupportedChains
73
- };
74
- function createAutoConfirmPlugin() {
75
- return {
76
- name: "autoConfirm",
77
- create: () => autoConfirm
78
- };
79
- }
80
- export {
81
- createAutoConfirmPlugin
82
- };
@@ -1,18 +0,0 @@
1
- var __accessCheck = (obj, member, msg) => {
2
- if (!member.has(obj))
3
- throw TypeError("Cannot " + msg);
4
- };
5
- var __privateAdd = (obj, member, value) => {
6
- if (member.has(obj))
7
- throw TypeError("Cannot add the same private member more than once");
8
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
9
- };
10
- var __privateMethod = (obj, member, method) => {
11
- __accessCheck(obj, member, "access private method");
12
- return method;
13
- };
14
-
15
- export {
16
- __privateAdd,
17
- __privateMethod
18
- };
@@ -1,139 +0,0 @@
1
- import { Plugin } from '../index.js';
2
- import { Transaction as Transaction$1 } from '@solana/kit';
3
- import { VersionedTransaction as VersionedTransaction$1 } from '@solana/web3.js';
4
-
5
- declare function connect(): Promise<string | undefined>;
6
-
7
- declare function disconnect(): Promise<void>;
8
-
9
- type Transaction = {
10
- message: Uint8Array;
11
- recentBlockhash: string;
12
- feePayer: string;
13
- instructions: any[];
14
- signers: string[];
15
- version: number;
16
- };
17
- type VersionedTransaction = {
18
- signatures: Uint8Array[];
19
- message: {
20
- deserialize: (serializedTransaction: Uint8Array) => VersionedTransaction;
21
- serialize: (transaction: VersionedTransaction) => Uint8Array;
22
- };
23
- };
24
- type SendOptions = {
25
- skipPreflight?: boolean;
26
- preflightCommitment?: string;
27
- maxRetries?: number;
28
- minContextSlot?: number;
29
- };
30
- type PublicKey = {
31
- toString: () => string;
32
- toBase58: () => string;
33
- };
34
- type SolanaSignInData = {
35
- domain?: string;
36
- address?: string;
37
- statement?: string;
38
- uri?: string;
39
- version?: string;
40
- chainId?: string;
41
- nonce?: string;
42
- issuedAt?: string;
43
- expirationTime?: string;
44
- notBefore?: string;
45
- requestId?: string;
46
- resources?: string[];
47
- };
48
- type DisplayEncoding = "utf8" | "hex";
49
- type PhantomEventType = "connect" | "disconnect" | "accountChanged";
50
- interface PhantomSolanaProvider {
51
- isPhantom: boolean;
52
- publicKey: PublicKey | null;
53
- isConnected: boolean;
54
- connect: (opts?: {
55
- onlyIfTrusted?: boolean;
56
- }) => Promise<{
57
- publicKey: PublicKey;
58
- }>;
59
- disconnect: () => Promise<void>;
60
- signMessage: (message: Uint8Array, display?: DisplayEncoding) => Promise<{
61
- signature: Uint8Array;
62
- publicKey: PublicKey;
63
- }>;
64
- signIn: (signInData: SolanaSignInData) => Promise<{
65
- address: PublicKey;
66
- signature: Uint8Array;
67
- signedMessage: Uint8Array;
68
- }>;
69
- signAndSendTransaction: (transaction: Transaction | VersionedTransaction, options?: SendOptions) => Promise<{
70
- signature: string;
71
- publicKey?: string;
72
- }>;
73
- signAllTransactions: (transactions: (Transaction | VersionedTransaction)[]) => Promise<(Transaction | VersionedTransaction)[]>;
74
- signTransaction: (transaction: Transaction | VersionedTransaction) => Promise<Transaction | VersionedTransaction>;
75
- on: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
76
- off: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
77
- }
78
-
79
- type ConnectCallback = (publicKey: string) => void;
80
- type DisconnectCallback = () => void;
81
- type AccountChangedCallback = (publicKey: string) => void;
82
- type PhantomEventCallback = ConnectCallback | DisconnectCallback | AccountChangedCallback;
83
-
84
- declare function getAccount(): Promise<string | undefined>;
85
-
86
- /**
87
- * Signs and sends a transaction using the Phantom provider.
88
- * @param transaction The transaction to sign and send.
89
- * @returns A promise that resolves with the transaction signature and optionally the public key.
90
- * @throws Error if Phantom provider is not found or if the operation fails.
91
- */
92
- declare function signAndSendTransaction(transaction: Transaction$1 | VersionedTransaction$1): Promise<{
93
- signature: string;
94
- address?: string;
95
- }>;
96
-
97
- /**
98
- * Signs in with Solana using the Phantom provider.
99
- * @param signInData The sign-in data.
100
- * @returns A promise that resolves with the address, signature, and signed message.
101
- * @throws Error if Phantom provider is not found or if the operation fails.
102
- */
103
- declare function signIn(signInData: SolanaSignInData): Promise<{
104
- address: string;
105
- signature: Uint8Array;
106
- signedMessage: Uint8Array;
107
- }>;
108
-
109
- /**
110
- * Signs a message using the Phantom provider.
111
- * @param message The message to sign (as a Uint8Array).
112
- * @param display The display encoding for the message (optional, defaults to utf8).
113
- * @returns A promise that resolves with the signature and public key.
114
- * @throws Error if Phantom provider is not found or if the operation fails.
115
- */
116
- declare function signMessage(message: Uint8Array, display?: DisplayEncoding): Promise<{
117
- signature: Uint8Array;
118
- address: string;
119
- }>;
120
-
121
- type Solana = {
122
- connect: typeof connect;
123
- disconnect: typeof disconnect;
124
- getAccount: typeof getAccount;
125
- signMessage: typeof signMessage;
126
- signIn: typeof signIn;
127
- signAndSendTransaction: typeof signAndSendTransaction;
128
- addEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => () => void;
129
- removeEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => void;
130
- };
131
- declare function createSolanaPlugin(): Plugin<Solana>;
132
-
133
- declare module "../index" {
134
- interface Phantom {
135
- solana: Solana;
136
- }
137
- }
138
-
139
- export { PhantomSolanaProvider, SolanaSignInData, createSolanaPlugin };