@txnlab/use-wallet 2.5.0 → 2.6.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.
Files changed (34) hide show
  1. package/README.md +12 -0
  2. package/dist/cjs/index.js +242 -44
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/src/clients/base/base.d.ts +1 -1
  5. package/dist/cjs/src/clients/index.d.ts +3 -2
  6. package/dist/cjs/src/clients/kibisis/constants.d.ts +1 -1
  7. package/dist/cjs/src/clients/kibisis/utils.d.ts +9 -0
  8. package/dist/cjs/src/clients/kibisis/utils.test.d.ts +1 -0
  9. package/dist/cjs/src/clients/magic/client.d.ts +35 -0
  10. package/dist/cjs/src/clients/magic/constants.d.ts +1 -0
  11. package/dist/cjs/src/clients/magic/index.d.ts +2 -0
  12. package/dist/cjs/src/clients/magic/types.d.ts +27 -0
  13. package/dist/cjs/src/constants/constants.d.ts +2 -1
  14. package/dist/cjs/src/store/state/walletStore.d.ts +2 -2
  15. package/dist/cjs/src/testUtils/mockClients.d.ts +3 -0
  16. package/dist/cjs/src/types/providers.d.ts +13 -1
  17. package/dist/cjs/src/types/wallet.d.ts +2 -1
  18. package/dist/esm/index.js +242 -45
  19. package/dist/esm/src/clients/base/base.d.ts +1 -1
  20. package/dist/esm/src/clients/index.d.ts +3 -2
  21. package/dist/esm/src/clients/kibisis/constants.d.ts +1 -1
  22. package/dist/esm/src/clients/kibisis/utils.d.ts +9 -0
  23. package/dist/esm/src/clients/kibisis/utils.test.d.ts +1 -0
  24. package/dist/esm/src/clients/magic/client.d.ts +35 -0
  25. package/dist/esm/src/clients/magic/constants.d.ts +1 -0
  26. package/dist/esm/src/clients/magic/index.d.ts +2 -0
  27. package/dist/esm/src/clients/magic/types.d.ts +27 -0
  28. package/dist/esm/src/constants/constants.d.ts +2 -1
  29. package/dist/esm/src/store/state/walletStore.d.ts +2 -2
  30. package/dist/esm/src/testUtils/mockClients.d.ts +3 -0
  31. package/dist/esm/src/types/providers.d.ts +13 -1
  32. package/dist/esm/src/types/wallet.d.ts +2 -1
  33. package/dist/index.d.ts +65 -6
  34. package/package.json +14 -1
