@mysten/enoki 0.0.0-experimental-20231117210618
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 +11 -0
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/dist/cjs/EnokiClient/index.d.ts +18 -0
- package/dist/cjs/EnokiClient/index.js +114 -0
- package/dist/cjs/EnokiClient/index.js.map +7 -0
- package/dist/cjs/EnokiClient/type.d.ts +36 -0
- package/dist/cjs/EnokiClient/type.js +17 -0
- package/dist/cjs/EnokiClient/type.js.map +7 -0
- package/dist/cjs/EnokiFlow.d.ts +50 -0
- package/dist/cjs/EnokiFlow.js +256 -0
- package/dist/cjs/EnokiFlow.js.map +7 -0
- package/dist/cjs/EnokiKeypair.d.ts +31 -0
- package/dist/cjs/EnokiKeypair.js +119 -0
- package/dist/cjs/EnokiKeypair.js.map +7 -0
- package/dist/cjs/encryption.d.ts +15 -0
- package/dist/cjs/encryption.js +47 -0
- package/dist/cjs/encryption.js.map +7 -0
- package/dist/cjs/index.d.ts +5 -0
- package/dist/cjs/index.js +36 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/package.json +4 -0
- package/dist/cjs/react.d.ts +9 -0
- package/dist/cjs/react.js +46 -0
- package/dist/cjs/react.js.map +7 -0
- package/dist/cjs/stores.d.ts +21 -0
- package/dist/cjs/stores.js +67 -0
- package/dist/cjs/stores.js.map +7 -0
- package/dist/esm/EnokiClient/index.d.ts +18 -0
- package/dist/esm/EnokiClient/index.js +94 -0
- package/dist/esm/EnokiClient/index.js.map +7 -0
- package/dist/esm/EnokiClient/type.d.ts +36 -0
- package/dist/esm/EnokiClient/type.js +1 -0
- package/dist/esm/EnokiClient/type.js.map +7 -0
- package/dist/esm/EnokiFlow.d.ts +50 -0
- package/dist/esm/EnokiFlow.js +236 -0
- package/dist/esm/EnokiFlow.js.map +7 -0
- package/dist/esm/EnokiKeypair.d.ts +31 -0
- package/dist/esm/EnokiKeypair.js +99 -0
- package/dist/esm/EnokiKeypair.js.map +7 -0
- package/dist/esm/encryption.d.ts +15 -0
- package/dist/esm/encryption.js +30 -0
- package/dist/esm/encryption.js.map +7 -0
- package/dist/esm/index.d.ts +5 -0
- package/dist/esm/index.js +20 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/package.json +4 -0
- package/dist/esm/react.d.ts +9 -0
- package/dist/esm/react.js +26 -0
- package/dist/esm/react.js.map +7 -0
- package/dist/esm/stores.d.ts +21 -0
- package/dist/esm/stores.js +47 -0
- package/dist/esm/stores.js.map +7 -0
- package/dist/tsconfig.esm.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +73 -0
- package/react/package.json +5 -0
- package/src/EnokiClient/index.ts +97 -0
- package/src/EnokiClient/type.ts +42 -0
- package/src/EnokiFlow.ts +308 -0
- package/src/EnokiKeypair.ts +98 -0
- package/src/encryption.ts +44 -0
- package/src/index.ts +13 -0
- package/src/react.tsx +33 -0
- package/src/stores.ts +68 -0
package/src/react.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { useStore } from '@nanostores/react';
|
|
5
|
+
import type { ReactNode } from 'react';
|
|
6
|
+
import { createContext, useContext, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import type { EnokiFlowConfig } from './EnokiFlow.js';
|
|
9
|
+
import { EnokiFlow } from './EnokiFlow.js';
|
|
10
|
+
|
|
11
|
+
const EnokiFlowContext = createContext<EnokiFlow | null>(null);
|
|
12
|
+
|
|
13
|
+
export interface EnokiFlowProviderProps extends EnokiFlowConfig {
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function EnokiFlowProvider({ children, ...config }: EnokiFlowProviderProps) {
|
|
18
|
+
const [enokiFlow] = useState(() => new EnokiFlow(config));
|
|
19
|
+
return <EnokiFlowContext.Provider value={enokiFlow}>{children}</EnokiFlowContext.Provider>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useEnokiFlow() {
|
|
23
|
+
const context = useContext(EnokiFlowContext);
|
|
24
|
+
if (!context) {
|
|
25
|
+
throw new Error('Missing `EnokiFlowContext` provider');
|
|
26
|
+
}
|
|
27
|
+
return context;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function useZkLogin() {
|
|
31
|
+
const flow = useEnokiFlow();
|
|
32
|
+
return useStore(flow.$zkLoginState);
|
|
33
|
+
}
|
package/src/stores.ts
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Copyright (c) Mysten Labs, Inc.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* An sync key-value store.
|
|
6
|
+
*/
|
|
7
|
+
export interface SyncStore {
|
|
8
|
+
get(key: string): string | null;
|
|
9
|
+
set(key: string, value: string): void;
|
|
10
|
+
delete(key: string): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function createWebStorage(storage: Storage): SyncStore {
|
|
14
|
+
return {
|
|
15
|
+
get(key: string) {
|
|
16
|
+
return storage.getItem(key);
|
|
17
|
+
},
|
|
18
|
+
set(key: string, value: string) {
|
|
19
|
+
storage.setItem(key, value);
|
|
20
|
+
},
|
|
21
|
+
delete(key: string) {
|
|
22
|
+
storage.removeItem(key);
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Create a storage interface backed by memory.
|
|
29
|
+
* This is generally useful for server-side rendering, and test environments.
|
|
30
|
+
*/
|
|
31
|
+
export function createInMemoryStorage(): SyncStore {
|
|
32
|
+
const store = new Map<string, string>();
|
|
33
|
+
return {
|
|
34
|
+
get(key) {
|
|
35
|
+
return store.get(key) ?? null;
|
|
36
|
+
},
|
|
37
|
+
set(key, value) {
|
|
38
|
+
store.set(key, value);
|
|
39
|
+
},
|
|
40
|
+
delete(key) {
|
|
41
|
+
store.delete(key);
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a store backed by `localStorage`.
|
|
48
|
+
*/
|
|
49
|
+
export function createLocalStorage(): SyncStore {
|
|
50
|
+
if (typeof window === 'undefined') {
|
|
51
|
+
console.warn('`window.localStorage` is not available, falling back to in-memory storage');
|
|
52
|
+
return createInMemoryStorage();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return createWebStorage(window.localStorage);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Create a store backed by `sessionStorage`.
|
|
60
|
+
*/
|
|
61
|
+
export function createSessionStorage(): SyncStore {
|
|
62
|
+
if (typeof window === 'undefined') {
|
|
63
|
+
console.warn('`window.sessionStorage` is not available, falling back to in-memory storage');
|
|
64
|
+
return createInMemoryStorage();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return createWebStorage(window.sessionStorage);
|
|
68
|
+
}
|