shogun-core 1.2.0 → 1.2.3
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 +6 -6
- package/dist/browser/shogun-core.js +1 -1
- package/dist/browser/shogun-core.light.js +1 -0
- package/dist/browser/shogun-core.vendors.light.js +1 -0
- package/dist/browser.js +11 -11
- package/dist/core.js +46 -45
- package/dist/gundb/gun.js +112 -92
- package/dist/plugins/index.js +4 -4
- package/dist/plugins/{bitcoin → nostr}/nostrConnectorPlugin.js +7 -8
- package/dist/plugins/{ethereum → web3}/web3ConnectorPlugin.js +7 -7
- package/dist/types/browser.d.ts +4 -4
- package/dist/types/core.d.ts +1 -2
- package/dist/types/gundb/gun.d.ts +4 -10
- package/dist/types/plugins/index.d.ts +6 -6
- package/dist/types/shogun.js +2 -2
- package/dist/types/types/shogun.d.ts +5 -23
- package/package.json +1 -1
- package/dist/gundb/models/auth/auth.js +0 -207
- package/dist/gundb/models/auth/state-machine.js +0 -216
- package/dist/gundb/models/streams.js +0 -116
- package/dist/types/gundb/models/auth/auth.d.ts +0 -121
- package/dist/types/gundb/models/auth/state-machine.d.ts +0 -70
- package/dist/types/gundb/models/streams.d.ts +0 -67
- /package/dist/plugins/{bitcoin → nostr}/index.js +0 -0
- /package/dist/plugins/{bitcoin → nostr}/nostrConnector.js +0 -0
- /package/dist/plugins/{bitcoin → nostr}/types.js +0 -0
- /package/dist/plugins/{ethereum → web3}/index.js +0 -0
- /package/dist/plugins/{ethereum → web3}/types.js +0 -0
- /package/dist/plugins/{ethereum → web3}/web3Connector.js +0 -0
- /package/dist/types/plugins/{bitcoin → nostr}/index.d.ts +0 -0
- /package/dist/types/plugins/{bitcoin → nostr}/nostrConnector.d.ts +0 -0
- /package/dist/types/plugins/{bitcoin → nostr}/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/plugins/{bitcoin → nostr}/types.d.ts +0 -0
- /package/dist/types/plugins/{ethereum → web3}/index.d.ts +0 -0
- /package/dist/types/plugins/{ethereum → web3}/types.d.ts +0 -0
- /package/dist/types/plugins/{ethereum → web3}/web3Connector.d.ts +0 -0
- /package/dist/types/plugins/{ethereum → web3}/web3ConnectorPlugin.d.ts +0 -0
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import { GunUser, ISEAPair } from "gun";
|
|
2
|
-
import { GunDB } from "../../gun";
|
|
3
|
-
import { StateMachineEvent } from "./state-machine";
|
|
4
|
-
/** A valid user alias. Must be checked with the as_alias function. */
|
|
5
|
-
export type GunAlias = string & {
|
|
6
|
-
_value: never;
|
|
7
|
-
};
|
|
8
|
-
/** A valid user password. Must be checked with the AuthManager.validate function. */
|
|
9
|
-
export type GunPassword = string & {
|
|
10
|
-
_value: never;
|
|
11
|
-
};
|
|
12
|
-
/** An auth manager that wraps gun.user logic. */
|
|
13
|
-
export default class AuthManager {
|
|
14
|
-
static INITIAL_STATE: "disconnected";
|
|
15
|
-
static state: {
|
|
16
|
-
subscribe: (cb: (state: import("./state-machine").AUTH_STATE) => any) => () => void;
|
|
17
|
-
set: (event: StateMachineEvent) => void;
|
|
18
|
-
getCurrentState: () => import("./state-machine").AUTH_STATE;
|
|
19
|
-
waitForState: (targetState: import("./state-machine").AUTH_STATE, timeoutMs?: number) => Promise<boolean>;
|
|
20
|
-
isAuthenticated: () => boolean;
|
|
21
|
-
isWalletReady: () => boolean;
|
|
22
|
-
};
|
|
23
|
-
static instance: AuthManager;
|
|
24
|
-
gundb: GunDB;
|
|
25
|
-
app_scope: string;
|
|
26
|
-
/** Returns the validated alias and password information. This will also be scoped using app_scope */
|
|
27
|
-
validate(alias: string, password: string): Promise<{
|
|
28
|
-
alias: GunAlias;
|
|
29
|
-
password: GunPassword;
|
|
30
|
-
}>;
|
|
31
|
-
/** A new AuthManager. */
|
|
32
|
-
constructor(gundb: GunDB, appScope?: string);
|
|
33
|
-
/** Gets the user chain, if authenticated. */
|
|
34
|
-
get chain(): import("gun").IGunChain<any, import("gun").IGunInstance<any>, import("gun").IGunInstance<any>, string>;
|
|
35
|
-
/**
|
|
36
|
-
* Attempt to get the pair of the currently logged in user.
|
|
37
|
-
*
|
|
38
|
-
* You may do `pair({strict})` to throw if the user is not authenticated.
|
|
39
|
-
* */
|
|
40
|
-
pair(options: {
|
|
41
|
-
strict: true;
|
|
42
|
-
}): ISEAPair;
|
|
43
|
-
pair(options?: {
|
|
44
|
-
strict?: false;
|
|
45
|
-
}): ISEAPair | undefined;
|
|
46
|
-
/**
|
|
47
|
-
* Generate a new gun user pair using alias and password.
|
|
48
|
-
*
|
|
49
|
-
* @param alias - The user alias.
|
|
50
|
-
* @param password - The user password.
|
|
51
|
-
* @returns A promise that resolves with gun ack or rejects with gun ack on errors.
|
|
52
|
-
*/
|
|
53
|
-
create: ({ alias, password, }: {
|
|
54
|
-
alias: GunAlias;
|
|
55
|
-
password: GunPassword;
|
|
56
|
-
}) => Promise<{
|
|
57
|
-
ok: 0;
|
|
58
|
-
pub: string;
|
|
59
|
-
} | {
|
|
60
|
-
err: string;
|
|
61
|
-
}>;
|
|
62
|
-
/**
|
|
63
|
-
* Authenicate existing gun user using either a pair or a alias/password combination.
|
|
64
|
-
* @returns A promise that resolves with gun ack or rejects with gun ack on errors.
|
|
65
|
-
*/
|
|
66
|
-
auth: (info: {
|
|
67
|
-
alias: GunAlias;
|
|
68
|
-
password: GunPassword;
|
|
69
|
-
} | ISEAPair) => Promise<GunAuthAck>;
|
|
70
|
-
/**
|
|
71
|
-
* Un-authenticates the currently authenticated gun user.
|
|
72
|
-
*/
|
|
73
|
-
leave: () => Promise<{
|
|
74
|
-
success: true;
|
|
75
|
-
}>;
|
|
76
|
-
/**
|
|
77
|
-
* A simple default certificate that will allow everybody to write to the users graph, as long as the key or path contains their public key.
|
|
78
|
-
*/
|
|
79
|
-
certify(): null;
|
|
80
|
-
/**
|
|
81
|
-
* Start wallet initialization process
|
|
82
|
-
*/
|
|
83
|
-
startWalletInit(): void;
|
|
84
|
-
/**
|
|
85
|
-
* Mark wallet initialization as successful
|
|
86
|
-
*/
|
|
87
|
-
walletInitSuccess(): void;
|
|
88
|
-
/**
|
|
89
|
-
* Mark wallet initialization as failed
|
|
90
|
-
*/
|
|
91
|
-
walletInitFail(error?: any): void;
|
|
92
|
-
/**
|
|
93
|
-
* Wait for authentication to complete
|
|
94
|
-
*/
|
|
95
|
-
waitForAuthentication(timeoutMs?: number): Promise<boolean>;
|
|
96
|
-
/**
|
|
97
|
-
* Wait for wallet to be ready
|
|
98
|
-
*/
|
|
99
|
-
waitForWalletReady(timeoutMs?: number): Promise<boolean>;
|
|
100
|
-
/**
|
|
101
|
-
* Check if user is authenticated
|
|
102
|
-
*/
|
|
103
|
-
isAuthenticated(): boolean;
|
|
104
|
-
/**
|
|
105
|
-
* Check if wallet is ready
|
|
106
|
-
*/
|
|
107
|
-
isWalletReady(): boolean;
|
|
108
|
-
/**
|
|
109
|
-
* Get current authentication state
|
|
110
|
-
*/
|
|
111
|
-
getCurrentState(): "wallet_initializing" | "wallet_ready" | "disconnected" | "creating" | "pending" | "authorized" | "leaving";
|
|
112
|
-
}
|
|
113
|
-
export type GunAuthAck = {
|
|
114
|
-
ack: 2;
|
|
115
|
-
soul: string;
|
|
116
|
-
get: string;
|
|
117
|
-
put: GunUser;
|
|
118
|
-
sea: ISEAPair;
|
|
119
|
-
} | {
|
|
120
|
-
err: string;
|
|
121
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
/** Transistion function that takes a state and event and outputs a new state */
|
|
2
|
-
interface Machine {
|
|
3
|
-
(state: AUTH_STATE, event: StateMachineEvent): AUTH_STATE;
|
|
4
|
-
}
|
|
5
|
-
/** A state machine event with optional data */
|
|
6
|
-
export declare class StateMachineEvent {
|
|
7
|
-
type: AUTH_EVENT;
|
|
8
|
-
data: any;
|
|
9
|
-
constructor(type: AUTH_EVENT, data?: any);
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param machine - A machine function that defines state transitions.
|
|
14
|
-
* @param initial - The initial state of the machine.
|
|
15
|
-
*/
|
|
16
|
-
export declare function use_machine(machine: Machine, initial: AUTH_STATE): {
|
|
17
|
-
/**
|
|
18
|
-
* Subscribe to state updates.
|
|
19
|
-
* @returns an unsubscriber */
|
|
20
|
-
subscribe: (cb: (state: AUTH_STATE) => any) => () => void;
|
|
21
|
-
/** attempt to update the state machine */
|
|
22
|
-
set: (event: StateMachineEvent) => void;
|
|
23
|
-
/** Get the current state */
|
|
24
|
-
getCurrentState: () => AUTH_STATE;
|
|
25
|
-
/** Wait for a specific state */
|
|
26
|
-
waitForState: (targetState: AUTH_STATE, timeoutMs?: number) => Promise<boolean>;
|
|
27
|
-
/** Check if user is authenticated */
|
|
28
|
-
isAuthenticated: () => boolean;
|
|
29
|
-
/** Check if wallet is ready */
|
|
30
|
-
isWalletReady: () => boolean;
|
|
31
|
-
};
|
|
32
|
-
/** Possible states that the auth-manager can be in. */
|
|
33
|
-
export declare const states: {
|
|
34
|
-
/** The user is in an un-busy and unauthorized state.*/
|
|
35
|
-
disconnected: "disconnected";
|
|
36
|
-
/** A user is currently being created. */
|
|
37
|
-
creating: "creating";
|
|
38
|
-
/** A user is currently being authorized. */
|
|
39
|
-
pending: "pending";
|
|
40
|
-
/** The user is in an un-busy and authorized state. */
|
|
41
|
-
authorized: "authorized";
|
|
42
|
-
/** The user is currently logging out. */
|
|
43
|
-
leaving: "leaving";
|
|
44
|
-
/** Wallet initialization is in progress. */
|
|
45
|
-
wallet_initializing: "wallet_initializing";
|
|
46
|
-
/** Wallet is ready and available. */
|
|
47
|
-
wallet_ready: "wallet_ready";
|
|
48
|
-
};
|
|
49
|
-
/** Possible events that the auth-manager can take. */
|
|
50
|
-
export declare const events: {
|
|
51
|
-
create: "create";
|
|
52
|
-
authenticate: "authenticate";
|
|
53
|
-
disconnect: "disconnect";
|
|
54
|
-
fail: "fail";
|
|
55
|
-
success: "success";
|
|
56
|
-
wallet_init_start: "wallet_init_start";
|
|
57
|
-
wallet_init_success: "wallet_init_success";
|
|
58
|
-
wallet_init_fail: "wallet_init_fail";
|
|
59
|
-
};
|
|
60
|
-
export type AUTH_EVENT = keyof typeof events;
|
|
61
|
-
export type AUTH_STATE = keyof typeof states;
|
|
62
|
-
/**
|
|
63
|
-
* Defines possible transitions from the states in the auth manager.
|
|
64
|
-
*
|
|
65
|
-
* @param state - The current state.
|
|
66
|
-
* @param event The event that has happend.
|
|
67
|
-
* @returns The new state.
|
|
68
|
-
*/
|
|
69
|
-
export declare function auth_state_machine(state: AUTH_STATE, event: StateMachineEvent): AUTH_STATE;
|
|
70
|
-
export {};
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { IGunChain } from "gun";
|
|
2
|
-
interface GunNode {
|
|
3
|
-
chain: IGunChain<any>;
|
|
4
|
-
}
|
|
5
|
-
interface GunNodeClassSimple<T extends GunNode> {
|
|
6
|
-
new (chain: IGunChain<any>): T;
|
|
7
|
-
}
|
|
8
|
-
export type ValidGunChunk = {
|
|
9
|
-
key: string;
|
|
10
|
-
value: any;
|
|
11
|
-
chain: IGunChain<any>;
|
|
12
|
-
};
|
|
13
|
-
export type NullGunChunk = {
|
|
14
|
-
key: string;
|
|
15
|
-
value: null;
|
|
16
|
-
chain: null;
|
|
17
|
-
};
|
|
18
|
-
export type ValidGunNodeChunk<T extends GunNode> = {
|
|
19
|
-
key: string;
|
|
20
|
-
value: any;
|
|
21
|
-
node: T;
|
|
22
|
-
};
|
|
23
|
-
export type NullGunNodeChunk = {
|
|
24
|
-
key: string;
|
|
25
|
-
value: any;
|
|
26
|
-
node: null;
|
|
27
|
-
};
|
|
28
|
-
declare global {
|
|
29
|
-
interface ReadableStream<R> {
|
|
30
|
-
[Symbol.asyncIterator](): AsyncIterableIterator<R>;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
*
|
|
35
|
-
* Wraps .on call in a stream. Cancelling the stream will unsubscribe from updates from gun.
|
|
36
|
-
*
|
|
37
|
-
* **Usage:**
|
|
38
|
-
* ```
|
|
39
|
-
* const stream = on_stream(node)
|
|
40
|
-
* for await (const chunk of stream) {
|
|
41
|
-
* // Do something with each 'chunk'
|
|
42
|
-
* }
|
|
43
|
-
* ```
|
|
44
|
-
*/
|
|
45
|
-
export declare function on_stream(chain: IGunChain<any>): ReadableStream<ValidGunChunk | NullGunChunk>;
|
|
46
|
-
/**
|
|
47
|
-
*
|
|
48
|
-
* Takes an incoming stream, but only issues updates if the data changes from valid data to null data.
|
|
49
|
-
* You can use this to keep a list in sync with the gun state. If data is tombstoned, it can be removed from the list.
|
|
50
|
-
*
|
|
51
|
-
* **Example:**
|
|
52
|
-
* ```
|
|
53
|
-
* const map = new Map();
|
|
54
|
-
* const items = [];
|
|
55
|
-
* const stream = on_stream(node).pipeThrough(unique_transformer());
|
|
56
|
-
* for await (const chunk of stream) {
|
|
57
|
-
* chunk.value === null ? map.delete(chunk.key) : map.set(chunk.key, chunk.chain);
|
|
58
|
-
items.splice(0, items.length, ...map.values());
|
|
59
|
-
* }
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export declare function to_unique(): TransformStream<ValidGunChunk | NullGunChunk, ValidGunChunk | NullGunChunk>;
|
|
63
|
-
/**
|
|
64
|
-
* Transoforms a stream of gun chains into a stream of gun nodes.
|
|
65
|
-
*/
|
|
66
|
-
export declare function to_node<T extends GunNode = GunNode>(target: GunNodeClassSimple<T>): TransformStream<ValidGunChunk | NullGunChunk, NullGunNodeChunk | ValidGunNodeChunk<T>>;
|
|
67
|
-
export {};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|