@@ -8,7 +8,7 @@ declare abstract class BaseClient {
8
8
  keepWCAlive: HTMLAudioElement;
9
9
  metadata: Metadata;
10
10
  static metadata: Metadata;
11
- abstract connect(onDisconnect: () => void): Promise<Wallet>;
11
+ abstract connect(onDisconnect: () => void, arg?: any): Promise<Wallet>;
12
12
  abstract disconnect(): Promise<void>;
13
13
  abstract reconnect(onDisconnect: () => void): Promise<Wallet | null>;
14
14
  abstract signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
@@ -6,13 +6,14 @@ import exodus from './exodus';
6
6
  import algosigner from './algosigner';
7
7
  import lute from './lute';
8
8
  import walletconnect from './walletconnect2';
9
+ import magic from './magic';
9
10
  import kmd from './kmd';
10
11
  import mnemonic from './mnemonic';
11
12
  import { CustomProvider } from './custom/types';
12
13
  import custom from './custom';
13
14
  import kibisis from './kibisis';
14
- export { pera, myalgo, defly, exodus, algosigner, lute, walletconnect, kmd, mnemonic, custom, CustomProvider, kibisis };
15
+ export { pera, myalgo, defly, exodus, algosigner, lute, walletconnect, kmd, mnemonic, custom, CustomProvider, kibisis, magic };
15
16
  declare const _default: {
16
- [x: string]: typeof pera | typeof myalgo | typeof defly | typeof exodus | typeof algosigner | typeof lute | typeof walletconnect | typeof kmd | typeof mnemonic | typeof custom | typeof kibisis | typeof daffi;
17
+ [x: string]: typeof pera | typeof myalgo | typeof defly | typeof exodus | typeof algosigner | typeof lute | typeof walletconnect | typeof kmd | typeof mnemonic | typeof custom | typeof kibisis | typeof magic | typeof daffi;
17
18
  };
18
19
  export default _default;
@@ -29,7 +29,7 @@ export declare const VOI_TESTNET_GENESIS_HASH = "IXnoWtviVVJW5LGivNFc0Dq14V3kqaX
29
29
  * timeouts
30
30
  */
31
31
  export declare const DEFAULT_REQUEST_TIMEOUT = 180000;
32
- export declare const LOWER_REQUEST_TIMEOUT = 3000;
32
+ export declare const LOWER_REQUEST_TIMEOUT = 750;
33
33
  export declare const UPPER_REQUEST_TIMEOUT = 300000;
34
34
  /**
35
35
  * icon
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Generates a UUID version 4 string. This function attempts to use the `crypto.randomUUID()` function from the Web
3
+ * Crypto API if it is available, otherwise it uses a polyfill method.
4
+ *
5
+ * NOTE: `crypto.randomUUID()` is not available in non-secure contexts; only localhost and HTTPS.
6
+ * @returns {string} a valid UUID version 4 string.
7
+ * @see {@link https://stackoverflow.com/a/2117523}
8
+ */
9
+ export declare function generateUuid(): string;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,35 @@
1
+ import BaseClient from '../base';
2
+ import { PROVIDER_ID } from '../../constants';
3
+ import type { Network } from '../../types/node';
4
+ import type { InitParams } from '../../types/providers';
5
+ import type { Wallet } from '../../types/wallet';
6
+ import type { MagicAuthConstructor, MagicAuthConnectOptions } from './types';
7
+ declare class MagicAuth extends BaseClient {
8
+ #private;
9
+ clientOptions?: MagicAuthConnectOptions;
10
+ network: Network;
11
+ constructor({ metadata, client, clientOptions, algosdk, algodClient, network }: MagicAuthConstructor);
12
+ static metadata: {
13
+ id: PROVIDER_ID;
14
+ name: string;
15
+ icon: string;
16
+ isWalletConnect: boolean;
17
+ };
18
+ static init({ clientOptions, algodOptions, clientStatic, getDynamicClient, algosdkStatic, network }: InitParams<PROVIDER_ID.MAGIC>): Promise<BaseClient | null>;
19
+ connect(_: () => void, arg?: any): Promise<Wallet>;
20
+ reconnect(): Promise<{
21
+ accounts: {
22
+ name: string;
23
+ address: string;
24
+ providerId: PROVIDER_ID;
25
+ email: string;
26
+ }[];
27
+ id: PROVIDER_ID;
28
+ name: string;
29
+ icon: string;
30
+ isWalletConnect: boolean;
31
+ } | null>;
32
+ disconnect(): Promise<void>;
33
+ signTransactions(connectedAccounts: string[], txnGroups: Uint8Array[] | Uint8Array[][], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
34
+ }
35
+ export default MagicAuth;
@@ -0,0 +1 @@
1
+ export declare const ICON: string;
@@ -0,0 +1,2 @@
1
+ import magic from './client';
2
+ export default magic;
@@ -0,0 +1,27 @@
1
+ import type algosdk from 'algosdk';
2
+ import type { Network } from '../../types/node';
3
+ import type { Metadata } from '../../types/wallet';
4
+ import { SDKBase, InstanceWithExtensions } from '@magic-sdk/provider';
5
+ import { AlgorandExtension } from '@magic-ext/algorand';
6
+ export type MagicAuthConnectOptions = {
7
+ apiKey: string;
8
+ };
9
+ export interface MagicAuthTransaction {
10
+ txn: string;
11
+ /**
12
+ * Optional list of addresses that must sign the transactions.
13
+ * Wallet skips to sign this txn if signers is empty array.
14
+ * If undefined, wallet tries to sign it.
15
+ */
16
+ signers?: string[];
17
+ }
18
+ export type MagicAuthConstructor = {
19
+ metadata: Metadata;
20
+ client: InstanceWithExtensions<SDKBase, {
21
+ algorand: AlgorandExtension;
22
+ }>;
23
+ clientOptions: MagicAuthConnectOptions;
24
+ algosdk: typeof algosdk;
25
+ algodClient: algosdk.Algodv2;
26
+ network: Network;
27
+ };
@@ -11,7 +11,8 @@ export declare enum PROVIDER_ID {
11
11
  EXODUS = "exodus",
12
12
  KIBISIS = "kibisis",
13
13
  WALLETCONNECT = "walletconnect",
14
- MNEMONIC = "mnemonic"
14
+ MNEMONIC = "mnemonic",
15
+ MAGIC = "magic"
15
16
  }
16
17
  export declare const DEFAULT_NETWORK: Network;
17
18
  export declare const DEFAULT_NODE_BASEURL = "https://mainnet-api.algonode.cloud";
@@ -30,7 +30,7 @@ export declare const useWalletStore: import("zustand").UseBoundStore<Omit<Omit<O
30
30
  };
31
31
  }, "setState"> & {
32
32
  setState<A extends string | {
33
- type: string;
33
+ type: unknown;
34
34
  }>(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: import("immer/dist/internal").WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined, action?: A | undefined): void;
35
35
  }>;
