@phantom/browser-sdk 0.0.10 → 0.2.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.10",
3
+ "version": "0.2.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,50 +10,46 @@
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
- "./extension": {
19
- "import": "./dist/extension/index.mjs",
20
- "require": "./dist/extension/index.js",
21
- "types": "./dist/extension/index.d.ts"
22
- },
23
- "./auto-confirm": {
24
- "import": "./dist/auto-confirm/index.mjs",
25
- "require": "./dist/auto-confirm/index.js",
26
- "types": "./dist/auto-confirm/index.d.ts"
27
13
  }
28
14
  },
29
15
  "files": [
30
16
  "dist"
31
17
  ],
32
- "license": "MIT",
33
18
  "scripts": {
34
19
  "?pack-release": "When https://github.com/changesets/changesets/issues/432 has a solution we can remove this trick",
35
20
  "pack-release": "rimraf ./_release && yarn pack && mkdir ./_release && tar zxvf ./package.tgz --directory ./_release && rm ./package.tgz",
36
- "build": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/extension/index.ts src/auto-confirm/index.ts --format cjs,esm --dts",
37
- "build:watch": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/extension/index.ts src/auto-confirm/index.ts --format cjs,esm --dts --watch",
38
- "dev": "rimraf ./dist && tsup src/index.ts src/solana/index.ts src/extension/index.ts src/auto-confirm/index.ts --format cjs,esm --dts --watch",
21
+ "build": "rimraf ./dist && tsup",
22
+ "dev": "rimraf ./dist && tsup --watch",
23
+ "clean": "rm -rf dist",
24
+ "test": "jest",
25
+ "test:watch": "jest --watch",
39
26
  "lint": "tsc --noEmit && eslint --cache . --ext .ts,.tsx",
40
- "test": "jest"
27
+ "prettier": "prettier --write \"src/**/*.{ts,tsx}\""
28
+ },
29
+ "dependencies": {
30
+ "@phantom/api-key-stamper": "^0.1.0",
31
+ "@phantom/base64url": "^0.1.0",
32
+ "@phantom/browser-injected-sdk": "^0.0.9",
33
+ "@phantom/client": "^0.1.0",
34
+ "axios": "^1.10.0",
35
+ "bs58": "^6.0.0",
36
+ "buffer": "^6.0.3",
37
+ "jose": "^6.0.12",
38
+ "tweetnacl": "^1.0.3"
41
39
  },
42
40
  "devDependencies": {
43
- "@solana/web3.js": "^1.98.2",
44
- "@types/jest": "^29.5.14",
41
+ "@types/jest": "^29.5.12",
42
+ "@types/node": "^20.11.0",
45
43
  "eslint": "8.53.0",
46
- "jest": "^29.7.0",
44
+ "fake-indexeddb": "^4.0.2",
45
+ "jest": "^30.0.5",
46
+ "jest-environment-jsdom": "^30.0.5",
47
+ "prettier": "^3.5.2",
47
48
  "rimraf": "^6.0.1",
49
+ "ts-jest": "^29.1.2",
48
50
  "tsup": "^6.7.0",
49
51
  "typescript": "^5.0.4"
50
52
  },
51
- "dependencies": {
52
- "@solana/compat": "2.1.1",
53
- "@solana/kit": "^2.1.1",
54
- "@solana/transactions": "^2.1.1"
55
- },
56
53
  "publishConfig": {
57
54
  "directory": "_release/package"
58
55
  }
