@multiplatform.one/web3 7.33.1 → 7.34.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/README.md +24 -6
- package/dist/cjs/phantom/crypto.cjs +108 -0
- package/dist/cjs/phantom/crypto.native.js +224 -0
- package/dist/cjs/phantom/crypto.native.js.map +1 -0
- package/dist/cjs/phantom/index.cjs +16 -1
- package/dist/cjs/phantom/index.native.js +16 -1
- package/dist/cjs/phantom/index.native.js.map +1 -1
- package/dist/cjs/phantom/solana.cjs +309 -0
- package/dist/cjs/phantom/solana.native.js +466 -0
- package/dist/cjs/phantom/solana.native.js.map +1 -0
- package/dist/cjs/phantom/urls.cjs +68 -3
- package/dist/cjs/phantom/urls.native.js +92 -4
- package/dist/cjs/phantom/urls.native.js.map +1 -1
- package/dist/esm/phantom/crypto.mjs +67 -0
- package/dist/esm/phantom/crypto.mjs.map +1 -0
- package/dist/esm/phantom/crypto.native.js +180 -0
- package/dist/esm/phantom/crypto.native.js.map +1 -0
- package/dist/esm/phantom/index.mjs +4 -2
- package/dist/esm/phantom/index.mjs.map +1 -1
- package/dist/esm/phantom/index.native.js +4 -2
- package/dist/esm/phantom/index.native.js.map +1 -1
- package/dist/esm/phantom/solana.mjs +271 -0
- package/dist/esm/phantom/solana.mjs.map +1 -0
- package/dist/esm/phantom/solana.native.js +425 -0
- package/dist/esm/phantom/solana.native.js.map +1 -0
- package/dist/esm/phantom/urls.mjs +53 -3
- package/dist/esm/phantom/urls.mjs.map +1 -1
- package/dist/esm/phantom/urls.native.js +77 -4
- package/dist/esm/phantom/urls.native.js.map +1 -1
- package/dist/jsx/phantom/crypto.mjs +67 -0
- package/dist/jsx/phantom/crypto.mjs.map +1 -0
- package/dist/jsx/phantom/crypto.native.js +224 -0
- package/dist/jsx/phantom/crypto.native.js.map +1 -0
- package/dist/jsx/phantom/index.mjs +4 -2
- package/dist/jsx/phantom/index.mjs.map +1 -1
- package/dist/jsx/phantom/index.native.js +16 -1
- package/dist/jsx/phantom/index.native.js.map +1 -1
- package/dist/jsx/phantom/solana.mjs +271 -0
- package/dist/jsx/phantom/solana.mjs.map +1 -0
- package/dist/jsx/phantom/solana.native.js +466 -0
- package/dist/jsx/phantom/solana.native.js.map +1 -0
- package/dist/jsx/phantom/urls.mjs +53 -3
- package/dist/jsx/phantom/urls.mjs.map +1 -1
- package/dist/jsx/phantom/urls.native.js +92 -4
- package/dist/jsx/phantom/urls.native.js.map +1 -1
- package/package.json +7 -6
- package/src/phantom/crypto.spec.ts +61 -0
- package/src/phantom/crypto.ts +88 -0
- package/src/phantom/index.ts +38 -5
- package/src/phantom/solana.spec.ts +262 -0
- package/src/phantom/solana.ts +374 -0
- package/src/phantom/urls.spec.ts +101 -10
- package/src/phantom/urls.ts +119 -4
- package/types/phantom/crypto.d.ts +27 -0
- package/types/phantom/crypto.d.ts.map +1 -0
- package/types/phantom/index.d.ts +3 -1
- package/types/phantom/index.d.ts.map +1 -1
- package/types/phantom/solana.d.ts +113 -0
- package/types/phantom/solana.d.ts.map +1 -0
- package/types/phantom/urls.d.ts +46 -2
- package/types/phantom/urls.d.ts.map +1 -1
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { type PhantomCluster, type PhantomMethod } from "./urls";
|
|
2
|
+
/** The slice of the Web Storage API the session needs. */
|
|
3
|
+
export interface PhantomStorage {
|
|
4
|
+
getItem(key: string): string | null;
|
|
5
|
+
setItem(key: string, value: string): void;
|
|
6
|
+
removeItem(key: string): void;
|
|
7
|
+
}
|
|
8
|
+
/** What is kept between the tap and the return. Base58 throughout. */
|
|
9
|
+
export interface PhantomSessionRecord {
|
|
10
|
+
dappSecretKey: string;
|
|
11
|
+
cluster?: PhantomCluster;
|
|
12
|
+
phantomEncryptionPublicKey?: string;
|
|
13
|
+
session?: string;
|
|
14
|
+
publicKey?: string;
|
|
15
|
+
pending?: {
|
|
16
|
+
method: PhantomMethod;
|
|
17
|
+
at: number;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface PhantomDeeplinkConfig {
|
|
21
|
+
/** Stored in Phantom's session and checked against its blocklist. */
|
|
22
|
+
appUrl: string;
|
|
23
|
+
/**
|
|
24
|
+
* Where Phantom returns. Defaults to the current page without Phantom's
|
|
25
|
+
* parameters. An https link shows the app's name and icon in Phantom and
|
|
26
|
+
* returns to the phone's browser; a custom scheme returns to an app, which
|
|
27
|
+
* must hand the URL to `handleRedirect` in a page with the same storage.
|
|
28
|
+
*/
|
|
29
|
+
redirectLink?: string;
|
|
30
|
+
cluster?: PhantomCluster;
|
|
31
|
+
/**
|
|
32
|
+
* Must outlive the trip to Phantom: on Android the return can land in a new
|
|
33
|
+
* browser tab. Defaults to localStorage.
|
|
34
|
+
*/
|
|
35
|
+
storage?: PhantomStorage;
|
|
36
|
+
storageKey?: string;
|
|
37
|
+
/** Defaults to `location.assign`. Called synchronously inside the request method. */
|
|
38
|
+
navigate?: (url: string) => void;
|
|
39
|
+
/** Overrides https://phantom.com/ul. */
|
|
40
|
+
base?: string;
|
|
41
|
+
now?: () => number;
|
|
42
|
+
}
|
|
43
|
+
export type PhantomRedirectResult = {
|
|
44
|
+
ok: true;
|
|
45
|
+
method: "connect";
|
|
46
|
+
publicKey: string;
|
|
47
|
+
session: string;
|
|
48
|
+
} | {
|
|
49
|
+
ok: true;
|
|
50
|
+
method: "signTransaction";
|
|
51
|
+
transaction: Uint8Array;
|
|
52
|
+
} | {
|
|
53
|
+
ok: true;
|
|
54
|
+
method: "signAllTransactions";
|
|
55
|
+
transactions: Uint8Array[];
|
|
56
|
+
} | {
|
|
57
|
+
ok: true;
|
|
58
|
+
method: "signAndSendTransaction";
|
|
59
|
+
signature: string;
|
|
60
|
+
} | {
|
|
61
|
+
ok: true;
|
|
62
|
+
method: "signMessage";
|
|
63
|
+
signature: Uint8Array;
|
|
64
|
+
} | {
|
|
65
|
+
ok: false;
|
|
66
|
+
method: PhantomMethod | undefined;
|
|
67
|
+
errorCode: string;
|
|
68
|
+
errorMessage: string;
|
|
69
|
+
};
|
|
70
|
+
export declare class PhantomNotConnectedError extends Error {
|
|
71
|
+
constructor();
|
|
72
|
+
}
|
|
73
|
+
export interface PhantomDeeplink {
|
|
74
|
+
/** The connected wallet's base58 address, once a connect has come back. */
|
|
75
|
+
readonly publicKey: string | undefined;
|
|
76
|
+
readonly connected: boolean;
|
|
77
|
+
/** The request still waiting for Phantom's answer, if any. */
|
|
78
|
+
readonly pending: PhantomSessionRecord["pending"];
|
|
79
|
+
/**
|
|
80
|
+
* Each request below builds its link from what is already stored and
|
|
81
|
+
* navigates before returning, with nothing awaited, so it runs inside the
|
|
82
|
+
* tap's user activation and the browser follows the link without asking.
|
|
83
|
+
* The link is returned too, for an `<a href>`.
|
|
84
|
+
*/
|
|
85
|
+
connect(): string;
|
|
86
|
+
signTransaction(serializedTransaction: Uint8Array): string;
|
|
87
|
+
signAllTransactions(serializedTransactions: Uint8Array[]): string;
|
|
88
|
+
/** Deprecated by Phantom: prefer signTransaction and sendSolanaTransaction. */
|
|
89
|
+
signAndSendTransaction(serializedTransaction: Uint8Array, sendOptions?: Record<string, unknown>): string;
|
|
90
|
+
signMessage(message: Uint8Array | string, display?: "utf8" | "hex"): string;
|
|
91
|
+
/** Forgets the session here at once, then tells Phantom. */
|
|
92
|
+
disconnect(): string;
|
|
93
|
+
/**
|
|
94
|
+
* Reads Phantom's answer off the return URL (the current one by default)
|
|
95
|
+
* and updates the stored session. Undefined when the URL carries none.
|
|
96
|
+
* Throws PhantomDecryptError when the answer was not sealed for this
|
|
97
|
+
* session's key.
|
|
98
|
+
*/
|
|
99
|
+
handleRedirect(href?: string): PhantomRedirectResult | undefined;
|
|
100
|
+
/** Drops the stored keypair and session without asking Phantom. */
|
|
101
|
+
forget(): void;
|
|
102
|
+
}
|
|
103
|
+
/** A Solana wallet in the Phantom app, reached from a phone's browser through Phantom's encrypted deeplinks. */
|
|
104
|
+
export declare function phantomDeeplink(config: PhantomDeeplinkConfig): PhantomDeeplink;
|
|
105
|
+
/**
|
|
106
|
+
* Broadcasts a transaction Phantom signed (signTransaction's answer) through
|
|
107
|
+
* a Solana JSON-RPC endpoint and returns its base58 signature.
|
|
108
|
+
*/
|
|
109
|
+
export declare function sendSolanaTransaction(rpcUrl: string, signedTransaction: Uint8Array, options?: {
|
|
110
|
+
skipPreflight?: boolean;
|
|
111
|
+
fetch?: typeof fetch;
|
|
112
|
+
}): Promise<string>;
|
|
113
|
+
//# sourceMappingURL=solana.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"solana.d.ts","sourceRoot":"","sources":["../../src/phantom/solana.ts"],"names":[],"mappings":"AAOA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,aAAa,EACnB,MAAM,QAAQ,CAAC;AAEhB,0DAA0D;AAC1D,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IACpC,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1C,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED,sEAAsE;AACtE,MAAM,WAAW,oBAAoB;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,CAAC,EAAE;QAAE,MAAM,EAAE,aAAa,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;CACjD;AAED,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,MAAM,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB;;;OAGG;IACH,OAAO,C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ClD;;;;;OAKG;IACH,OAAO,IAAI,MAAM,CAAC;IAClB,eAAe,CAAC,qBAAqB,EAAE,UAAU,GAAG,MAAM,CAAC;IAC3D,mBAAmB,CAAC,sBAAsB,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IAClE,+EAA+E;IAC/E,sBAAsB,CACpB,qBAAqB,EAAE,UAAU,EACjC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACpC,MAAM,CAAC;IACV,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,MAAM,CAAC;IAC5E,4DAA4D;IAC5D,UAAU,IAAI,MAAM,CAAC;IACrB;;;;;OAKG;IACH,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,qBAAqB,GAAG,SAAS,CAAC;IACjE,mEAAmE;IACnE,MAAM,IAAI,IAAI,CAAC;CAChB;AAgBD,gHAAgH;AAChH,wBAAgB,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,eAAe,CAyM9E;AAQD;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,MAAM,EACd,iBAAiB,EAAE,UAAU,EAC7B,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;CAAO,GAC9D,OAAO,CAAC,MAAM,CAAC,CAyBjB"}
|
package/types/phantom/urls.d.ts
CHANGED
|
@@ -1,11 +1,55 @@
|
|
|
1
1
|
/** Phantom's universal-link host. `https://phantom.app/ul` still answers; Phantom asks new code to use this one. */
|
|
2
2
|
export declare const phantomUniversalLinkBase = "https://phantom.com/ul";
|
|
3
|
+
export type PhantomCluster = "mainnet-beta" | "testnet" | "devnet";
|
|
4
|
+
/**
|
|
5
|
+
* Deeplink provider methods, all Solana-only. `signAndSendTransaction` is
|
|
6
|
+
* deprecated by Phantom in favour of `signTransaction` and a broadcast by the
|
|
7
|
+
* page, and is kept for wallets that still honour it.
|
|
8
|
+
*/
|
|
9
|
+
export type PhantomMethod = "connect" | "disconnect" | "signTransaction" | "signAllTransactions" | "signAndSendTransaction" | "signMessage";
|
|
3
10
|
/**
|
|
4
11
|
* Opens `url` inside Phantom's in-app browser, where Phantom injects
|
|
5
|
-
* `window.phantom.ethereum`. Phantom's deeplinks
|
|
6
|
-
* this is how a phone's browser reaches its EVM wallet.
|
|
12
|
+
* `window.phantom.ethereum` and `window.phantom.solana`. Phantom's deeplinks
|
|
13
|
+
* carry no EVM methods, so this is how a phone's browser reaches its EVM wallet.
|
|
7
14
|
*/
|
|
8
15
|
export declare function phantomBrowseUrl(url: string, ref: string, options?: {
|
|
9
16
|
base?: string;
|
|
10
17
|
}): string;
|
|
18
|
+
export interface PhantomConnectUrlParams {
|
|
19
|
+
appUrl: string;
|
|
20
|
+
dappEncryptionPublicKey: Uint8Array;
|
|
21
|
+
redirectLink: string;
|
|
22
|
+
cluster?: PhantomCluster;
|
|
23
|
+
base?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function phantomConnectUrl(params: PhantomConnectUrlParams): string;
|
|
26
|
+
export interface PhantomMethodUrlParams {
|
|
27
|
+
method: Exclude<PhantomMethod, "connect">;
|
|
28
|
+
/** The fields the method's payload carries besides `session`. */
|
|
29
|
+
payload: Record<string, unknown>;
|
|
30
|
+
session: string;
|
|
31
|
+
dappEncryptionPublicKey: Uint8Array;
|
|
32
|
+
sharedSecret: Uint8Array;
|
|
33
|
+
redirectLink: string;
|
|
34
|
+
nonce?: Uint8Array;
|
|
35
|
+
base?: string;
|
|
36
|
+
}
|
|
37
|
+
/** A provider-method link: the payload, session included, sealed with the session's shared secret. */
|
|
38
|
+
export declare function phantomMethodUrl(params: PhantomMethodUrlParams): string;
|
|
39
|
+
/** What Phantom appends to `redirect_link`. */
|
|
40
|
+
export interface PhantomRedirectParams {
|
|
41
|
+
phantomEncryptionPublicKey?: string;
|
|
42
|
+
nonce?: string;
|
|
43
|
+
data?: string;
|
|
44
|
+
errorCode?: string;
|
|
45
|
+
errorMessage?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Reads Phantom's response off the return URL. Phantom appends with `?` even
|
|
49
|
+
* when the redirect link already has a query, so every `?` after the first is
|
|
50
|
+
* read as `&`. Returns undefined when the URL carries no response.
|
|
51
|
+
*/
|
|
52
|
+
export declare function parsePhantomRedirect(href: string): PhantomRedirectParams | undefined;
|
|
53
|
+
/** `href` without Phantom's response parameters, for `history.replaceState` after handling it. */
|
|
54
|
+
export declare function stripPhantomRedirect(href: string): string;
|
|
11
55
|
//# sourceMappingURL=urls.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/phantom/urls.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"urls.d.ts","sourceRoot":"","sources":["../../src/phantom/urls.ts"],"names":[],"mappings":"AAGA,oHAAoH;AACpH,eAAO,MAAM,wBAAwB,2BAA2B,CAAC;AAEjE,MAAM,MAAM,cAAc,GAAG,cAAc,GAAG,SAAS,GAAG,QAAQ,CAAC;AAEnE;;;;GAIG;AACH,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,YAAY,GACZ,iBAAiB,GACjB,qBAAqB,GACrB,wBAAwB,GACxB,aAAa,CAAC;AAIlB;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAO,GAC9B,MAAM,CAER;AAED,MAAM,WAAW,uBAAuB;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,EAAE,UAAU,CAAC;IACpC,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,iBAAi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