36
36
  export declare const useHydratedWalletStore: import("zustand").UseBoundStore<Omit<Omit<Omit<import("zustand").StoreApi<WalletStore>, "setState"> & {
@@ -47,6 +47,6 @@ export declare const useHydratedWalletStore: import("zustand").UseBoundStore<Omi
47
47
  };
48
48
  }, "setState"> & {
49
49
  setState<A extends string | {
50
- type: string;
50
+ type: unknown;
51
51
  }>(nextStateOrUpdater: WalletStore | Partial<WalletStore> | ((state: import("immer/dist/internal").WritableDraft<WalletStore>) => void), shouldReplace?: boolean | undefined, action?: A | undefined): void;
52
52
  }>;
@@ -12,6 +12,7 @@ import WalletConnectClient from '../clients/walletconnect2/client';
12
12
  import { PROVIDER_ID } from '../constants';
13
13
  import type { Account, ClientOptions } from '../types';
14
14
  import CustomWalletClient from '../clients/custom/client';
15
+ import MagicAuthClient from '../clients/magic/client';
15
16
  type ClientTypeMap = {
16
17
  [PROVIDER_ID.ALGOSIGNER]: AlgoSignerClient;
17
18
  [PROVIDER_ID.CUSTOM]: CustomWalletClient;
@@ -25,6 +26,7 @@ type ClientTypeMap = {
25
26
  [PROVIDER_ID.WALLETCONNECT]: WalletConnectClient;
26
27
  [PROVIDER_ID.LUTE]: LuteClient;
27
28
  [PROVIDER_ID.KIBISIS]: KibisisClient;
29
+ [PROVIDER_ID.MAGIC]: MagicAuthClient;
28
30
  };
29
31
  export declare const createMockClient: <T extends PROVIDER_ID>(providerId: T, clientOptions?: ClientOptions, accounts?: Array<Account>) => ClientTypeMap[T];
30
32
  export declare const createAlgoSignerMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => AlgoSignerClient;
@@ -39,4 +41,5 @@ export declare const createMnemonicMockInstance: (clientOptions?: ClientOptions,
39
41
  export declare const createMyAlgoMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => MyAlgoWalletClient;
40
42
  export declare const createPeraMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => PeraWalletClient;
41
43
  export declare const createWalletConnectMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => WalletConnectClient;
44
+ export declare const createMagicMockInstance: (clientOptions?: ClientOptions, accounts?: Array<Account>) => MagicAuthClient;
42
45
  export {};
@@ -17,6 +17,7 @@ import type { DaffiWalletConnectOptions } from '../clients/daffi/types';
17
17
  import type { NonEmptyArray } from './utilities';
18
18
  import type BaseClient from '../clients/base';
19
19
  import type { CustomOptions } from '../clients/custom/types';
20
+ import { Magic } from 'magic-sdk';
20
21
  export type ProviderConfigMapping = {
21
22
  [PROVIDER_ID.PERA]: {
22
23
  clientOptions?: PeraWalletConnectOptions;
@@ -78,6 +79,13 @@ export type ProviderConfigMapping = {
78
79
  clientStatic?: undefined;
79
80
  getDynamicClient?: undefined;
80
81
  };
82
+ [PROVIDER_ID.MAGIC]: {
83
+ clientOptions?: {
84
+ apiKey: string;
85
+ };
86
+ clientStatic?: undefined;
87
+ getDynamicClient?: () => Promise<typeof Magic>;
88
+ };
81
89
  };
82
90
  /**
83
91
  * Enforces correct configuration given for each provider. For example,
@@ -113,7 +121,11 @@ type DynamicClient<T> = {
113
121
  getDynamicClient: () => Promise<T>;
114
122
  };
115
123
  type OneOfStaticOrDynamicClient<T> = StaticClient<T> | DynamicClient<T>;
116
- type ProviderDef = (ProviderConfig<PROVIDER_ID.PERA> & OneOfStaticOrDynamicClient<typeof PeraWalletConnect>) | (ProviderConfig<PROVIDER_ID.DEFLY> & OneOfStaticOrDynamicClient<typeof DeflyWalletConnect>) | (ProviderConfig<PROVIDER_ID.DAFFI> & OneOfStaticOrDynamicClient<typeof DaffiWalletConnect>) | (ProviderConfig<PROVIDER_ID.LUTE> & OneOfStaticOrDynamicClient<typeof LuteConnect> & {
124
+ type ProviderDef = (ProviderConfig<PROVIDER_ID.PERA> & OneOfStaticOrDynamicClient<typeof PeraWalletConnect>) | (ProviderConfig<PROVIDER_ID.MAGIC> & OneOfStaticOrDynamicClient<typeof Magic> & {
125
+ clientOptions: {
126
+ apiKey: string;
127
+ };
128
+ }) | (ProviderConfig<PROVIDER_ID.DEFLY> & OneOfStaticOrDynamicClient<typeof DeflyWalletConnect>) | (ProviderConfig<PROVIDER_ID.DAFFI> & OneOfStaticOrDynamicClient<typeof DaffiWalletConnect>) | (ProviderConfig<PROVIDER_ID.LUTE> & OneOfStaticOrDynamicClient<typeof LuteConnect> & {
117
129
  clientOptions: LuteConnectOptions;
118
130
  }) | (ProviderConfig<PROVIDER_ID.WALLETCONNECT> & OneOfStaticOrDynamicClient<typeof WalletConnectModalSign> & {
119
131
  clientOptions: WalletConnectModalSignOptions;
@@ -4,12 +4,13 @@ export interface Account {
4
4
  name: string;
5
5
  address: string;
6
6
  authAddr?: string;
7
+ email?: string;
7
8
  }
8
9
  export type Provider = {
9
10
  accounts: Account[];
10
11
  isActive: boolean;
11
12
  isConnected: boolean;
12
- connect: () => Promise<void>;
13
+ connect: (arg?: any) => Promise<void>;
13
14
  disconnect: () => Promise<void>;
14
15
  reconnect: () => Promise<void>;
15
16
  setActiveProvider: () => void;