@@ -1,10 +0,0 @@
1
- import { A as AutoConfirmPlugin } from '../index-52a9bded.js';
2
- export { e as AutoConfirmEnableParams, f as AutoConfirmResult, g as AutoConfirmSupportedChainsResult, N as NetworkID, d as createAutoConfirmPlugin } from '../index-52a9bded.js';
3
- import '@solana/kit';
4
- import '@solana/web3.js';
5
-
6
- declare module "../index" {
7
- interface Phantom {
8
- autoConfirm: AutoConfirmPlugin;
9
- }
10
- }
@@ -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,10 +0,0 @@
1
- import { E as Extension } from '../index-52a9bded.js';
2
- export { b as createExtensionPlugin } from '../index-52a9bded.js';
3
- import '@solana/kit';
4
- import '@solana/web3.js';
5
-
6
- declare module "../index" {
7
- interface Phantom {
8
- extension: Extension;
9
- }
10
- }
@@ -1,50 +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/extension/index.ts
21
- var extension_exports = {};
22
- __export(extension_exports, {
23
- createExtensionPlugin: () => createExtensionPlugin
24
- });
25
- module.exports = __toCommonJS(extension_exports);
26
-
27
- // src/extension/isInstalled.ts
28
- function isInstalled() {
29
- try {
30
- const phantom = window.phantom;
31
- return !!phantom;
32
- } catch (error) {
33
- return false;
34
- }
35
- }
36
-
37
- // src/extension/plugin.ts
38
- var extension = {
39
- isInstalled
40
- };
41
- function createExtensionPlugin() {
42
- return {
43
- name: "extension",
44
- create: () => extension
45
- };
46
- }
47
- // Annotate the CommonJS export names for ESM import in node:
48
- 0 && (module.exports = {
49
- createExtensionPlugin
50
- });
@@ -1,25 +0,0 @@
1
- import "../chunk-GV6AIHPN.mjs";
2
-
3
- // src/extension/isInstalled.ts
4
- function isInstalled() {
5
- try {
6
- const phantom = window.phantom;
7
- return !!phantom;
8
- } catch (error) {
9
- return false;
10
- }
11
- }
12
-
13
- // src/extension/plugin.ts
14
- var extension = {
15
- isInstalled
16
- };
17
- function createExtensionPlugin() {
18
- return {
19
- name: "extension",
20
- create: () => extension
21
- };
22
- }
23
- export {
24
- createExtensionPlugin
25
- };
@@ -1,182 +0,0 @@
1
- import { Transaction as Transaction$1 } from '@solana/kit';
2
- import { VersionedTransaction as VersionedTransaction$1 } from '@solana/web3.js';
3
-
4
- declare function isInstalled(): boolean;
5
-
6
- type Extension = {
7
- isInstalled: typeof isInstalled;
8
- };
9
- declare function createExtensionPlugin(): Plugin<Extension>;
10
-
11
- declare function connect(): Promise<string | undefined>;
12
-
13
- declare function disconnect(): Promise<void>;
14
-
15
- type Transaction = {
16
- message: Uint8Array;
17
- recentBlockhash: string;
18
- feePayer: string;
19
- instructions: any[];
20
- signers: string[];
21
- version: number;
22
- };
23
- type VersionedTransaction = {
24
- signatures: Uint8Array[];
25
- message: {
26
- deserialize: (serializedTransaction: Uint8Array) => VersionedTransaction;
27
- serialize: (transaction: VersionedTransaction) => Uint8Array;
28
- };
29
- };
30
- type SendOptions = {
31
- skipPreflight?: boolean;
32
- preflightCommitment?: string;
33
- maxRetries?: number;
34
- minContextSlot?: number;
35
- };
36
- type PublicKey = {
37
- toString: () => string;
38
- toBase58: () => string;
39
- };
40
- type SolanaSignInData = {
41
- domain?: string;
42
- address?: string;
43
- statement?: string;
44
- uri?: string;
45
- version?: string;
46
- chainId?: string;
47
- nonce?: string;
48
- issuedAt?: string;
49
- expirationTime?: string;
50
- notBefore?: string;
51
- requestId?: string;
52
- resources?: string[];
53
- };
54
- type DisplayEncoding = "utf8" | "hex";
55
- type PhantomEventType = "connect" | "disconnect" | "accountChanged";
56
- interface PhantomSolanaProvider {
57
- isPhantom: boolean;
58
- publicKey: PublicKey | null;
59
- isConnected: boolean;
60
- connect: (opts?: {
61
- onlyIfTrusted?: boolean;
62
- }) => Promise<{
63
- publicKey: PublicKey;
64
- }>;
65
- disconnect: () => Promise<void>;
66
- signMessage: (message: Uint8Array, display?: DisplayEncoding) => Promise<{
67
- signature: Uint8Array;
68
- publicKey: PublicKey;
69
- }>;
70
- signIn: (signInData: SolanaSignInData) => Promise<{
71
- address: PublicKey;
72
- signature: Uint8Array;
73
- signedMessage: Uint8Array;
74
- }>;
75
- signAndSendTransaction: (transaction: Transaction | VersionedTransaction, options?: SendOptions) => Promise<{
76
- signature: string;
77
- publicKey?: string;
78
- }>;
79
- signAllTransactions: (transactions: (Transaction | VersionedTransaction)[]) => Promise<(Transaction | VersionedTransaction)[]>;
80
- signTransaction: (transaction: Transaction | VersionedTransaction) => Promise<Transaction | VersionedTransaction>;
81
- on: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
82
- off: (event: "connect" | "disconnect" | "accountChanged", handler: (publicKey?: PublicKey) => void) => void;
83
- }
84
-
85
- type ConnectCallback = (publicKey: string) => void;
86
- type DisconnectCallback = () => void;
87
- type AccountChangedCallback = (publicKey: string) => void;
88
- type PhantomEventCallback = ConnectCallback | DisconnectCallback | AccountChangedCallback;
89
-
90
- declare function getAccount(): Promise<string | undefined>;
91
-
92
- /**
93
- * Signs and sends a transaction using the Phantom provider.
94
- * @param transaction The transaction to sign and send.
95
- * @returns A promise that resolves with the transaction signature and optionally the public key.
96
- * @throws Error if Phantom provider is not found or if the operation fails.
97
- */
98
- declare function signAndSendTransaction(transaction: Transaction$1 | VersionedTransaction$1): Promise<{
99
- signature: string;
100
- address?: string;
101
- }>;
102
-
103
- /**
104
- * Signs in with Solana using the Phantom provider.
105
- * @param signInData The sign-in data.
106
- * @returns A promise that resolves with the address, signature, and signed message.
107
- * @throws Error if Phantom provider is not found or if the operation fails.
108
- */
109
- declare function signIn(signInData: SolanaSignInData): Promise<{
110
- address: string;
111
- signature: Uint8Array;
112
- signedMessage: Uint8Array;
113
- }>;
114
-
115
- /**
116
- * Signs a message using the Phantom provider.
117
- * @param message The message to sign (as a Uint8Array).
118
- * @param display The display encoding for the message (optional, defaults to utf8).
119
- * @returns A promise that resolves with the signature and public key.
120
- * @throws Error if Phantom provider is not found or if the operation fails.
121
- */
122
- declare function signMessage(message: Uint8Array, display?: DisplayEncoding): Promise<{
123
- signature: Uint8Array;
124
- address: string;
125
- }>;
126
-
127
- type Solana = {
128
- connect: typeof connect;
129
- disconnect: typeof disconnect;
130
- getAccount: typeof getAccount;
131
- signMessage: typeof signMessage;
132
- signIn: typeof signIn;
133
- signAndSendTransaction: typeof signAndSendTransaction;
134
- addEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => () => void;
135
- removeEventListener: (event: PhantomEventType, callback: PhantomEventCallback) => void;
136
- };
137
- declare function createSolanaPlugin(): Plugin<Solana>;
138
-
139
- 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";
140
- type AutoConfirmEnableParams = {
141
- chains?: NetworkID[];
142
- };
143
- type AutoConfirmResult = {
144
- enabled: boolean;
145
- chains: NetworkID[];
146
- };
147
- type AutoConfirmSupportedChainsResult = {
148
- chains: NetworkID[];
149
- };
150
-
151
- declare function autoConfirmEnable(params?: AutoConfirmEnableParams): Promise<AutoConfirmResult>;
152
-
153
- declare function autoConfirmDisable(): Promise<AutoConfirmResult>;
154
-
155
- declare function autoConfirmStatus(): Promise<AutoConfirmResult>;
156
-
157
- declare function autoConfirmSupportedChains(): Promise<AutoConfirmSupportedChainsResult>;
158
-
159
- type AutoConfirmPlugin = {
160
- autoConfirmEnable: typeof autoConfirmEnable;
161
- autoConfirmDisable: typeof autoConfirmDisable;
162
- autoConfirmStatus: typeof autoConfirmStatus;
163
- autoConfirmSupportedChains: typeof autoConfirmSupportedChains;
164
- };
165
- declare function createAutoConfirmPlugin(): Plugin<AutoConfirmPlugin>;
166
-
167
- type Plugin<T> = {
168
- name: string;
169
- create: () => T;
170
- };
171
- type CreatePhantomConfig = {
172
- plugins?: Plugin<Solana | Extension | AutoConfirmPlugin>[];
173
- };
174
- interface Phantom {
175
- }
176
- /**
177
- * Creates a Phantom instance with the provided plugins.
178
- * Each plugin extends the Phantom interface via declaration merging.
179
- */
180
- declare function createPhantom({ plugins }: CreatePhantomConfig): Phantom;
181
-
182
- export { AutoConfirmPlugin as A, CreatePhantomConfig as C, Extension as E, NetworkID as N, PhantomSolanaProvider as P, Solana as S, SolanaSignInData as a, createExtensionPlugin as b, createSolanaPlugin as c, createAutoConfirmPlugin as d, AutoConfirmEnableParams as e, AutoConfirmResult as f, AutoConfirmSupportedChainsResult as g, Plugin as h, Phantom as i, createPhantom as j };
@@ -1,10 +0,0 @@
1
- import { S as Solana } from '../index-52a9bded.js';
2
- export { P as PhantomSolanaProvider, a as SolanaSignInData, c as createSolanaPlugin } from '../index-52a9bded.js';
3
- import '@solana/kit';
4
- import '@solana/web3.js';
5
-
6
- declare module "../index" {
7
- interface Phantom {
8
- solana: Solana;
9
- }
10
- }