@mysten/enoki 0.9.1 → 0.11.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/CHANGELOG.md +19 -0
- package/dist/cjs/EnokiClient/type.d.ts +1 -1
- package/dist/cjs/EnokiClient/type.js.map +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/wallet/features.d.ts +50 -0
- package/dist/cjs/wallet/{feature.js → features.js} +7 -5
- package/dist/cjs/wallet/features.js.map +7 -0
- package/dist/cjs/wallet/providers.js +5 -0
- package/dist/cjs/wallet/providers.js.map +2 -2
- package/dist/cjs/wallet/state.d.ts +3 -3
- package/dist/cjs/wallet/state.js +30 -32
- package/dist/cjs/wallet/state.js.map +2 -2
- package/dist/cjs/wallet/types.d.ts +24 -21
- package/dist/cjs/wallet/types.js.map +1 -1
- package/dist/cjs/wallet/utils.d.ts +3 -1
- package/dist/cjs/wallet/utils.js +24 -6
- package/dist/cjs/wallet/utils.js.map +3 -3
- package/dist/cjs/wallet/wallet.d.ts +2 -2
- package/dist/cjs/wallet/wallet.js +46 -58
- package/dist/cjs/wallet/wallet.js.map +2 -2
- package/dist/esm/EnokiClient/type.d.ts +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/wallet/features.d.ts +50 -0
- package/dist/esm/wallet/features.js +7 -0
- package/dist/esm/wallet/features.js.map +7 -0
- package/dist/esm/wallet/providers.js +5 -0
- package/dist/esm/wallet/providers.js.map +2 -2
- package/dist/esm/wallet/state.d.ts +3 -3
- package/dist/esm/wallet/state.js +32 -34
- package/dist/esm/wallet/state.js.map +2 -2
- package/dist/esm/wallet/types.d.ts +24 -21
- package/dist/esm/wallet/utils.d.ts +3 -1
- package/dist/esm/wallet/utils.js +19 -1
- package/dist/esm/wallet/utils.js.map +3 -3
- package/dist/esm/wallet/wallet.d.ts +2 -2
- package/dist/esm/wallet/wallet.js +45 -57
- package/dist/esm/wallet/wallet.js.map +2 -2
- package/dist/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/wallet/feature.d.ts +0 -31
- package/dist/cjs/wallet/feature.js.map +0 -7
- package/dist/esm/wallet/feature.d.ts +0 -31
- package/dist/esm/wallet/feature.js +0 -5
- package/dist/esm/wallet/feature.js.map +0 -7
package/dist/esm/wallet/state.js
CHANGED
|
@@ -6,33 +6,30 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
6
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
-
var _encryption, _encryptionKey,
|
|
10
|
-
import { clear, createStore } from "idb-keyval";
|
|
11
|
-
import { atom, onMount, onSet } from "nanostores";
|
|
9
|
+
var _encryption, _encryptionKey, _stateStore, _sessionContextByNetwork, _zkLoginState, _EnokiWalletState_instances, createZkLoginState_fn;
|
|
10
|
+
import { clear, createStore, del, get, set } from "idb-keyval";
|
|
11
|
+
import { atom, onMount, onSet, task } from "nanostores";
|
|
12
12
|
import { createDefaultEncryption } from "../encryption.js";
|
|
13
|
-
|
|
13
|
+
const sessionKey = "zklogin-session";
|
|
14
|
+
const stateKey = "zklogin-state";
|
|
14
15
|
class EnokiWalletState {
|
|
15
16
|
constructor(config) {
|
|
16
17
|
__privateAdd(this, _EnokiWalletState_instances);
|
|
17
18
|
__privateAdd(this, _encryption);
|
|
18
19
|
__privateAdd(this, _encryptionKey);
|
|
19
|
-
__privateAdd(this,
|
|
20
|
-
__privateAdd(this, _stateStorageKey);
|
|
20
|
+
__privateAdd(this, _stateStore);
|
|
21
21
|
__privateAdd(this, _sessionContextByNetwork);
|
|
22
22
|
__privateAdd(this, _zkLoginState);
|
|
23
23
|
__privateSet(this, _encryptionKey, config.apiKey);
|
|
24
24
|
__privateSet(this, _encryption, createDefaultEncryption());
|
|
25
|
-
__privateSet(this,
|
|
26
|
-
__privateSet(this, _stateStorageKey, `@enoki/flow/state/${config.apiKey}/${config.clientId}`);
|
|
25
|
+
__privateSet(this, _stateStore, createStore(`${config.apiKey}_${config.clientId}`, "enoki"));
|
|
27
26
|
__privateSet(this, _zkLoginState, __privateMethod(this, _EnokiWalletState_instances, createZkLoginState_fn).call(this));
|
|
28
27
|
__privateSet(this, _sessionContextByNetwork, config.clients.reduce((accumulator, client) => {
|
|
29
28
|
const network = client.network;
|
|
30
|
-
const storageKey = `@enoki/flow/session/${config.apiKey}/${network}/${config.clientId}`;
|
|
31
29
|
const idbStore = createStore(`${config.apiKey}_${network}_${config.clientId}`, "enoki");
|
|
32
30
|
const sessionContext = {
|
|
33
31
|
$zkLoginSession: atom({ initialized: false, value: null }),
|
|
34
32
|
client,
|
|
35
|
-
storageKey,
|
|
36
33
|
idbStore
|
|
37
34
|
};
|
|
38
35
|
onMount(sessionContext.$zkLoginSession, () => {
|
|
@@ -55,31 +52,31 @@ class EnokiWalletState {
|
|
|
55
52
|
return context;
|
|
56
53
|
}
|
|
57
54
|
async logout() {
|
|
58
|
-
__privateGet(this, _zkLoginState).set(
|
|
59
|
-
|
|
60
|
-
for (const
|
|
61
|
-
await
|
|
62
|
-
await
|
|
55
|
+
__privateGet(this, _zkLoginState).set(null);
|
|
56
|
+
await clear(__privateGet(this, _stateStore));
|
|
57
|
+
for (const context of __privateGet(this, _sessionContextByNetwork).values()) {
|
|
58
|
+
await this.setSession(context, null);
|
|
59
|
+
await clear(context.idbStore);
|
|
63
60
|
}
|
|
64
61
|
}
|
|
65
|
-
async setSession(
|
|
62
|
+
async setSession(context, newValue) {
|
|
66
63
|
if (newValue) {
|
|
67
64
|
const storedValue = await __privateGet(this, _encryption).encrypt(
|
|
68
65
|
__privateGet(this, _encryptionKey),
|
|
69
66
|
JSON.stringify(newValue)
|
|
70
67
|
);
|
|
71
|
-
|
|
68
|
+
await set(sessionKey, storedValue, context.idbStore);
|
|
72
69
|
} else {
|
|
73
|
-
|
|
70
|
+
await del(sessionKey, context.idbStore);
|
|
74
71
|
}
|
|
75
|
-
|
|
72
|
+
context.$zkLoginSession.set({ initialized: true, value: newValue });
|
|
76
73
|
}
|
|
77
|
-
async getSession({ $zkLoginSession,
|
|
74
|
+
async getSession({ $zkLoginSession, idbStore }) {
|
|
78
75
|
if ($zkLoginSession.get().initialized) {
|
|
79
76
|
return $zkLoginSession.get().value;
|
|
80
77
|
}
|
|
81
78
|
try {
|
|
82
|
-
const storedValue =
|
|
79
|
+
const storedValue = await get(sessionKey, idbStore);
|
|
83
80
|
if (!storedValue) return null;
|
|
84
81
|
const state = JSON.parse(
|
|
85
82
|
await __privateGet(this, _encryption).decrypt(__privateGet(this, _encryptionKey), storedValue)
|
|
@@ -97,24 +94,25 @@ class EnokiWalletState {
|
|
|
97
94
|
}
|
|
98
95
|
_encryption = new WeakMap();
|
|
99
96
|
_encryptionKey = new WeakMap();
|
|
100
|
-
|
|
101
|
-
_stateStorageKey = new WeakMap();
|
|
97
|
+
_stateStore = new WeakMap();
|
|
102
98
|
_sessionContextByNetwork = new WeakMap();
|
|
103
99
|
_zkLoginState = new WeakMap();
|
|
104
100
|
_EnokiWalletState_instances = new WeakSet();
|
|
105
101
|
createZkLoginState_fn = function() {
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
102
|
+
const $zkLoginState = atom(null);
|
|
103
|
+
onMount($zkLoginState, () => {
|
|
104
|
+
task(async () => {
|
|
105
|
+
try {
|
|
106
|
+
const rawStoredValue = await get(stateKey, __privateGet(this, _stateStore));
|
|
107
|
+
if (rawStoredValue) {
|
|
108
|
+
$zkLoginState.set(JSON.parse(rawStoredValue));
|
|
109
|
+
}
|
|
110
|
+
} catch {
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
});
|
|
116
114
|
onSet($zkLoginState, ({ newValue }) => {
|
|
117
|
-
|
|
115
|
+
set(stateKey, JSON.stringify(newValue), __privateGet(this, _stateStore));
|
|
118
116
|
});
|
|
119
117
|
return $zkLoginState;
|
|
120
118
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/wallet/state.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { clear, createStore } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, onMount, onSet } from 'nanostores';\n\nimport type { Encryption } from '../encryption.js';\nimport { createDefaultEncryption } from '../encryption.js';\nimport type { EnokiClientConfig } from '../EnokiClient/index.js';\nimport type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';\
|
|
5
|
-
"mappings": ";;;;;;;;AAAA;
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { UseStore } from 'idb-keyval';\nimport { clear, createStore, del, get, set } from 'idb-keyval';\nimport type { WritableAtom } from 'nanostores';\nimport { atom, onMount, onSet, task } from 'nanostores';\n\nimport type { Encryption } from '../encryption.js';\nimport { createDefaultEncryption } from '../encryption.js';\nimport type { EnokiClientConfig } from '../EnokiClient/index.js';\nimport type { ClientWithCoreApi, Experimental_SuiClientTypes } from '@mysten/sui/experimental';\n\nimport type { EnokiSessionContext, ZkLoginSession, ZkLoginState } from './types.js';\n\nexport type EnokiWalletStateConfig = EnokiClientConfig & {\n\tclients: ClientWithCoreApi[];\n\tclientId: string;\n};\n\nconst sessionKey = 'zklogin-session';\n\nconst stateKey = 'zklogin-state';\n\nexport class EnokiWalletState {\n\t#encryption: Encryption;\n\t#encryptionKey: string;\n\n\t#stateStore: UseStore;\n\t#sessionContextByNetwork: Map<Experimental_SuiClientTypes.Network, EnokiSessionContext>;\n\t#zkLoginState: WritableAtom<ZkLoginState | null>;\n\n\tconstructor(config: EnokiWalletStateConfig) {\n\t\tthis.#encryptionKey = config.apiKey;\n\t\tthis.#encryption = createDefaultEncryption();\n\n\t\tthis.#stateStore = createStore(`${config.apiKey}_${config.clientId}`, 'enoki');\n\t\tthis.#zkLoginState = this.#createZkLoginState();\n\n\t\tthis.#sessionContextByNetwork = config.clients.reduce((accumulator, client) => {\n\t\t\tconst network = client.network;\n\t\t\tconst idbStore = createStore(`${config.apiKey}_${network}_${config.clientId}`, 'enoki');\n\n\t\t\tconst sessionContext: EnokiSessionContext = {\n\t\t\t\t$zkLoginSession: atom({ initialized: false, value: null }),\n\t\t\t\tclient,\n\t\t\t\tidbStore,\n\t\t\t};\n\n\t\t\tonMount(sessionContext.$zkLoginSession, () => {\n\t\t\t\tthis.getSession(sessionContext);\n\t\t\t});\n\n\t\t\treturn accumulator.set(network, sessionContext);\n\t\t}, new Map());\n\t}\n\n\tget zkLoginState() {\n\t\treturn this.#zkLoginState;\n\t}\n\n\tget sessionContextByNetwork() {\n\t\treturn this.#sessionContextByNetwork;\n\t}\n\n\tgetSessionContext(network: Experimental_SuiClientTypes.Network) {\n\t\tconst context = this.#sessionContextByNetwork.get(network);\n\t\tif (!context) {\n\t\t\tthrow new Error(`The network ${network} isn't supported.`);\n\t\t}\n\n\t\treturn context;\n\t}\n\n\tasync logout() {\n\t\tthis.#zkLoginState.set(null);\n\t\tawait clear(this.#stateStore);\n\n\t\tfor (const context of this.#sessionContextByNetwork.values()) {\n\t\t\tawait this.setSession(context, null);\n\t\t\tawait clear(context.idbStore);\n\t\t}\n\t}\n\n\tasync setSession(context: EnokiSessionContext, newValue: ZkLoginSession | null) {\n\t\tif (newValue) {\n\t\t\tconst storedValue = await this.#encryption.encrypt(\n\t\t\t\tthis.#encryptionKey,\n\t\t\t\tJSON.stringify(newValue),\n\t\t\t);\n\n\t\t\tawait set(sessionKey, storedValue, context.idbStore);\n\t\t} else {\n\t\t\tawait del(sessionKey, context.idbStore);\n\t\t}\n\n\t\tcontext.$zkLoginSession.set({ initialized: true, value: newValue });\n\t}\n\n\tasync getSession({ $zkLoginSession, idbStore }: EnokiSessionContext) {\n\t\tif ($zkLoginSession.get().initialized) {\n\t\t\treturn $zkLoginSession.get().value;\n\t\t}\n\n\t\ttry {\n\t\t\tconst storedValue = await get(sessionKey, idbStore);\n\t\t\tif (!storedValue) return null;\n\n\t\t\tconst state: ZkLoginSession = JSON.parse(\n\t\t\t\tawait this.#encryption.decrypt(this.#encryptionKey, storedValue),\n\t\t\t);\n\n\t\t\tif (state?.expiresAt && Date.now() > state.expiresAt) {\n\t\t\t\tawait this.logout();\n\t\t\t} else {\n\t\t\t\t$zkLoginSession.set({ initialized: true, value: state });\n\t\t\t}\n\t\t} catch {\n\t\t\t$zkLoginSession.set({ initialized: true, value: null });\n\t\t}\n\n\t\treturn $zkLoginSession.get().value;\n\t}\n\n\t#createZkLoginState() {\n\t\tconst $zkLoginState = atom<ZkLoginState | null>(null);\n\n\t\tonMount($zkLoginState, () => {\n\t\t\ttask(async () => {\n\t\t\t\ttry {\n\t\t\t\t\tconst rawStoredValue = await get<string>(stateKey, this.#stateStore);\n\t\t\t\t\tif (rawStoredValue) {\n\t\t\t\t\t\t$zkLoginState.set(JSON.parse(rawStoredValue));\n\t\t\t\t\t}\n\t\t\t\t} catch {\n\t\t\t\t\t// Ignore errors\n\t\t\t\t}\n\t\t\t});\n\t\t});\n\n\t\tonSet($zkLoginState, ({ newValue }) => {\n\t\t\tset(stateKey, JSON.stringify(newValue), this.#stateStore);\n\t\t});\n\n\t\treturn $zkLoginState;\n\t}\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -10,8 +10,8 @@ export type WalletEventsMap = {
|
|
|
10
10
|
[E in keyof StandardEventsListeners]: Parameters<StandardEventsListeners[E]>[0];
|
|
11
11
|
};
|
|
12
12
|
export type ZkLoginState = {
|
|
13
|
-
address
|
|
14
|
-
publicKey
|
|
13
|
+
address: string;
|
|
14
|
+
publicKey: string;
|
|
15
15
|
};
|
|
16
16
|
export type ZkLoginSession = {
|
|
17
17
|
maxEpoch: number;
|
|
@@ -23,18 +23,32 @@ export type ZkLoginSession = {
|
|
|
23
23
|
export type EnokiSessionContext = {
|
|
24
24
|
idbStore: UseStore;
|
|
25
25
|
client: ClientWithCoreApi;
|
|
26
|
-
storageKey: string;
|
|
27
26
|
$zkLoginSession: WritableAtom<{
|
|
28
27
|
initialized: boolean;
|
|
29
28
|
value: ZkLoginSession | null;
|
|
30
29
|
}>;
|
|
31
30
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
type ClientConfig = {
|
|
32
|
+
/**
|
|
33
|
+
* A list of client instances to use when building and executing transactions.
|
|
34
|
+
*/
|
|
35
35
|
clients: ClientWithCoreApi[];
|
|
36
|
+
/**
|
|
37
|
+
* A function that returns the current network that the application is acting on.
|
|
38
|
+
*/
|
|
36
39
|
getCurrentNetwork: () => Experimental_SuiClientTypes.Network;
|
|
37
|
-
}
|
|
40
|
+
};
|
|
41
|
+
export type EnokiWalletOptions = {
|
|
42
|
+
/**
|
|
43
|
+
* The window features to use when opening the authorization popup.
|
|
44
|
+
* https://developer.mozilla.org/en-US/docs/Web/API/Window/open#windowfeatures
|
|
45
|
+
*/
|
|
46
|
+
windowFeatures?: string | (() => string);
|
|
47
|
+
/**
|
|
48
|
+
* The authentication provider to register the wallet for.
|
|
49
|
+
*/
|
|
50
|
+
provider: AuthProvider;
|
|
51
|
+
} & AuthProviderOptions & EnokiClientConfig & ClientConfig & Pick<Wallet, 'name' | 'icon'>;
|
|
38
52
|
export type AuthProviderOptions = {
|
|
39
53
|
/**
|
|
40
54
|
* The OAuth client ID.
|
|
@@ -49,24 +63,12 @@ export type AuthProviderOptions = {
|
|
|
49
63
|
*/
|
|
50
64
|
extraParams?: Record<string, string> | (() => Record<string, string>);
|
|
51
65
|
};
|
|
52
|
-
export type RegisterEnokiWalletsOptions =
|
|
66
|
+
export type RegisterEnokiWalletsOptions = {
|
|
53
67
|
/**
|
|
54
68
|
* Configuration for each OAuth provider.
|
|
55
69
|
*/
|
|
56
70
|
providers: Partial<Record<AuthProvider, AuthProviderOptions>>;
|
|
57
|
-
|
|
58
|
-
* The window features to use when opening the authorization popup.
|
|
59
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/Window/open#windowfeatures
|
|
60
|
-
*/
|
|
61
|
-
windowFeatures?: string | (() => string);
|
|
62
|
-
} & ({
|
|
63
|
-
/**
|
|
64
|
-
* A list of client instances to use when building and executing transactions.
|
|
65
|
-
*/
|
|
66
|
-
clients: ClientWithCoreApi[];
|
|
67
|
-
/** A function that returns the current network that the application is acting on. */
|
|
68
|
-
getCurrentNetwork: () => Experimental_SuiClientTypes.Network;
|
|
69
|
-
} | {
|
|
71
|
+
} & Pick<EnokiWalletOptions, 'apiKey' | 'apiUrl' | 'windowFeatures'> & (ClientConfig | {
|
|
70
72
|
/**
|
|
71
73
|
* The SuiClient instance to use when building and executing transactions.
|
|
72
74
|
*/
|
|
@@ -77,3 +79,4 @@ export type RegisterEnokiWalletsOptions = EnokiClientConfig & {
|
|
|
77
79
|
*/
|
|
78
80
|
network?: EnokiNetwork;
|
|
79
81
|
});
|
|
82
|
+
export {};
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Wallet } from '@mysten/wallet-standard';
|
|
2
2
|
import type { UiWallet } from '@wallet-standard/ui';
|
|
3
3
|
import type { EnokiWallet } from './wallet.js';
|
|
4
|
+
import type { EnokiGetSessionInput } from './features.js';
|
|
4
5
|
export declare function isEnokiWallet(wallet: UiWallet): boolean;
|
|
5
6
|
export declare function isEnokiWallet(wallet: Wallet): wallet is EnokiWallet;
|
|
6
|
-
export declare function getWalletMetadata(wallet: Wallet | UiWallet): import("./
|
|
7
|
+
export declare function getWalletMetadata(wallet: Wallet | UiWallet): import("./features.js").EnokiGetMetadataOutput | null;
|
|
8
|
+
export declare function getSession(wallet: Wallet | UiWallet, input?: EnokiGetSessionInput): Promise<import("./features.js").EnokiGetSessionOutput>;
|
|
7
9
|
export declare function isGoogleWallet(wallet: Wallet | UiWallet): boolean;
|
|
8
10
|
export declare function isTwitchWallet(wallet: Wallet | UiWallet): boolean;
|
|
9
11
|
export declare function isFacebookWallet(wallet: Wallet | UiWallet): boolean;
|
package/dist/esm/wallet/utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getWalletFeature } from "@wallet-standard/ui";
|
|
2
|
-
import { EnokiGetMetadata } from "./
|
|
2
|
+
import { EnokiGetMetadata, EnokiGetSession } from "./features.js";
|
|
3
3
|
function isEnokiWallet(wallet) {
|
|
4
4
|
if (isWalletHandle(wallet)) {
|
|
5
5
|
return wallet.features.includes(EnokiGetMetadata);
|
|
@@ -23,6 +23,23 @@ function getWalletMetadata(wallet) {
|
|
|
23
23
|
}
|
|
24
24
|
return null;
|
|
25
25
|
}
|
|
26
|
+
async function getSession(wallet, input) {
|
|
27
|
+
if (isWalletHandle(wallet)) {
|
|
28
|
+
try {
|
|
29
|
+
const { getSession: getSession2 } = getWalletFeature(
|
|
30
|
+
wallet,
|
|
31
|
+
EnokiGetSession
|
|
32
|
+
);
|
|
33
|
+
return await getSession2(input);
|
|
34
|
+
} catch (error) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
} else if (EnokiGetSession in wallet.features) {
|
|
38
|
+
const walletWithFeature = wallet;
|
|
39
|
+
return await walletWithFeature.features[EnokiGetSession].getSession(input);
|
|
40
|
+
}
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
26
43
|
function isGoogleWallet(wallet) {
|
|
27
44
|
return getWalletMetadata(wallet)?.provider === "google";
|
|
28
45
|
}
|
|
@@ -36,6 +53,7 @@ function isWalletHandle(wallet) {
|
|
|
36
53
|
return Array.isArray(wallet.features);
|
|
37
54
|
}
|
|
38
55
|
export {
|
|
56
|
+
getSession,
|
|
39
57
|
getWalletMetadata,
|
|
40
58
|
isEnokiWallet,
|
|
41
59
|
isFacebookWallet,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/wallet/utils.ts"],
|
|
4
|
-
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Wallet, WalletWithFeatures } from '@mysten/wallet-standard';\nimport type { UiWallet } from '@wallet-standard/ui';\nimport { getWalletFeature } from '@wallet-standard/ui';\nimport type { EnokiWallet } from './wallet.js';\nimport type {
|
|
5
|
-
"mappings": "AAKA,SAAS,wBAAwB;
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["// Copyright (c) Mysten Labs, Inc.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Wallet, WalletWithFeatures } from '@mysten/wallet-standard';\nimport type { UiWallet } from '@wallet-standard/ui';\nimport { getWalletFeature } from '@wallet-standard/ui';\nimport type { EnokiWallet } from './wallet.js';\nimport type {\n\tEnokiGetMetadataFeature,\n\tEnokiGetSessionFeature,\n\tEnokiGetSessionInput,\n} from './features.js';\nimport { EnokiGetMetadata, EnokiGetSession } from './features.js';\n\nexport function isEnokiWallet(wallet: UiWallet): boolean;\nexport function isEnokiWallet(wallet: Wallet): wallet is EnokiWallet;\nexport function isEnokiWallet(wallet: Wallet | UiWallet) {\n\tif (isWalletHandle(wallet)) {\n\t\treturn wallet.features.includes(EnokiGetMetadata);\n\t}\n\treturn EnokiGetMetadata in wallet.features;\n}\n\nexport function getWalletMetadata(wallet: Wallet | UiWallet) {\n\tif (isWalletHandle(wallet)) {\n\t\ttry {\n\t\t\tconst { getMetadata } = getWalletFeature(\n\t\t\t\twallet,\n\t\t\t\tEnokiGetMetadata,\n\t\t\t) as EnokiGetMetadataFeature[typeof EnokiGetMetadata];\n\n\t\t\treturn getMetadata();\n\t\t} catch (error) {\n\t\t\treturn null;\n\t\t}\n\t} else if (EnokiGetMetadata in wallet.features) {\n\t\tconst walletWithFeature = wallet as WalletWithFeatures<EnokiGetMetadataFeature>;\n\t\treturn walletWithFeature.features[EnokiGetMetadata].getMetadata();\n\t}\n\treturn null;\n}\n\nexport async function getSession(wallet: Wallet | UiWallet, input?: EnokiGetSessionInput) {\n\tif (isWalletHandle(wallet)) {\n\t\ttry {\n\t\t\tconst { getSession } = getWalletFeature(\n\t\t\t\twallet,\n\t\t\t\tEnokiGetSession,\n\t\t\t) as EnokiGetSessionFeature[typeof EnokiGetSession];\n\n\t\t\treturn await getSession(input);\n\t\t} catch (error) {\n\t\t\treturn null;\n\t\t}\n\t} else if (EnokiGetSession in wallet.features) {\n\t\tconst walletWithFeature = wallet as WalletWithFeatures<EnokiGetSessionFeature>;\n\t\treturn await walletWithFeature.features[EnokiGetSession].getSession(input);\n\t}\n\treturn null;\n}\n\nexport function isGoogleWallet(wallet: Wallet | UiWallet) {\n\treturn getWalletMetadata(wallet)?.provider === 'google';\n}\n\nexport function isTwitchWallet(wallet: Wallet | UiWallet) {\n\treturn getWalletMetadata(wallet)?.provider === 'twitch';\n}\n\nexport function isFacebookWallet(wallet: Wallet | UiWallet) {\n\treturn getWalletMetadata(wallet)?.provider === 'facebook';\n}\n\nfunction isWalletHandle(wallet: UiWallet | Wallet): wallet is UiWallet {\n\t// TypeScript doesn't properly narrow readonly arrays:\n\t// https://github.com/microsoft/TypeScript/issues/1700\n\treturn Array.isArray(wallet.features);\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,wBAAwB;AAOjC,SAAS,kBAAkB,uBAAuB;AAI3C,SAAS,cAAc,QAA2B;AACxD,MAAI,eAAe,MAAM,GAAG;AAC3B,WAAO,OAAO,SAAS,SAAS,gBAAgB;AAAA,EACjD;AACA,SAAO,oBAAoB,OAAO;AACnC;AAEO,SAAS,kBAAkB,QAA2B;AAC5D,MAAI,eAAe,MAAM,GAAG;AAC3B,QAAI;AACH,YAAM,EAAE,YAAY,IAAI;AAAA,QACvB;AAAA,QACA;AAAA,MACD;AAEA,aAAO,YAAY;AAAA,IACpB,SAAS,OAAO;AACf,aAAO;AAAA,IACR;AAAA,EACD,WAAW,oBAAoB,OAAO,UAAU;AAC/C,UAAM,oBAAoB;AAC1B,WAAO,kBAAkB,SAAS,gBAAgB,EAAE,YAAY;AAAA,EACjE;AACA,SAAO;AACR;AAEA,eAAsB,WAAW,QAA2B,OAA8B;AACzF,MAAI,eAAe,MAAM,GAAG;AAC3B,QAAI;AACH,YAAM,EAAE,YAAAA,YAAW,IAAI;AAAA,QACtB;AAAA,QACA;AAAA,MACD;AAEA,aAAO,MAAMA,YAAW,KAAK;AAAA,IAC9B,SAAS,OAAO;AACf,aAAO;AAAA,IACR;AAAA,EACD,WAAW,mBAAmB,OAAO,UAAU;AAC9C,UAAM,oBAAoB;AAC1B,WAAO,MAAM,kBAAkB,SAAS,eAAe,EAAE,WAAW,KAAK;AAAA,EAC1E;AACA,SAAO;AACR;AAEO,SAAS,eAAe,QAA2B;AACzD,SAAO,kBAAkB,MAAM,GAAG,aAAa;AAChD;AAEO,SAAS,eAAe,QAA2B;AACzD,SAAO,kBAAkB,MAAM,GAAG,aAAa;AAChD;AAEO,SAAS,iBAAiB,QAA2B;AAC3D,SAAO,kBAAkB,MAAM,GAAG,aAAa;AAChD;AAEA,SAAS,eAAe,QAA+C;AAGtE,SAAO,MAAM,QAAQ,OAAO,QAAQ;AACrC;",
|
|
6
|
+
"names": ["getSession"]
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import type { StandardConnectFeature, StandardDisconnectFeature, StandardEventsF
|
|
|
2
2
|
import { ReadonlyWalletAccount } from '@mysten/wallet-standard';
|
|
3
3
|
import type { AuthProvider } from '../EnokiClient/type.js';
|
|
4
4
|
import type { EnokiWalletOptions } from './types.js';
|
|
5
|
-
import type { EnokiGetMetadataFeature } from './
|
|
5
|
+
import type { EnokiGetMetadataFeature, EnokiGetSessionFeature } from './features.js';
|
|
6
6
|
export declare class EnokiWallet implements Wallet {
|
|
7
7
|
#private;
|
|
8
8
|
get name(): string;
|
|
@@ -11,6 +11,6 @@ export declare class EnokiWallet implements Wallet {
|
|
|
11
11
|
get version(): "1.0.0";
|
|
12
12
|
get chains(): `sui:${string & {}}`[];
|
|
13
13
|
get accounts(): ReadonlyWalletAccount[];
|
|
14
|
-
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature & EnokiGetMetadataFeature;
|
|
14
|
+
get features(): StandardConnectFeature & StandardDisconnectFeature & StandardEventsFeature & SuiSignTransactionFeature & SuiSignAndExecuteTransactionFeature & SuiSignPersonalMessageFeature & EnokiGetMetadataFeature & EnokiGetSessionFeature;
|
|
15
15
|
constructor({ name, icon, provider, clientId, redirectUrl, extraParams, windowFeatures, getCurrentNetwork, apiKey, apiUrl, clients, }: EnokiWalletOptions);
|
|
16
16
|
}
|
|
@@ -6,7 +6,7 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
6
6
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
7
7
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
8
8
|
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
9
|
-
var _events, _accounts, _name, _icon, _enokiClient, _state, _provider, _clientId, _redirectUrl, _extraParams, _getCurrentNetwork, _windowFeatures, _signTransaction, _signAndExecuteTransaction, _signPersonalMessage, _getMetadata, _on, _connect, _disconnect, _EnokiWallet_instances, getAuthorizedAccounts_fn,
|
|
9
|
+
var _events, _accounts, _name, _icon, _enokiClient, _state, _provider, _clientId, _redirectUrl, _extraParams, _getCurrentNetwork, _windowFeatures, _signTransaction, _signAndExecuteTransaction, _signPersonalMessage, _getMetadata, _getSession, _on, _connect, _disconnect, _EnokiWallet_instances, getAuthorizedAccounts_fn, getKeypair_fn, getSignerContext_fn, createSession_fn, createAuthorizationURL_fn, handleAuthCallback_fn;
|
|
10
10
|
import { Transaction } from "@mysten/sui/transactions";
|
|
11
11
|
import { fromBase64, toBase64 } from "@mysten/sui/utils";
|
|
12
12
|
import {
|
|
@@ -19,13 +19,14 @@ import {
|
|
|
19
19
|
SuiSignTransaction
|
|
20
20
|
} from "@mysten/wallet-standard";
|
|
21
21
|
import mitt from "mitt";
|
|
22
|
-
import { EnokiGetMetadata } from "./
|
|
22
|
+
import { EnokiGetMetadata, EnokiGetSession } from "./features.js";
|
|
23
23
|
import { decodeJwt } from "@mysten/sui/zklogin";
|
|
24
24
|
import { WebCryptoSigner } from "@mysten/signers/webcrypto";
|
|
25
25
|
import { get, set } from "idb-keyval";
|
|
26
26
|
import { EnokiClient } from "../EnokiClient/index.js";
|
|
27
27
|
import { EnokiKeypair } from "../EnokiKeypair.js";
|
|
28
28
|
import { EnokiWalletState } from "./state.js";
|
|
29
|
+
import { allTasks } from "nanostores";
|
|
29
30
|
class EnokiWallet {
|
|
30
31
|
constructor({
|
|
31
32
|
name,
|
|
@@ -105,26 +106,27 @@ class EnokiWallet {
|
|
|
105
106
|
return keypair.signPersonalMessage(message);
|
|
106
107
|
});
|
|
107
108
|
__privateAdd(this, _getMetadata, () => {
|
|
108
|
-
const sessionContext = __privateGet(this, _state).getSessionContext(__privateGet(this, _getCurrentNetwork).call(this));
|
|
109
|
-
const session = sessionContext?.$zkLoginSession.get();
|
|
110
|
-
const decodedJwt = session?.value?.jwt ? decodeJwt(session.value.jwt) : void 0;
|
|
111
109
|
return {
|
|
112
|
-
provider: __privateGet(this, _provider)
|
|
113
|
-
activeSession: decodedJwt ? { decodedJwt } : void 0
|
|
110
|
+
provider: __privateGet(this, _provider)
|
|
114
111
|
};
|
|
115
112
|
});
|
|
113
|
+
__privateAdd(this, _getSession, async (input) => {
|
|
114
|
+
const sessionContext = __privateGet(this, _state).getSessionContext(
|
|
115
|
+
input?.network ?? __privateGet(this, _getCurrentNetwork).call(this)
|
|
116
|
+
);
|
|
117
|
+
return await __privateGet(this, _state).getSession(sessionContext);
|
|
118
|
+
});
|
|
116
119
|
__privateAdd(this, _on, (event, listener) => {
|
|
117
120
|
__privateGet(this, _events).on(event, listener);
|
|
118
121
|
return () => __privateGet(this, _events).off(event, listener);
|
|
119
122
|
});
|
|
120
123
|
__privateAdd(this, _connect, async (input) => {
|
|
124
|
+
await allTasks();
|
|
121
125
|
if (input?.silent || __privateGet(this, _accounts).length > 0) {
|
|
122
126
|
return { accounts: __privateGet(this, _accounts) };
|
|
123
127
|
}
|
|
124
128
|
const currentNetwork = __privateGet(this, _getCurrentNetwork).call(this);
|
|
125
129
|
await __privateMethod(this, _EnokiWallet_instances, createSession_fn).call(this, { network: currentNetwork });
|
|
126
|
-
__privateSet(this, _accounts, __privateMethod(this, _EnokiWallet_instances, getAuthorizedAccounts_fn).call(this));
|
|
127
|
-
__privateGet(this, _events).emit("change", { accounts: __privateGet(this, _accounts) });
|
|
128
130
|
return { accounts: __privateGet(this, _accounts) };
|
|
129
131
|
});
|
|
130
132
|
__privateAdd(this, _disconnect, async () => {
|
|
@@ -143,7 +145,11 @@ class EnokiWallet {
|
|
|
143
145
|
__privateSet(this, _extraParams, extraParams);
|
|
144
146
|
__privateSet(this, _windowFeatures, windowFeatures);
|
|
145
147
|
__privateSet(this, _getCurrentNetwork, getCurrentNetwork);
|
|
146
|
-
__privateSet(this, _accounts,
|
|
148
|
+
__privateSet(this, _accounts, []);
|
|
149
|
+
__privateGet(this, _state).zkLoginState.subscribe(() => {
|
|
150
|
+
__privateSet(this, _accounts, __privateMethod(this, _EnokiWallet_instances, getAuthorizedAccounts_fn).call(this));
|
|
151
|
+
__privateGet(this, _events).emit("change", { accounts: __privateGet(this, _accounts) });
|
|
152
|
+
});
|
|
147
153
|
}
|
|
148
154
|
get name() {
|
|
149
155
|
return __privateGet(this, _name);
|
|
@@ -194,6 +200,10 @@ class EnokiWallet {
|
|
|
194
200
|
[EnokiGetMetadata]: {
|
|
195
201
|
version: "1.0.0",
|
|
196
202
|
getMetadata: __privateGet(this, _getMetadata)
|
|
203
|
+
},
|
|
204
|
+
[EnokiGetSession]: {
|
|
205
|
+
version: "1.0.0",
|
|
206
|
+
getSession: __privateGet(this, _getSession)
|
|
197
207
|
}
|
|
198
208
|
};
|
|
199
209
|
}
|
|
@@ -214,35 +224,30 @@ _signTransaction = new WeakMap();
|
|
|
214
224
|
_signAndExecuteTransaction = new WeakMap();
|
|
215
225
|
_signPersonalMessage = new WeakMap();
|
|
216
226
|
_getMetadata = new WeakMap();
|
|
227
|
+
_getSession = new WeakMap();
|
|
217
228
|
_on = new WeakMap();
|
|
218
229
|
_connect = new WeakMap();
|
|
219
230
|
_disconnect = new WeakMap();
|
|
220
231
|
_EnokiWallet_instances = new WeakSet();
|
|
221
232
|
getAuthorizedAccounts_fn = function() {
|
|
222
|
-
const
|
|
223
|
-
if (
|
|
233
|
+
const zkLoginState = __privateGet(this, _state).zkLoginState.get();
|
|
234
|
+
if (zkLoginState) {
|
|
224
235
|
return [
|
|
225
236
|
new ReadonlyWalletAccount({
|
|
226
|
-
address,
|
|
237
|
+
address: zkLoginState.address,
|
|
227
238
|
chains: this.chains,
|
|
228
239
|
icon: this.icon,
|
|
229
240
|
features: [SuiSignPersonalMessage, SuiSignTransaction, SuiSignAndExecuteTransaction],
|
|
230
|
-
publicKey: fromBase64(publicKey)
|
|
241
|
+
publicKey: fromBase64(zkLoginState.publicKey)
|
|
231
242
|
})
|
|
232
243
|
];
|
|
233
244
|
}
|
|
234
245
|
return [];
|
|
235
246
|
};
|
|
236
|
-
|
|
237
|
-
const
|
|
238
|
-
if (
|
|
239
|
-
|
|
240
|
-
throw new Error("Stored proof is expired.");
|
|
241
|
-
}
|
|
242
|
-
return zkp.proof;
|
|
243
|
-
}
|
|
244
|
-
if (!zkp?.jwt) {
|
|
245
|
-
throw new Error("Missing required parameters for proof generation");
|
|
247
|
+
getKeypair_fn = async function(sessionContext) {
|
|
248
|
+
const session = await __privateGet(this, _state).getSession(sessionContext);
|
|
249
|
+
if (!session?.jwt || session.proof && Date.now() > session.expiresAt) {
|
|
250
|
+
await __privateMethod(this, _EnokiWallet_instances, createSession_fn).call(this, { network: sessionContext.client.network });
|
|
246
251
|
}
|
|
247
252
|
const storedNativeSigner = await get(
|
|
248
253
|
"ephemeralKeyPair",
|
|
@@ -251,40 +256,24 @@ getProof_fn = async function(sessionContext) {
|
|
|
251
256
|
if (!storedNativeSigner) {
|
|
252
257
|
throw new Error("Native signer not found in store.");
|
|
253
258
|
}
|
|
254
|
-
const
|
|
259
|
+
const updatedSession = await __privateGet(this, _state).getSession(sessionContext);
|
|
260
|
+
if (!updatedSession?.jwt) {
|
|
261
|
+
throw new Error("Failed to retrieve an active session.");
|
|
262
|
+
}
|
|
263
|
+
const ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);
|
|
255
264
|
const proof = await __privateGet(this, _enokiClient).createZkLoginZkp({
|
|
256
265
|
network: sessionContext.client.network,
|
|
257
|
-
jwt:
|
|
258
|
-
maxEpoch:
|
|
259
|
-
randomness:
|
|
260
|
-
ephemeralPublicKey:
|
|
266
|
+
jwt: updatedSession.jwt,
|
|
267
|
+
maxEpoch: updatedSession.maxEpoch,
|
|
268
|
+
randomness: updatedSession.randomness,
|
|
269
|
+
ephemeralPublicKey: ephemeralKeypair.getPublicKey()
|
|
261
270
|
});
|
|
262
|
-
await __privateGet(this, _state).setSession(sessionContext, { ...
|
|
263
|
-
return proof;
|
|
264
|
-
};
|
|
265
|
-
getKeypair_fn = async function(sessionContext) {
|
|
266
|
-
await __privateMethod(this, _EnokiWallet_instances, getProof_fn).call(this, sessionContext);
|
|
267
|
-
const zkp = await __privateGet(this, _state).getSession(sessionContext);
|
|
268
|
-
const { address } = __privateGet(this, _state).zkLoginState.get();
|
|
269
|
-
if (!address || !zkp || !zkp.proof) {
|
|
270
|
-
throw new Error("Missing required data for keypair generation.");
|
|
271
|
-
}
|
|
272
|
-
if (Date.now() > zkp.expiresAt) {
|
|
273
|
-
throw new Error("Stored proof is expired.");
|
|
274
|
-
}
|
|
275
|
-
const storedNativeSigner = await get(
|
|
276
|
-
"ephemeralKeyPair",
|
|
277
|
-
sessionContext.idbStore
|
|
278
|
-
);
|
|
279
|
-
if (!storedNativeSigner) {
|
|
280
|
-
throw new Error("Native signer not found in store.");
|
|
281
|
-
}
|
|
282
|
-
const ephemeralKeypair = WebCryptoSigner.import(storedNativeSigner);
|
|
271
|
+
await __privateGet(this, _state).setSession(sessionContext, { ...updatedSession, proof });
|
|
283
272
|
return new EnokiKeypair({
|
|
284
|
-
address,
|
|
273
|
+
address: this.accounts[0].address,
|
|
274
|
+
maxEpoch: updatedSession.maxEpoch,
|
|
285
275
|
ephemeralKeypair,
|
|
286
|
-
|
|
287
|
-
proof: zkp.proof
|
|
276
|
+
proof
|
|
288
277
|
});
|
|
289
278
|
};
|
|
290
279
|
getSignerContext_fn = async function(chain) {
|
|
@@ -294,10 +283,6 @@ getSignerContext_fn = async function(chain) {
|
|
|
294
283
|
`A valid Sui chain identifier was not provided in the request. Please report this issue to the dApp developer. Examples of valid Sui chain identifiers are 'sui:testnet' and 'sui:mainnet'. Consider using the '@mysten/dapp-kit' package, which provides this value automatically.`
|
|
295
284
|
);
|
|
296
285
|
}
|
|
297
|
-
const zkLoginSession = await __privateGet(this, _state).getSession(sessionContext);
|
|
298
|
-
if (!zkLoginSession) {
|
|
299
|
-
await __privateMethod(this, _EnokiWallet_instances, createSession_fn).call(this, { network: sessionContext.client.network });
|
|
300
|
-
}
|
|
301
286
|
const keypair = await __privateMethod(this, _EnokiWallet_instances, getKeypair_fn).call(this, sessionContext);
|
|
302
287
|
return { client: sessionContext.client, keypair };
|
|
303
288
|
};
|
|
@@ -365,6 +350,9 @@ createAuthorizationURL_fn = async function(sessionContext) {
|
|
|
365
350
|
params.set("force_verify", "true");
|
|
366
351
|
oauthUrl = `https://id.twitch.tv/oauth2/authorize?${params}`;
|
|
367
352
|
break;
|
|
353
|
+
case "onefc":
|
|
354
|
+
oauthUrl = `https://login.onepassport.onefc.com/de3ee5c1-5644-4113-922d-e8336569a462/b2c_1a_prod_signupsignin_onesuizklogin/oauth2/v2.0/authorize?${params}`;
|
|
355
|
+
break;
|
|
368
356
|
default:
|
|
369
357
|
throw new Error(`Invalid provider: ${__privateGet(this, _provider)}`);
|
|
370
358
|
}
|