@xrpl-wallet-kit/adapter-privy 0.3.4 → 0.3.5
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 +12 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +24 -16
- package/dist/privy-provider.d.ts +3 -0
- package/dist/privy-provider.d.ts.map +1 -0
- package/dist/privy-provider.js +4 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PrivyAdapterOptions } from "@xrpl-commons/xrpl-connect-privy";
|
|
2
2
|
import { BaseWalletAdapter } from "@xrpl-wallet-kit/core";
|
|
3
3
|
import type { ConnectOptions, SignAndSubmitRequest, SignTransactionRequest, WalletCapabilities, WalletInteraction, WalletNetwork, WalletSession } from "@xrpl-wallet-kit/core";
|
|
4
|
-
|
|
5
|
-
type
|
|
6
|
-
export type CreatePrivyAdapterOptions = Pick<PrivyAdapterOptions, "appId" | "clientId" | "redirectUri"> & {
|
|
4
|
+
import { loadPrivyProvider } from "./privy-provider.js";
|
|
5
|
+
export type CreatePrivyAdapterOptions = Pick<PrivyAdapterOptions, "appId" | "clientId"> & {
|
|
7
6
|
onDisconnected?: () => void;
|
|
8
|
-
}
|
|
7
|
+
} & ({
|
|
8
|
+
emailOnly: true;
|
|
9
|
+
redirectUri?: string;
|
|
10
|
+
} | {
|
|
11
|
+
emailOnly?: false;
|
|
12
|
+
redirectUri: string;
|
|
13
|
+
});
|
|
9
14
|
export declare class PrivyAdapter extends BaseWalletAdapter {
|
|
10
15
|
private readonly options;
|
|
11
16
|
private readonly loadProvider;
|
|
@@ -25,8 +30,9 @@ export declare class PrivyAdapter extends BaseWalletAdapter {
|
|
|
25
30
|
private signing?;
|
|
26
31
|
private teardown?;
|
|
27
32
|
private connectionPromptError?;
|
|
28
|
-
constructor(options: CreatePrivyAdapterOptions, loadProvider?:
|
|
33
|
+
constructor(options: CreatePrivyAdapterOptions, loadProvider?: typeof loadPrivyProvider);
|
|
29
34
|
private invalidConfiguration;
|
|
35
|
+
private resolveRedirectUri;
|
|
30
36
|
private getProvider;
|
|
31
37
|
private handlePrompt;
|
|
32
38
|
isAvailable(): boolean;
|
|
@@ -109,5 +115,4 @@ export declare class PrivyAdapter extends BaseWalletAdapter {
|
|
|
109
115
|
}>;
|
|
110
116
|
}
|
|
111
117
|
export declare function createPrivyAdapter(options: CreatePrivyAdapterOptions): PrivyAdapter;
|
|
112
|
-
export {};
|
|
113
118
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAwC,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAClH,OAAO,EAAE,iBAAiB,EAA2E,MAAM,uBAAuB,CAAC;AACnI,OAAO,KAAK,EAAE,cAAc,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE/K,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,mBAAmB,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG;IACxF,cAAc,CAAC,EAAE,MAAM,IAAI,CAAC;CAC7B,GAAG,CAAC;IAAE,SAAS,EAAE,IAAI,CAAC;IAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,SAAS,CAAC,EAAE,KAAK,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAsB7F,qBAAa,YAAa,SAAQ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O,EAAE,yBAAyB,gBAAuC"}
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { BaseWalletAdapter, createWalletError, getNetworkFamily, WalletKitError, WalletKitErrorCode } from "@xrpl-wallet-kit/core";
|
|
2
2
|
import { PRIVY_ICON } from "./icon.js";
|
|
3
|
-
|
|
4
|
-
const { PrivyAdapter: Provider } = await import("@xrpl-commons/xrpl-connect-privy");
|
|
5
|
-
return new Provider(options);
|
|
6
|
-
};
|
|
3
|
+
import { loadPrivyProvider } from "./privy-provider.js";
|
|
7
4
|
function resolveNetwork(network) {
|
|
8
5
|
if (!network || getNetworkFamily(network) !== "xrpl" ||
|
|
9
6
|
!((network.id === "mainnet" && network.networkType === "MAINNET" && (network.networkId ?? 0) === 0) ||
|
|
@@ -36,25 +33,34 @@ export class PrivyAdapter extends BaseWalletAdapter {
|
|
|
36
33
|
};
|
|
37
34
|
this.restoreSessionTimeoutMs = 30000;
|
|
38
35
|
this.listeners = new Set();
|
|
36
|
+
if (!options.appId.trim() || (!options.emailOnly && !options.redirectUri))
|
|
37
|
+
throw this.invalidConfiguration();
|
|
38
|
+
if (options.redirectUri !== undefined)
|
|
39
|
+
this.resolveRedirectUri(options.redirectUri);
|
|
40
|
+
this.metadata = { id: "privy", name: "Privy", type: "embedded", icon: PRIVY_ICON, homepage: "https://privy.io" };
|
|
41
|
+
}
|
|
42
|
+
invalidConfiguration() {
|
|
43
|
+
return new WalletKitError(WalletKitErrorCode.INVALID_REQUEST, "Privy requires a public App ID and an absolute same-origin callback URL.");
|
|
44
|
+
}
|
|
45
|
+
resolveRedirectUri(uri = this.options.redirectUri) {
|
|
39
46
|
let redirect;
|
|
40
47
|
try {
|
|
41
|
-
redirect =
|
|
48
|
+
redirect = uri === undefined && this.options.emailOnly && typeof window !== "undefined"
|
|
49
|
+
? new URL(window.location.pathname, window.location.origin)
|
|
50
|
+
: new URL(uri ?? "");
|
|
42
51
|
}
|
|
43
52
|
catch {
|
|
44
53
|
throw this.invalidConfiguration();
|
|
45
54
|
}
|
|
46
|
-
if (
|
|
47
|
-
|
|
48
|
-
(typeof window !== "undefined" && redirect.origin !== window.location.origin)) {
|
|
55
|
+
if (redirect.username || redirect.password || !["http:", "https:"].includes(redirect.protocol) ||
|
|
56
|
+
(typeof window !== "undefined" && redirect.origin !== window.location.origin))
|
|
49
57
|
throw this.invalidConfiguration();
|
|
50
|
-
|
|
51
|
-
this.metadata = { id: "privy", name: "Privy", type: "embedded", icon: PRIVY_ICON, homepage: "https://privy.io" };
|
|
52
|
-
}
|
|
53
|
-
invalidConfiguration() {
|
|
54
|
-
return new WalletKitError(WalletKitErrorCode.INVALID_REQUEST, "Privy requires a public App ID and an absolute same-origin callback URL.");
|
|
58
|
+
return redirect.href;
|
|
55
59
|
}
|
|
56
60
|
getProvider() {
|
|
57
|
-
this.provider ?? (this.provider = this.loadProvider(
|
|
61
|
+
this.provider ?? (this.provider = this.loadProvider({
|
|
62
|
+
appId: this.options.appId, clientId: this.options.clientId, redirectUri: this.resolveRedirectUri()
|
|
63
|
+
}).then(provider => {
|
|
58
64
|
if (this.options.onDisconnected)
|
|
59
65
|
provider.on("disconnect", this.options.onDisconnected);
|
|
60
66
|
provider.onAuthPrompt(prompt => this.handlePrompt(prompt));
|
|
@@ -136,7 +142,8 @@ export class PrivyAdapter extends BaseWalletAdapter {
|
|
|
136
142
|
const available = await provider.getLoginMethods({ signal });
|
|
137
143
|
if (signal.aborted)
|
|
138
144
|
throw rejected();
|
|
139
|
-
const
|
|
145
|
+
const allowed = this.options.emailOnly ? ["email"] : ["email", "google", "twitter", "x"];
|
|
146
|
+
const methods = available.filter(method => allowed.includes(method.id));
|
|
140
147
|
const loginMethod = methods.length === 1 && methods[0].id === "email" ? "email" : await this.choose(methods);
|
|
141
148
|
if (signal.aborted)
|
|
142
149
|
throw rejected();
|
|
@@ -200,7 +207,8 @@ export class PrivyAdapter extends BaseWalletAdapter {
|
|
|
200
207
|
return null;
|
|
201
208
|
}
|
|
202
209
|
async canRecoverSession() {
|
|
203
|
-
if (typeof window === "undefined" ||
|
|
210
|
+
if (this.options.emailOnly || typeof window === "undefined" ||
|
|
211
|
+
window.location.pathname !== new URL(this.resolveRedirectUri()).pathname)
|
|
204
212
|
return false;
|
|
205
213
|
return (await this.getProvider()).hasPendingConnection();
|
|
206
214
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"privy-provider.d.ts","sourceRoot":"","sources":["../src/privy-provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAE5E,wBAAsB,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,oEAGnE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xrpl-wallet-kit/adapter-privy",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "Opt-in Privy embedded XRPL wallet adapter.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"files": ["dist", "README.md"],
|
|
12
12
|
"scripts": { "build": "tsc -p tsconfig.json" },
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@xrpl-wallet-kit/core": "0.3.
|
|
14
|
+
"@xrpl-wallet-kit/core": "0.3.5",
|
|
15
15
|
"@xrpl-commons/xrpl-connect-privy": "1.1.0-rc.0",
|
|
16
16
|
"xrpl-connect": "1.1.0-rc.0"
|
|
17
17
|
},
|