@hub3js/core 0.59.0 → 0.59.1-next.1
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/builders/action.d.ts +22 -0
- package/dist/builders/action.d.ts.map +1 -0
- package/dist/builders/mod.d.ts +5 -0
- package/dist/builders/mod.d.ts.map +1 -0
- package/dist/builders/namespace.d.ts +47 -0
- package/dist/builders/namespace.d.ts.map +1 -0
- package/dist/builders/provider.d.ts +37 -0
- package/dist/builders/provider.d.ts.map +1 -0
- package/dist/builders/types.d.ts +23 -0
- package/dist/builders/types.d.ts.map +1 -0
- package/dist/hub/helpers.d.ts +6 -0
- package/dist/hub/helpers.d.ts.map +1 -0
- package/dist/hub/hub.d.ts +44 -0
- package/dist/hub/hub.d.ts.map +1 -0
- package/dist/hub/mod.d.ts +9 -0
- package/dist/hub/mod.d.ts.map +1 -0
- package/dist/hub/namespaces/errors.d.ts +5 -0
- package/dist/hub/namespaces/errors.d.ts.map +1 -0
- package/dist/hub/namespaces/mod.d.ts +3 -0
- package/dist/hub/namespaces/mod.d.ts.map +1 -0
- package/dist/hub/namespaces/namespace.d.ts +148 -0
- package/dist/hub/namespaces/namespace.d.ts.map +1 -0
- package/dist/hub/namespaces/types.d.ts +36 -0
- package/dist/hub/namespaces/types.d.ts.map +1 -0
- package/dist/hub/provider/mod.d.ts +3 -0
- package/dist/hub/provider/mod.d.ts.map +1 -0
- package/dist/hub/provider/provider.d.ts +102 -0
- package/dist/hub/provider/provider.d.ts.map +1 -0
- package/dist/hub/provider/types.d.ts +28 -0
- package/dist/hub/provider/types.d.ts.map +1 -0
- package/dist/hub/store/events.d.ts +54 -0
- package/dist/hub/store/events.d.ts.map +1 -0
- package/dist/hub/store/extend.d.ts +14 -0
- package/dist/hub/store/extend.d.ts.map +1 -0
- package/dist/hub/store/hub.d.ts +11 -0
- package/dist/hub/store/hub.d.ts.map +1 -0
- package/dist/hub/store/mod.d.ts +8 -0
- package/dist/hub/store/mod.d.ts.map +1 -0
- package/dist/hub/store/mod.js +1 -1
- package/dist/hub/store/mod.js.map +2 -2
- package/dist/hub/store/namespaces.d.ts +38 -0
- package/dist/hub/store/namespaces.d.ts.map +1 -0
- package/dist/hub/store/providers.d.ts +84 -0
- package/dist/hub/store/providers.d.ts.map +1 -0
- package/dist/hub/store/selectors.d.ts +18 -0
- package/dist/hub/store/selectors.d.ts.map +1 -0
- package/dist/hub/store/store.d.ts +14 -0
- package/dist/hub/store/store.d.ts.map +1 -0
- package/dist/hub/types.d.ts +5 -0
- package/dist/hub/types.d.ts.map +1 -0
- package/dist/mod.d.ts +5 -0
- package/dist/mod.d.ts.map +1 -0
- package/dist/mod.js +1 -1
- package/dist/mod.js.map +4 -4
- package/dist/test-utils/fixtures.d.ts +4 -0
- package/dist/test-utils/fixtures.d.ts.map +1 -0
- package/dist/test-utils/mod.d.ts +2 -0
- package/dist/test-utils/mod.d.ts.map +1 -0
- package/dist/test-utils/mod.js +2 -0
- package/dist/test-utils/mod.js.map +7 -0
- package/dist/utils/mod.d.ts +3 -0
- package/dist/utils/mod.d.ts.map +1 -0
- package/dist/utils/mod.js +1 -1
- package/dist/utils/mod.js.map +4 -4
- package/dist/utils/versions.d.ts +50 -0
- package/dist/utils/versions.d.ts.map +1 -0
- package/package.json +9 -60
- package/src/builders/action.test.ts +225 -0
- package/src/builders/action.ts +1 -1
- package/src/builders/namespace.ts +1 -1
- package/src/builders/provider.ts +59 -19
- package/src/builders/types.ts +6 -4
- package/src/hub/hub.test.ts +108 -0
- package/src/hub/hub.ts +26 -9
- package/src/hub/mod.ts +2 -1
- package/src/hub/namespaces/namespace.ts +2 -2
- package/src/hub/namespaces/types.ts +1 -1
- package/src/hub/provider/mod.ts +1 -2
- package/src/hub/provider/provider.test.ts +64 -19
- package/src/hub/provider/provider.ts +43 -92
- package/src/hub/provider/types.ts +14 -31
- package/src/hub/store/mod.ts +1 -0
- package/src/hub/store/providers.ts +32 -18
- package/src/mod.ts +2 -21
- package/src/test-utils/mod.ts +1 -0
- package/src/utils/mod.ts +2 -8
- package/src/utils/versions.test.ts +0 -1
- package/src/utils/versions.ts +71 -44
- package/dist/legacy/mod.js +0 -2
- package/dist/legacy/mod.js.map +0 -7
- package/dist/namespaces/common/mod.js +0 -2
- package/dist/namespaces/common/mod.js.map +0 -7
- package/dist/namespaces/cosmos/mod.js +0 -2
- package/dist/namespaces/cosmos/mod.js.map +0 -7
- package/dist/namespaces/evm/mod.js +0 -2
- package/dist/namespaces/evm/mod.js.map +0 -7
- package/dist/namespaces/solana/mod.js +0 -2
- package/dist/namespaces/solana/mod.js.map +0 -7
- package/dist/namespaces/starknet/mod.js +0 -2
- package/dist/namespaces/starknet/mod.js.map +0 -7
- package/dist/namespaces/sui/mod.js +0 -2
- package/dist/namespaces/sui/mod.js.map +0 -7
- package/dist/namespaces/tron/mod.js +0 -2
- package/dist/namespaces/tron/mod.js.map +0 -7
- package/dist/namespaces/utxo/mod.js +0 -2
- package/dist/namespaces/utxo/mod.js.map +0 -7
- package/dist/namespaces/xrpl/mod.js +0 -2
- package/dist/namespaces/xrpl/mod.js.map +0 -7
- package/legacy/package.json +0 -8
- package/namespaces/common/package.json +0 -8
- package/namespaces/cosmos/package.json +0 -8
- package/namespaces/evm/package.json +0 -8
- package/namespaces/solana/package.json +0 -8
- package/namespaces/starknet/package.json +0 -8
- package/namespaces/sui/package.json +0 -8
- package/namespaces/tron/package.json +0 -8
- package/namespaces/utxo/package.json +0 -8
- package/namespaces/xrpl/package.json +0 -8
- package/src/legacy/helpers.ts +0 -75
- package/src/legacy/mod.ts +0 -44
- package/src/legacy/persistor.ts +0 -19
- package/src/legacy/types.ts +0 -303
- package/src/legacy/utils.ts +0 -20
- package/src/legacy/wallet.ts +0 -552
- package/src/namespaces/common/actions.ts +0 -12
- package/src/namespaces/common/after.ts +0 -8
- package/src/namespaces/common/and.ts +0 -42
- package/src/namespaces/common/before.ts +0 -9
- package/src/namespaces/common/builders.ts +0 -14
- package/src/namespaces/common/helpers.ts +0 -10
- package/src/namespaces/common/hooks/changeAccountSubscriber.test.ts +0 -173
- package/src/namespaces/common/hooks/changeAccountSubscriber.ts +0 -236
- package/src/namespaces/common/mod.ts +0 -23
- package/src/namespaces/common/or.ts +0 -17
- package/src/namespaces/common/types.ts +0 -27
- package/src/namespaces/common/utils.ts +0 -43
- package/src/namespaces/cosmos/actions.ts +0 -3
- package/src/namespaces/cosmos/after.ts +0 -3
- package/src/namespaces/cosmos/and.ts +0 -5
- package/src/namespaces/cosmos/before.ts +0 -3
- package/src/namespaces/cosmos/builders.ts +0 -15
- package/src/namespaces/cosmos/constants.ts +0 -1
- package/src/namespaces/cosmos/mod.ts +0 -15
- package/src/namespaces/cosmos/types.ts +0 -31
- package/src/namespaces/cosmos/utils.ts +0 -21
- package/src/namespaces/evm/actions.ts +0 -134
- package/src/namespaces/evm/after.ts +0 -3
- package/src/namespaces/evm/and.ts +0 -5
- package/src/namespaces/evm/before.ts +0 -3
- package/src/namespaces/evm/builders.ts +0 -52
- package/src/namespaces/evm/constants.ts +0 -2
- package/src/namespaces/evm/eip1193.ts +0 -1415
- package/src/namespaces/evm/hooks.ts +0 -43
- package/src/namespaces/evm/mod.ts +0 -10
- package/src/namespaces/evm/types.ts +0 -36
- package/src/namespaces/evm/utils.ts +0 -106
- package/src/namespaces/solana/actions.ts +0 -44
- package/src/namespaces/solana/after.ts +0 -3
- package/src/namespaces/solana/and.ts +0 -5
- package/src/namespaces/solana/before.ts +0 -3
- package/src/namespaces/solana/builders.ts +0 -40
- package/src/namespaces/solana/constants.ts +0 -2
- package/src/namespaces/solana/hooks.ts +0 -10
- package/src/namespaces/solana/mod.ts +0 -10
- package/src/namespaces/solana/types.ts +0 -25
- package/src/namespaces/solana/utils.ts +0 -36
- package/src/namespaces/starknet/actions.ts +0 -19
- package/src/namespaces/starknet/after.ts +0 -3
- package/src/namespaces/starknet/and.ts +0 -5
- package/src/namespaces/starknet/before.ts +0 -3
- package/src/namespaces/starknet/builders.ts +0 -18
- package/src/namespaces/starknet/constants.ts +0 -8
- package/src/namespaces/starknet/mod.ts +0 -9
- package/src/namespaces/starknet/types.ts +0 -18
- package/src/namespaces/starknet/utils.ts +0 -35
- package/src/namespaces/sui/actions.ts +0 -27
- package/src/namespaces/sui/builders.ts +0 -77
- package/src/namespaces/sui/constants.ts +0 -8
- package/src/namespaces/sui/hooks.ts +0 -10
- package/src/namespaces/sui/mod.ts +0 -8
- package/src/namespaces/sui/types.ts +0 -25
- package/src/namespaces/sui/utils.ts +0 -56
- package/src/namespaces/tron/actions.ts +0 -3
- package/src/namespaces/tron/after.ts +0 -3
- package/src/namespaces/tron/and.ts +0 -5
- package/src/namespaces/tron/before.ts +0 -3
- package/src/namespaces/tron/builders.ts +0 -15
- package/src/namespaces/tron/constants.ts +0 -8
- package/src/namespaces/tron/mod.ts +0 -8
- package/src/namespaces/tron/types.ts +0 -14
- package/src/namespaces/tron/utils.ts +0 -18
- package/src/namespaces/utxo/actions.ts +0 -3
- package/src/namespaces/utxo/after.ts +0 -3
- package/src/namespaces/utxo/and.ts +0 -5
- package/src/namespaces/utxo/before.ts +0 -3
- package/src/namespaces/utxo/builders.ts +0 -12
- package/src/namespaces/utxo/constants.ts +0 -2
- package/src/namespaces/utxo/mod.ts +0 -8
- package/src/namespaces/utxo/types.ts +0 -14
- package/src/namespaces/utxo/utils.ts +0 -18
- package/src/namespaces/xrpl/builders.ts +0 -14
- package/src/namespaces/xrpl/constants.ts +0 -7
- package/src/namespaces/xrpl/mod.ts +0 -5
- package/src/namespaces/xrpl/types.ts +0 -16
- package/src/namespaces/xrpl/utils.ts +0 -15
- package/src/types/accounts.ts +0 -12
- package/src/types/mod.ts +0 -1
- package/src/types/utils.ts +0 -7
- /package/src/{types/actions.ts → hub/types.ts} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Actions, Context, Operators } from '../hub/namespaces/types.js';
|
|
2
|
+
import type { AnyFunction, FunctionWithContext } from '../hub/types.js';
|
|
3
|
+
export interface ActionByBuilder<T, Context> {
|
|
4
|
+
actionName: keyof T;
|
|
5
|
+
and: Operators<T>;
|
|
6
|
+
or: Operators<T>;
|
|
7
|
+
after: Operators<T>;
|
|
8
|
+
before: Operators<T>;
|
|
9
|
+
action: FunctionWithContext<T[keyof T], Context>;
|
|
10
|
+
}
|
|
11
|
+
export declare class ActionBuilder<T extends Actions<T>, K extends keyof T> {
|
|
12
|
+
#private;
|
|
13
|
+
readonly name: K;
|
|
14
|
+
constructor(name: K);
|
|
15
|
+
and(action: FunctionWithContext<AnyFunction, Context<T>>): this;
|
|
16
|
+
or(action: FunctionWithContext<AnyFunction, Context<T>>): this;
|
|
17
|
+
before(action: FunctionWithContext<AnyFunction, Context<T>>): this;
|
|
18
|
+
after(action: FunctionWithContext<AnyFunction, Context<T>>): this;
|
|
19
|
+
action(action: FunctionWithContext<T[keyof T], Context<T>>): this;
|
|
20
|
+
build(): ActionByBuilder<T, Context<T>>;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=action.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/builders/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAExE,MAAM,WAAW,eAAe,CAAC,CAAC,EAAE,OAAO;IACzC,UAAU,EAAE,MAAM,CAAC,CAAC;IACpB,GAAG,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IAClB,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACjB,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACpB,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;IACrB,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;CAClD;AAYD,qBAAa,aAAa,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC;;IAChE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;gBAOL,IAAI,EAAE,CAAC;IAIZ,GAAG,CAAC,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAQxD,EAAE,CAAC,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAQvD,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAQ3D,KAAK,CAAC,MAAM,EAAE,mBAAmB,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAQ1D,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAK1D,KAAK,IAAI,eAAe,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;CAc/C"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/builders/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAEzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { ActionByBuilder } from './action.js';
|
|
2
|
+
import type { ProxiedNamespace } from './types.js';
|
|
3
|
+
import type { Actions, Context } from '../hub/namespaces/mod.js';
|
|
4
|
+
import type { NamespaceConfig } from '../hub/store/mod.js';
|
|
5
|
+
import type { FunctionWithContext } from '../hub/types.js';
|
|
6
|
+
/**
|
|
7
|
+
* There are Namespace's methods that should be called directly on Proxy object.
|
|
8
|
+
* The Proxy object is creating in `.build`.
|
|
9
|
+
*/
|
|
10
|
+
export declare const allowedMethods: readonly ["init", "state", "after", "before", "and_then", "or_else", "store"];
|
|
11
|
+
export declare class NamespaceBuilder<T extends Actions<T>> {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(id: string, providerId: string);
|
|
14
|
+
/** There are some predefined configs that can be set for each namespace separately */
|
|
15
|
+
config<K extends keyof NamespaceConfig>(name: K, value: NamespaceConfig[K]): this;
|
|
16
|
+
/**
|
|
17
|
+
* Getting a list of actions.
|
|
18
|
+
*
|
|
19
|
+
* e.g.:
|
|
20
|
+
* ```ts
|
|
21
|
+
* .action([
|
|
22
|
+
* ["connect", () => {}],
|
|
23
|
+
* ["disconnect", () => {}]
|
|
24
|
+
* ])
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
action<K extends keyof T>(action: (readonly [K, FunctionWithContext<T[K], Context<T>>])[]): NamespaceBuilder<T>;
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* Add a single action
|
|
32
|
+
*
|
|
33
|
+
* e.g.:
|
|
34
|
+
* ```ts
|
|
35
|
+
* .action( ["connect", () => {}] )
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
action<K extends keyof T>(action: K, actionFn: FunctionWithContext<T[K], Context<T>>): NamespaceBuilder<T>;
|
|
39
|
+
action(action: ActionByBuilder<T, Context<T>>): NamespaceBuilder<T>;
|
|
40
|
+
/**
|
|
41
|
+
* By calling build, an instance of Namespace will be built.
|
|
42
|
+
*
|
|
43
|
+
* Note: it's not exactly a `Namespace`, it returns a Proxy which add more convenient use like `namespace.connect()` instead of `namespace.run("connect")`
|
|
44
|
+
*/
|
|
45
|
+
build(): ProxiedNamespace<T>;
|
|
46
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e,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC;IA0C1E;;;;OAIG;IACI,KAAK,IAAI,gBAAgB,CAAC,CAAC,CAAC;CAwHpC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { ProxiedNamespace } from './types.js';
|
|
2
|
+
import type { Actions } from '../hub/namespaces/mod.js';
|
|
3
|
+
import type { ExtendableInternalActions, ProviderBuilderOptions } from '../hub/provider/mod.js';
|
|
4
|
+
import type { ProviderConfig } from '../hub/store/mod.js';
|
|
5
|
+
import { Provider } from '../hub/provider/mod.js';
|
|
6
|
+
/**
|
|
7
|
+
* Fluent builder for `Provider`. Each `.add(key, namespace)` call accumulates
|
|
8
|
+
* the registered namespace map into the `TNS` generic, so the resulting
|
|
9
|
+
* `Provider<TNS>` knows exactly which namespaces it owns.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* const phantom = new ProviderBuilder('phantom')
|
|
14
|
+
* .config('metadata', meta)
|
|
15
|
+
* .add('evm', evmNamespace) // adds { evm: EvmActions }
|
|
16
|
+
* .add('solana', solanaNamespace) // adds { solana: SolanaActions }
|
|
17
|
+
* .build();
|
|
18
|
+
* // Provider<{ evm: EvmActions; solana: SolanaActions }>
|
|
19
|
+
* ```
|
|
20
|
+
* `{}` is intentional: identity element under intersection so the first
|
|
21
|
+
* `.add(K, T)` produces `{} & Record<K, T> = Record<K, T>` and subsequent calls
|
|
22
|
+
* accumulate cleanly. Not the unsafe "any non-nullish" usage the rule targets.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ProviderBuilder<TNS = {}> {
|
|
25
|
+
#private;
|
|
26
|
+
constructor(id: string, options?: ProviderBuilderOptions);
|
|
27
|
+
/**
|
|
28
|
+
* Register a namespace under `id`. Captures both the key and the namespace's
|
|
29
|
+
* action interface into the builder's `TNS` so subsequent operations are
|
|
30
|
+
* statically typed against the accumulated set.
|
|
31
|
+
*/
|
|
32
|
+
add<const K extends string, T extends Actions<T>>(id: K, namespace: ProxiedNamespace<T>): ProviderBuilder<TNS & Record<K, T>>;
|
|
33
|
+
config<K extends keyof ProviderConfig<TNS>>(name: K, value: ProviderConfig<TNS>[K]): this;
|
|
34
|
+
init(cb: Exclude<ExtendableInternalActions['init'], undefined>): this;
|
|
35
|
+
build(): Provider<TNS>;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../src/builders/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,KAAK,EACV,yBAAyB,EACzB,sBAAsB,EAEvB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAElD;;;;;;;;;;;;;;;;;GAiBG;AAEH,qBAAa,eAAe,CAAC,GAAG,GAAG,EAAE;;gBAWvB,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,sBAAsB;IAKxD;;;;OAIG;IACI,GAAG,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,EACrD,EAAE,EAAE,CAAC,EACL,SAAS,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAC7B,eAAe,CAAC,GAAG,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAQ/B,MAAM,CAAC,CAAC,SAAS,MAAM,cAAc,CAAC,GAAG,CAAC,EAC/C,IAAI,EAAE,CAAC,EACP,KAAK,EAAE,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAC5B,IAAI;IAKA,IAAI,CAAC,EAAE,EAAE,OAAO,CAAC,yBAAyB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI;IAKrE,KAAK,IAAI,QAAQ,CAAC,GAAG,CAAC;CAyB9B"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { allowedMethods } from './namespace.js';
|
|
2
|
+
import type { Actions, Namespace } from '../hub/namespaces/mod.js';
|
|
3
|
+
type NamespacePublicValues = {
|
|
4
|
+
namespaceId: string;
|
|
5
|
+
providerId: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* NamespaceBuilder is creating a proxy instead of return Namespace instance.
|
|
9
|
+
* The reason is improving access to actions. e.g `.connect()` instead of `.run('connect')`
|
|
10
|
+
*/
|
|
11
|
+
export type ProxiedNamespace<T extends Actions<T>> = T & Pick<Namespace<T>, (typeof allowedMethods)[number]> & NamespacePublicValues;
|
|
12
|
+
/**
|
|
13
|
+
* Map a key into the corresponding proxied namespace inside a namespace set.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```ts
|
|
17
|
+
* type List = { evm: EvmActions; solana: SolanaActions };
|
|
18
|
+
* FindProxiedNamespace<'solana', List>; // ProxiedNamespace<SolanaActions>
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export type FindProxiedNamespace<K extends keyof T, T> = T[K] extends Actions<T[K]> ? ProxiedNamespace<T[K]> : never;
|
|
22
|
+
export {};
|
|
23
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/builders/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGnE,KAAK,qBAAqB,GAAG;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,GACpD,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,GACnD,qBAAqB,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,IACnD,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Note: This only works native async, if we are going to support for old transpilers like Babel.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isAsync(fn: Function): boolean;
|
|
5
|
+
export declare function generateStoreId(providerId: string, namespace: string): string;
|
|
6
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/hub/helpers.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,wBAAgB,OAAO,CAAC,EAAE,EAAE,QAAQ,WAEnC;AAED,wBAAgB,eAAe,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,UAEpE"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { State as NamespaceState } from './namespaces/mod.js';
|
|
2
|
+
import type { Provider, State as ProviderState } from './provider/mod.js';
|
|
3
|
+
import type { Store } from './store/mod.js';
|
|
4
|
+
/**
|
|
5
|
+
* Hub stores providers with heterogeneous `TNS` shapes. `Provider<TNS>` is
|
|
6
|
+
* invariant in `TNS` (TNS appears in both reading and writing positions via
|
|
7
|
+
* the internal `Map`), so the only universally-assignable upper bound is
|
|
8
|
+
* `Provider<any>`. Concrete TNS information is preserved on each `Provider`
|
|
9
|
+
* instance itself — consumers recover precise types via `provider.get('evm')`.
|
|
10
|
+
*
|
|
11
|
+
* TODO: consider making `Provider<TNS>` covariant in TNS so this `any` can be
|
|
12
|
+
* replaced with `Provider<unknown>`. Requires switching the internal storage
|
|
13
|
+
* to a covariant container (e.g. `ReadonlyMap` semantics), moving TNS-typed
|
|
14
|
+
* constructor inputs out of the public class surface (factory pattern or
|
|
15
|
+
* interface + impl), and dropping TNS info from `getAll()`'s return type.
|
|
16
|
+
* Bigger surgery than this PR; deserves its own review cycle.
|
|
17
|
+
*/
|
|
18
|
+
type AnyProvider = Provider<any>;
|
|
19
|
+
type HubState = {
|
|
20
|
+
[key in string]: ProviderState & {
|
|
21
|
+
namespaces: NamespaceState[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
type RunAllResult = {
|
|
25
|
+
id: string;
|
|
26
|
+
provider: unknown;
|
|
27
|
+
namespaces: unknown[];
|
|
28
|
+
};
|
|
29
|
+
interface HubOptions {
|
|
30
|
+
store?: Store;
|
|
31
|
+
}
|
|
32
|
+
export declare class Hub {
|
|
33
|
+
#private;
|
|
34
|
+
constructor(options?: HubOptions);
|
|
35
|
+
init(): void;
|
|
36
|
+
runAll(action: string): RunAllResult[];
|
|
37
|
+
add(id: string, provider: AnyProvider): this;
|
|
38
|
+
remove(id: string): this;
|
|
39
|
+
get(providerId: string): AnyProvider | undefined;
|
|
40
|
+
getAll(): Map<string, AnyProvider>;
|
|
41
|
+
state(): HubState;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
44
|
+
//# sourceMappingURL=hub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hub.d.ts","sourceRoot":"","sources":["../../src/hub/hub.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,KAAK,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,QAAQ,EAAE,KAAK,IAAI,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C;;;;;;;;;;;;;GAaG;AAEH,KAAK,WAAW,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC;AAEjC,KAAK,QAAQ,GAAG;KACb,GAAG,IAAI,MAAM,GAAG,aAAa,GAAG;QAC/B,UAAU,EAAE,cAAc,EAAE,CAAC;KAC9B;CACF,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,OAAO,CAAC;IAClB,UAAU,EAAE,OAAO,EAAE,CAAC;CACvB,CAAC;AAEF,UAAU,UAAU;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf;AAED,qBAAa,GAAG;;gBAIF,OAAO,CAAC,EAAE,UAAU;IAIhC,IAAI;IASJ,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE;IAqCtC,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,IAAI;IAQ5C,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAaxB,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAIhD,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC;IAIlC,KAAK,IAAI,QAAQ;CAwBlB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type { Actions, Subscriber, SubscriberCleanUp, Context, } from './namespaces/mod.js';
|
|
2
|
+
export { Namespace } from './namespaces/mod.js';
|
|
3
|
+
export { Provider } from './provider/mod.js';
|
|
4
|
+
export type { RegisteredNamespaces } from './provider/mod.js';
|
|
5
|
+
export { Hub } from './hub.js';
|
|
6
|
+
export type { Store, State, ProviderMetadata } from './store/mod.js';
|
|
7
|
+
export { createStore, guessProviderStateSelector, namespaceStateSelector, } from './store/mod.js';
|
|
8
|
+
export { generateStoreId } from './helpers.js';
|
|
9
|
+
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../src/hub/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,OAAO,GACR,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,YAAY,EAAE,KAAK,EAAE,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EACL,WAAW,EACX,0BAA0B,EAC1B,sBAAsB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const ACTION_NOT_FOUND_ERROR: (name: string) => string;
|
|
2
|
+
export declare const OR_ELSE_ACTION_FAILED_ERROR: (name: string) => string;
|
|
3
|
+
export declare const BEFORE_ACTION_FAILED_ERROR: (name: string) => string;
|
|
4
|
+
export declare const NO_STORE_FOUND_ERROR = "For setup store, you should set `store` first.";
|
|
5
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/errors.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,sBAAsB,SAAU,MAAM,WACsB,CAAC;AAE1E,eAAO,MAAM,2BAA2B,SAAU,MAAM,WACZ,CAAC;AAE7C,eAAO,MAAM,0BAA0B,SAAU,MAAM,WACS,CAAC;AAEjE,eAAO,MAAM,oBAAoB,mDACiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,KAAK,EACL,iBAAiB,IAAI,UAAU,EAC/B,OAAO,EACP,OAAO,GACR,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import type { Actions, Context, GetState, RegisteredActions, SetState } from './types.js';
|
|
2
|
+
import type { NamespaceConfig, Store } from '../store/mod.js';
|
|
3
|
+
import type { AndFunction, AnyFunction, FunctionWithContext } from '../types.js';
|
|
4
|
+
type Params = any[];
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* A Namespace is a unit of wallets where usually handles connecting, signing, accounts, ...
|
|
8
|
+
* It will be injected by wallet in its object, for example, `window.phantom.ethereum` or `window.phantom.solana`
|
|
9
|
+
* Each namespace (like solana) has its own functionality which is not shared between all the blockchains.
|
|
10
|
+
* For example in EVM namespaces, you can have different networks (e.g. Ethereum,Polygon, ...) and there are specific flows to handle connecting to them or add a network and etc.
|
|
11
|
+
* But Solana doesn't have this concept and you will directly always connect to solana itself.
|
|
12
|
+
* This is true for signing a transaction, getting information about blockchain and more.
|
|
13
|
+
* So by creating a namespace for each of these, we can define a custom namespace based on blockchain's properties.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
declare class Namespace<T extends Actions<T>> {
|
|
17
|
+
#private;
|
|
18
|
+
/** it will be used for `store` and accessing to store by its id mainly. */
|
|
19
|
+
readonly namespaceId: string;
|
|
20
|
+
/** it will be used for `store` and accessing to store by its id mainly. */
|
|
21
|
+
readonly providerId: string;
|
|
22
|
+
constructor(id: string, providerId: string, options: {
|
|
23
|
+
store?: Store;
|
|
24
|
+
configs?: NamespaceConfig;
|
|
25
|
+
actions: RegisteredActions<T>;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* This is an special action that will be called **only once**.
|
|
29
|
+
* We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const myInit = () => { whatever; }
|
|
33
|
+
* const actions = new Map();
|
|
34
|
+
* actions.set("init", myInit)
|
|
35
|
+
* const ns = new Namespace(..., {actions});
|
|
36
|
+
*
|
|
37
|
+
* // Will run `myInit`
|
|
38
|
+
* ns.init()
|
|
39
|
+
*
|
|
40
|
+
* // Will not run `myInit` anymore.
|
|
41
|
+
* ns.init()
|
|
42
|
+
* ns.init()
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
init(): void;
|
|
46
|
+
/**
|
|
47
|
+
* Reading states from store and also update them.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* const ns = new Namespace(...);
|
|
52
|
+
* const [getState, setState] = ns.state();
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
state(): [GetState, SetState];
|
|
56
|
+
/**
|
|
57
|
+
* For keeping state, we need a store. all the states will be write to/read from store.
|
|
58
|
+
*
|
|
59
|
+
* Note: Store can be setup on constructor as well.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* const myStore = createStore();
|
|
64
|
+
* const ns = new Namespace(...);
|
|
65
|
+
* ns.store(myStore);
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
store(store: Store): this;
|
|
69
|
+
/**
|
|
70
|
+
* It's a boolean operator to run a sync function if action ran successfully.
|
|
71
|
+
* For example, if we have a `connect` action, we can add function to be run after `connect` if it ran successfully.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const ns = new Namespace(..);
|
|
76
|
+
*
|
|
77
|
+
* ns.and_then('connect', (context) => {
|
|
78
|
+
* ...
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
*/
|
|
83
|
+
and_then<K extends keyof T>(actionName: K, operatorFn: FunctionWithContext<AndFunction<T, K>, Context>): this;
|
|
84
|
+
/**
|
|
85
|
+
* It's a boolean operator to run a function to handle when an action fails.
|
|
86
|
+
* For example, if we have a `connect` action, we can add function to be run when `connect` fails (throw an error).
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```ts
|
|
90
|
+
* const ns = new Namespace(..);
|
|
91
|
+
*
|
|
92
|
+
* ns.or_else('connect', (context, error) => {
|
|
93
|
+
* ...
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
or_else<K extends keyof T>(actionName: K, operatorFn: FunctionWithContext<AnyFunction, Context>): this;
|
|
98
|
+
/**
|
|
99
|
+
* Running a function after a specific action
|
|
100
|
+
*
|
|
101
|
+
* Note: the context can be set from outside as well. this is useful for Provider to set its context instead of namespace context.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```ts
|
|
105
|
+
* const ns = new Namespace(...);
|
|
106
|
+
*
|
|
107
|
+
* ns.after("connect", (context) => {});
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
after<K extends keyof T, C = unknown>(actionName: K, hook: FunctionWithContext<AnyFunction, C>, options?: {
|
|
111
|
+
context?: C;
|
|
112
|
+
}): this;
|
|
113
|
+
/**
|
|
114
|
+
* Running a function before a specific action
|
|
115
|
+
*
|
|
116
|
+
* Note: the context can be set from outside as well. this is useful for Provider to set its context instead of using namespace context.
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```ts
|
|
120
|
+
* const ns = new Namespace(...);
|
|
121
|
+
*
|
|
122
|
+
* ns.before("connect", (context) => {});
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
before<K extends keyof T, C = unknown>(actionName: K, hook: FunctionWithContext<AnyFunction, C>, options?: {
|
|
126
|
+
context?: C;
|
|
127
|
+
}): this;
|
|
128
|
+
has<K extends keyof T>(actionName: K): boolean;
|
|
129
|
+
/**
|
|
130
|
+
*
|
|
131
|
+
* Registered actions will be called using `run`. it will run an action and all the operators or hooks that assigned.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* const actions = new Map();
|
|
136
|
+
* actions.set('connect', connectAction);
|
|
137
|
+
*
|
|
138
|
+
* const ns = new Namespace(NAMESPACE, PROVIDER_ID, {
|
|
139
|
+
* actions: actions,
|
|
140
|
+
* });
|
|
141
|
+
*
|
|
142
|
+
* ns.run("action");
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
run<K extends keyof T>(actionName: K, ...args: Params): unknown | Promise<unknown>;
|
|
146
|
+
}
|
|
147
|
+
export { Namespace };
|
|
148
|
+
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,OAAO,EACP,QAAQ,EAGR,iBAAiB,EACjB,QAAQ,EAET,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,KAAK,EACV,WAAW,EACX,WAAW,EACX,mBAAmB,EACpB,MAAM,aAAa,CAAC;AAYrB,KAAK,MAAM,GAAG,GAAG,EAAE,CAAC;AAEpB;;;;;;;;;;GAUG;AACH,cAAM,SAAS,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC;;IAClC,2EAA2E;IAC3E,SAAgB,WAAW,EAAE,MAAM,CAAC;IACpC,2EAA2E;IAC3E,SAAgB,UAAU,EAAE,MAAM,CAAC;gBAgBjC,E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IAeA,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,OAAO;IAGrD;;;;;;;;;;;;;;;OAeG;IACI,GAAG,CAAC,CAAC,SAAS,MAAM,CAAC,EAC1B,UAAU,EAAE,CAAC,EACb,GAAG,IAAI,EAAE,MAAM,GACd,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;CAqK9B;AAED,OAAO,EAAE,SAAS,EAAE,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { NamespaceData } from '../store/mod.js';
|
|
2
|
+
import type { AnyFunction, FunctionWithContext } from '../types.js';
|
|
3
|
+
type ActionName<K> = K | Omit<K, string>;
|
|
4
|
+
type Args = any[];
|
|
5
|
+
type ActionResult = any;
|
|
6
|
+
export type Subscriber<C extends Actions<C>> = (context: Context<C>, ...args: Args) => void;
|
|
7
|
+
export type SubscriberCleanUp<C extends Actions<C>> = (context: Context<C>, ...args: Args) => void;
|
|
8
|
+
export type CanEagerConnect<C extends Actions<C>> = (context: Context<C>, ...args: Args) => void;
|
|
9
|
+
export type State = NamespaceData;
|
|
10
|
+
export type SetState = <K extends keyof State>(name: K, value: State[K]) => void;
|
|
11
|
+
export type GetState = {
|
|
12
|
+
(): State;
|
|
13
|
+
<K extends keyof State>(name: K): State[K];
|
|
14
|
+
};
|
|
15
|
+
export type RegisteredActions<T extends Actions<T>> = Map<ActionName<keyof T>, FunctionWithContext<T[keyof T], Context<T>>>;
|
|
16
|
+
export type AndUseActions<T> = Map<keyof T, AnyFunction>;
|
|
17
|
+
export type Operators<T> = Map<keyof T, AnyFunction[]>;
|
|
18
|
+
export type HooksWithOptions<T> = Map<keyof T, {
|
|
19
|
+
hook: AnyFunction;
|
|
20
|
+
options?: {
|
|
21
|
+
context?: unknown;
|
|
22
|
+
};
|
|
23
|
+
}[]>;
|
|
24
|
+
export type Context<T extends Actions<T> = object> = {
|
|
25
|
+
state: () => [GetState, SetState];
|
|
26
|
+
action: (name: keyof T, ...args: Args) => ActionResult;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* This actually define what kind of action will be implemented in namespaces.
|
|
30
|
+
* For example evm namespace will have .connect(chain: string) and .switchNetwork
|
|
31
|
+
* But solana namespace only have: `.connect()`.
|
|
32
|
+
* This actions will be passed to this generic.
|
|
33
|
+
*/
|
|
34
|
+
export type Actions<T> = Record<keyof T, AnyFunction>;
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hub/namespaces/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEpE,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEzC,KAAK,IAAI,GAAG,GAAG,EAAE,CAAC;AAElB,KAAK,YAAY,GAAG,GAAG,CAAC;AAExB,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CAC7C,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,GAAG,IAAI,EAAE,IAAI,KACV,IAAI,CAAC;AACV,MAAM,MAAM,iBAAiB,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CACpD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,GAAG,IAAI,EAAE,IAAI,KACV,IAAI,CAAC;AACV,MAAM,MAAM,eAAe,CAAC,CAAC,SAAS,OAAO,CAAC,CAAC,CAAC,IAAI,CAClD,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EACnB,GAAG,IAAI,EAAE,IAAI,KACV,IAAI,CAAC;AACV,MAAM,MAAM,KAAK,GAAG,a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M,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/mod.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,yBAAyB,EACzB,oBAAoB,EACpB,KAAK,EACL,OAAO,EACP,sBAAsB,GACvB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { Context, ExtendableInternalActions, GetState, RegisteredNamespaces, SetState } from './types.js';
|
|
2
|
+
import type { FindProxiedNamespace } from '../../builders/mod.js';
|
|
3
|
+
import type { ProviderConfig, ProviderInfo, Store } from '../store/mod.js';
|
|
4
|
+
import type { AnyFunction, FunctionWithContext } from '../types.js';
|
|
5
|
+
/**
|
|
6
|
+
* A `Provider` represents one wallet/integration and owns the set of namespaces
|
|
7
|
+
* that wallet exposes (e.g. `evm`, `solana`).
|
|
8
|
+
*
|
|
9
|
+
* The `TNS` generic captures exactly which namespaces this provider supports.
|
|
10
|
+
* It's normally inferred by `ProviderBuilder` from chained `.add()` calls, so
|
|
11
|
+
* `phantom.get('cosmos')` is a compile-time error if Phantom never registered
|
|
12
|
+
* `cosmos`. Construct directly only when you have a precise namespace shape
|
|
13
|
+
* to pass via `new Provider<MyNamespaces>(...)`.
|
|
14
|
+
*/
|
|
15
|
+
export declare class Provider<TNS = unknown> {
|
|
16
|
+
#private;
|
|
17
|
+
readonly id: string;
|
|
18
|
+
readonly version = "1.0";
|
|
19
|
+
constructor(id: string, namespaces: RegisteredNamespaces<TNS>, configs: ProviderConfig<TNS>, options?: {
|
|
20
|
+
/**
|
|
21
|
+
* There are some cases we need to have a behavior like initializing a provider which will be run when we are creating an instance.
|
|
22
|
+
* These internal steps and behaviors will be useful for library user to extend the behavior by running a specific code.
|
|
23
|
+
*/
|
|
24
|
+
extendInternalActions?: ExtendableInternalActions;
|
|
25
|
+
store?: Store;
|
|
26
|
+
});
|
|
27
|
+
/**
|
|
28
|
+
* This is an special callback that will be called **only once**.
|
|
29
|
+
* We don't call this in `constructor` and developer should call this manually. we only ensure it will be called once.
|
|
30
|
+
*
|
|
31
|
+
* ```ts
|
|
32
|
+
* const myInit = () => { whatever; } *
|
|
33
|
+
* const provider = new Provider(..., {extendInternalActions: {init: myInit} });
|
|
34
|
+
*
|
|
35
|
+
* // Will run `myInit`
|
|
36
|
+
* provider.init()
|
|
37
|
+
*
|
|
38
|
+
* // Will not run `myInit` anymore.
|
|
39
|
+
* provider.init()
|
|
40
|
+
* provider.init()
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
init(): void;
|
|
44
|
+
/**
|
|
45
|
+
* Getting state of a provider.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* const provider = new Provider(...);
|
|
50
|
+
* const [getState, setState] = provider.state();
|
|
51
|
+
*
|
|
52
|
+
* getState('installed');
|
|
53
|
+
* // or
|
|
54
|
+
* getState().installed;
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
state(): [GetState, SetState];
|
|
58
|
+
/**
|
|
59
|
+
* For keeping state, we need a store. all the states will be write to/read from store.
|
|
60
|
+
*
|
|
61
|
+
* **Note: When you are setting an store for provider, it will be set for its namespaces automatically as well**
|
|
62
|
+
*/
|
|
63
|
+
store(store: Store): this;
|
|
64
|
+
/**
|
|
65
|
+
* Getting information about a provider which has been set on constructing Provider.
|
|
66
|
+
*/
|
|
67
|
+
info(): ProviderInfo<TNS> | undefined;
|
|
68
|
+
/**
|
|
69
|
+
* A list of registered _proxied_ namespaces.
|
|
70
|
+
*/
|
|
71
|
+
getAll(): RegisteredNamespaces<TNS>;
|
|
72
|
+
/**
|
|
73
|
+
* Get a registered namespace in provider by its **namespace key**.
|
|
74
|
+
*
|
|
75
|
+
* Note: difference between namespace key and namespace id is the first one
|
|
76
|
+
* is the key under which the namespace is registered (the `K` in `.add(K, ns)`),
|
|
77
|
+
* and the second one is the runtime `namespaceId` (e.g. `'eip155'`) chosen
|
|
78
|
+
* when constructing the namespace itself.
|
|
79
|
+
*/
|
|
80
|
+
get<K extends keyof TNS>(id: K): FindProxiedNamespace<K, TNS> | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Get a registered namespace by its **namespaceId** (the runtime id chosen
|
|
83
|
+
* when constructing the namespace). Returns the union of all namespaces this
|
|
84
|
+
* provider supports — caller is expected to discriminate via `namespaceId`.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* const provider = new Provider(...);
|
|
89
|
+
* provider.findByNamespace("whatever-id-i-set-for-namespace")
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
findByNamespace(namespaceLookingFor: string): FindProxiedNamespace<keyof TNS, TNS> | undefined;
|
|
93
|
+
/**
|
|
94
|
+
* Running a hook function _before_ a specific action for **all registered namespaces**.
|
|
95
|
+
*/
|
|
96
|
+
before(actionName: string, hookFn: FunctionWithContext<AnyFunction, Context>): this;
|
|
97
|
+
/**
|
|
98
|
+
* Running a hook function _after_ a specific action for **all registered namespaces**.
|
|
99
|
+
*/
|
|
100
|
+
after(actionName: string, hookFn: FunctionWithContext<AnyFunction, Context>): this;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/provider.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EACP,yBAAyB,EACzB,QAAQ,EACR,oBAAoB,EACpB,QAAQ,EAET,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;A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C,GAChD,IAAI;CA+CR"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FindProxiedNamespace } from '../../builders/mod.js';
|
|
2
|
+
import type { Store } from '../mod.js';
|
|
3
|
+
import type { AnyFunction, FunctionWithContext } from '../types.js';
|
|
4
|
+
export type Context = {
|
|
5
|
+
state: () => [GetState, SetState];
|
|
6
|
+
};
|
|
7
|
+
export interface State {
|
|
8
|
+
installed: boolean;
|
|
9
|
+
connected: boolean;
|
|
10
|
+
connecting: boolean;
|
|
11
|
+
}
|
|
12
|
+
export type SetState = <K extends keyof Pick<State, 'installed'>>(name: K, value: State[K]) => void;
|
|
13
|
+
export type GetState = {
|
|
14
|
+
(): State;
|
|
15
|
+
<K extends keyof State>(name: K): State[K];
|
|
16
|
+
};
|
|
17
|
+
export interface ExtendableInternalActions {
|
|
18
|
+
init?: FunctionWithContext<AnyFunction, Context>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The internal `Provider.#namespaces` map type — keys are the registered
|
|
22
|
+
* namespace ids, values are their corresponding proxied namespaces.
|
|
23
|
+
*/
|
|
24
|
+
export type RegisteredNamespaces<T> = Map<keyof T, FindProxiedNamespace<keyof T, T>>;
|
|
25
|
+
export type ProviderBuilderOptions = {
|
|
26
|
+
store?: Store;
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/hub/provider/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,MAAM,OAAO,GAAG;IACpB,KAAK,EAAE,MAAM,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC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