@orderly.network/core 0.0.5 → 0.0.6

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/index.d.mts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BehaviorSubject } from 'rxjs';
2
+ import { AccountStatusEnum } from '@orderly.network/types';
2
3
 
3
4
  interface OrderlyKeyPair {
4
5
  getPublicKey(): Promise<string>;
@@ -12,26 +13,54 @@ declare class BaseOrderlyKeyPair implements OrderlyKeyPair {
12
13
  getPublicKey(): Promise<string>;
13
14
  }
14
15
 
15
- interface KeyStore {
16
+ interface OrderlyKeyStore {
16
17
  getOrderlyKey: () => OrderlyKeyPair;
18
+ getAccountId: () => string | undefined;
19
+ setAccountId: (accountId: string) => void;
20
+ getAddress: () => string | undefined;
21
+ setAddress: (address: string) => void;
17
22
  generateKey: () => OrderlyKeyPair;
23
+ cleanKey: (key: string) => void;
24
+ cleanAllKey: () => void;
18
25
  setKey: (orderlyKey: string, secretKey: string) => void;
19
26
  }
20
- declare class LocalStorageStore implements KeyStore {
27
+ declare abstract class BaseKeyStore implements OrderlyKeyStore {
21
28
  private readonly networkId;
22
- private readonly accountId;
23
- constructor(networkId: string, accountId: string);
29
+ constructor(networkId: string);
30
+ abstract getOrderlyKey(): OrderlyKeyPair;
31
+ abstract getAccountId(): string | undefined;
32
+ abstract setAccountId(accountId: string): void;
33
+ abstract getAddress(): string | undefined;
34
+ abstract setAddress(address: string): void;
35
+ abstract generateKey(): OrderlyKeyPair;
36
+ abstract setKey(orderlyKey: string, secretKey: string): void;
37
+ abstract cleanAllKey(): void;
38
+ abstract cleanKey(key: string): void;
39
+ protected get keyPrefix(): string;
40
+ }
41
+ declare class LocalStorageStore extends BaseKeyStore {
24
42
  getOrderlyKey(): OrderlyKeyPair;
43
+ getAccountId(): string;
44
+ setAccountId(accountId: string): void;
45
+ getAddress(): string;
46
+ setAddress(address: string): void;
25
47
  generateKey(): BaseOrderlyKeyPair;
26
48
  setKey(orderlyKey: string, secretKey: string): void;
27
- private get _keyPrefix();
49
+ cleanAllKey(): void;
50
+ cleanKey(key: string): void;
28
51
  }
29
- declare class MockKeyStore implements KeyStore {
52
+ declare class MockKeyStore implements OrderlyKeyStore {
30
53
  private readonly secretKey;
31
54
  constructor(secretKey: string);
32
55
  generateKey(): BaseOrderlyKeyPair;
33
56
  getOrderlyKey(): BaseOrderlyKeyPair;
57
+ getAccountId(): string;
58
+ setAccountId(accountId: string): void;
59
+ getAddress(): string;
60
+ setAddress(address: string): void;
34
61
  setKey(orderlyKey: string, secretKey: string): void;
62
+ cleanAllKey(): void;
63
+ cleanKey(key: string): void;
35
64
  }
36
65
 
37
66
  type MessageFactor = {
@@ -61,10 +90,14 @@ type SignedMessagePayload = {
61
90
  */
62
91
  interface Signer {
63
92
  sign: (data: MessageFactor) => Promise<SignedMessagePayload>;
93
+ signText: (text: string) => Promise<{
94
+ signature: string;
95
+ publicKey: string;
96
+ }>;
64
97
  }
65
98
  declare class BaseSigner implements Signer {
66
99
  private readonly keyStore;
67
- constructor(keyStore: KeyStore);
100
+ constructor(keyStore: OrderlyKeyStore);
68
101
  sign(message: MessageFactor): Promise<SignedMessagePayload>;
69
102
  signText(text: string): Promise<{
70
103
  signature: string;
@@ -101,49 +134,13 @@ declare class SimpleDI {
101
134
  private constructor();
102
135
  }
103
136
 
104
- interface WalletClient {
105
- get address(): string;
106
- getBalance: () => Promise<any>;
107
- deposit: () => Promise<any>;
108
- connect: () => Promise<any>;
109
- }
110
- declare abstract class BaseWalletClient implements WalletClient {
111
- private readonly _address;
112
- constructor(_address: string);
113
- abstract getBalance(): Promise<any>;
114
- abstract deposit(): Promise<any>;
115
- abstract connect(): Promise<any>;
116
- get address(): string;
117
- }
118
- declare class SimpleWallet extends BaseWalletClient {
119
- getBalance(): Promise<any>;
120
- deposit(): Promise<any>;
121
- connect(): Promise<any>;
122
- }
123
-
124
- type wallet_BaseWalletClient = BaseWalletClient;
125
- declare const wallet_BaseWalletClient: typeof BaseWalletClient;
126
- type wallet_SimpleWallet = SimpleWallet;
127
- declare const wallet_SimpleWallet: typeof SimpleWallet;
128
- type wallet_WalletClient = WalletClient;
129
- declare namespace wallet {
130
- export {
131
- wallet_BaseWalletClient as BaseWalletClient,
132
- wallet_SimpleWallet as SimpleWallet,
133
- wallet_WalletClient as WalletClient,
134
- };
137
+ interface WalletAdapter {
138
+ getBalance: (address: string) => Promise<any>;
139
+ deposit: (from: string, to: string, amount: string) => Promise<any>;
135
140
  }
136
141
 
137
- type AccountStatus = "NotConnected" | "Connected" | "NotSignedIn" | "SignedIn";
138
- declare enum AccountStatusEnum {
139
- NotConnected = 0,
140
- Connected = 1,
141
- NotSignedIn = 2,
142
- SignedIn = 3,
143
- EnableTrading = 4
144
- }
145
142
  interface AccountState {
146
- status: AccountStatus;
143
+ status: AccountStatusEnum;
147
144
  accountId?: string;
148
145
  userId?: string;
149
146
  address?: string;
@@ -162,9 +159,11 @@ interface AccountState {
162
159
  */
163
160
  declare class Account {
164
161
  private readonly configStore;
165
- private walletClient?;
162
+ private readonly keyStore;
163
+ private readonly walletClient;
164
+ private _singer?;
166
165
  private _state$;
167
- constructor(configStore: ConfigStore, walletClient?: WalletClient | undefined);
166
+ constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, walletClient: WalletAdapter);
168
167
  /**
169
168
  * 登录
170
169
  * @param address 钱包地址
@@ -177,9 +176,10 @@ declare class Account {
177
176
  /**
178
177
  * 为账户设置钱包
179
178
  */
180
- set wallet(wallet: WalletClient | string);
179
+ set address(address: string);
181
180
  get state$(): BehaviorSubject<AccountState>;
182
181
  get stateValue(): AccountState;
182
+ get accountId(): string | undefined;
183
183
  /**
184
184
  * set user positions count
185
185
  */
@@ -187,6 +187,7 @@ declare class Account {
187
187
  set orders(orders: string[]);
188
188
  private _checkAccount;
189
189
  private _checkAccountExist;
190
+ get signer(): Signer;
190
191
  private getAccountInfo;
191
192
  private getBalance;
192
193
  private _fetch;
@@ -320,4 +321,11 @@ declare namespace WSMessage {
320
321
  }
321
322
  }
322
323
 
323
- export { API, Account, AccountState, AccountStatusEnum, BaseSigner, ConfigStore, KeyStore, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, getDefaultSigner, getMockSigner, wallet };
324
+ declare class Web3WalletAdapter implements Web3WalletAdapter {
325
+ private readonly web3;
326
+ constructor(web3: any);
327
+ getBalance(address: string): Promise<any>;
328
+ deposit(from: string, to: string, amount: string): Promise<any>;
329
+ }
330
+
331
+ export { API, Account, AccountState, BaseKeyStore, BaseSigner, ConfigStore, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, WalletAdapter, Web3WalletAdapter, getDefaultSigner, getMockSigner };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BehaviorSubject } from 'rxjs';
2
+ import { AccountStatusEnum } from '@orderly.network/types';
2
3
 
3
4
  interface OrderlyKeyPair {
4
5
  getPublicKey(): Promise<string>;
@@ -12,26 +13,54 @@ declare class BaseOrderlyKeyPair implements OrderlyKeyPair {
12
13
  getPublicKey(): Promise<string>;
13
14
  }
14
15
 
15
- interface KeyStore {
16
+ interface OrderlyKeyStore {
16
17
  getOrderlyKey: () => OrderlyKeyPair;
18
+ getAccountId: () => string | undefined;
19
+ setAccountId: (accountId: string) => void;
20
+ getAddress: () => string | undefined;
21
+ setAddress: (address: string) => void;
17
22
  generateKey: () => OrderlyKeyPair;
23
+ cleanKey: (key: string) => void;
24
+ cleanAllKey: () => void;
18
25
  setKey: (orderlyKey: string, secretKey: string) => void;
19
26
  }
20
- declare class LocalStorageStore implements KeyStore {
27
+ declare abstract class BaseKeyStore implements OrderlyKeyStore {
21
28
  private readonly networkId;
22
- private readonly accountId;
23
- constructor(networkId: string, accountId: string);
29
+ constructor(networkId: string);
30
+ abstract getOrderlyKey(): OrderlyKeyPair;
31
+ abstract getAccountId(): string | undefined;
32
+ abstract setAccountId(accountId: string): void;
33
+ abstract getAddress(): string | undefined;
34
+ abstract setAddress(address: string): void;
35
+ abstract generateKey(): OrderlyKeyPair;
36
+ abstract setKey(orderlyKey: string, secretKey: string): void;
37
+ abstract cleanAllKey(): void;
38
+ abstract cleanKey(key: string): void;
39
+ protected get keyPrefix(): string;
40
+ }
41
+ declare class LocalStorageStore extends BaseKeyStore {
24
42
  getOrderlyKey(): OrderlyKeyPair;
43
+ getAccountId(): string;
44
+ setAccountId(accountId: string): void;
45
+ getAddress(): string;
46
+ setAddress(address: string): void;
25
47
  generateKey(): BaseOrderlyKeyPair;
26
48
  setKey(orderlyKey: string, secretKey: string): void;
27
- private get _keyPrefix();
49
+ cleanAllKey(): void;
50
+ cleanKey(key: string): void;
28
51
  }
29
- declare class MockKeyStore implements KeyStore {
52
+ declare class MockKeyStore implements OrderlyKeyStore {
30
53
  private readonly secretKey;
31
54
  constructor(secretKey: string);
32
55
  generateKey(): BaseOrderlyKeyPair;
33
56
  getOrderlyKey(): BaseOrderlyKeyPair;
57
+ getAccountId(): string;
58
+ setAccountId(accountId: string): void;
59
+ getAddress(): string;
60
+ setAddress(address: string): void;
34
61
  setKey(orderlyKey: string, secretKey: string): void;
62
+ cleanAllKey(): void;
63
+ cleanKey(key: string): void;
35
64
  }
36
65
 
37
66
  type MessageFactor = {
@@ -61,10 +90,14 @@ type SignedMessagePayload = {
61
90
  */
62
91
  interface Signer {
63
92
  sign: (data: MessageFactor) => Promise<SignedMessagePayload>;
93
+ signText: (text: string) => Promise<{
94
+ signature: string;
95
+ publicKey: string;
96
+ }>;
64
97
  }
65
98
  declare class BaseSigner implements Signer {
66
99
  private readonly keyStore;
67
- constructor(keyStore: KeyStore);
100
+ constructor(keyStore: OrderlyKeyStore);
68
101
  sign(message: MessageFactor): Promise<SignedMessagePayload>;
69
102
  signText(text: string): Promise<{
70
103
  signature: string;
@@ -101,49 +134,13 @@ declare class SimpleDI {
101
134
  private constructor();
102
135
  }
103
136
 
104
- interface WalletClient {
105
- get address(): string;
106
- getBalance: () => Promise<any>;
107
- deposit: () => Promise<any>;
108
- connect: () => Promise<any>;
109
- }
110
- declare abstract class BaseWalletClient implements WalletClient {
111
- private readonly _address;
112
- constructor(_address: string);
113
- abstract getBalance(): Promise<any>;
114
- abstract deposit(): Promise<any>;
115
- abstract connect(): Promise<any>;
116
- get address(): string;
117
- }
118
- declare class SimpleWallet extends BaseWalletClient {
119
- getBalance(): Promise<any>;
120
- deposit(): Promise<any>;
121
- connect(): Promise<any>;
122
- }
123
-
124
- type wallet_BaseWalletClient = BaseWalletClient;
125
- declare const wallet_BaseWalletClient: typeof BaseWalletClient;
126
- type wallet_SimpleWallet = SimpleWallet;
127
- declare const wallet_SimpleWallet: typeof SimpleWallet;
128
- type wallet_WalletClient = WalletClient;
129
- declare namespace wallet {
130
- export {
131
- wallet_BaseWalletClient as BaseWalletClient,
132
- wallet_SimpleWallet as SimpleWallet,
133
- wallet_WalletClient as WalletClient,
134
- };
137
+ interface WalletAdapter {
138
+ getBalance: (address: string) => Promise<any>;
139
+ deposit: (from: string, to: string, amount: string) => Promise<any>;
135
140
  }
136
141
 
137
- type AccountStatus = "NotConnected" | "Connected" | "NotSignedIn" | "SignedIn";
138
- declare enum AccountStatusEnum {
139
- NotConnected = 0,
140
- Connected = 1,
141
- NotSignedIn = 2,
142
- SignedIn = 3,
143
- EnableTrading = 4
144
- }
145
142
  interface AccountState {
146
- status: AccountStatus;
143
+ status: AccountStatusEnum;
147
144
  accountId?: string;
148
145
  userId?: string;
149
146
  address?: string;
@@ -162,9 +159,11 @@ interface AccountState {
162
159
  */
163
160
  declare class Account {
164
161
  private readonly configStore;
165
- private walletClient?;
162
+ private readonly keyStore;
163
+ private readonly walletClient;
164
+ private _singer?;
166
165
  private _state$;
167
- constructor(configStore: ConfigStore, walletClient?: WalletClient | undefined);
166
+ constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, walletClient: WalletAdapter);
168
167
  /**
169
168
  * 登录
170
169
  * @param address 钱包地址
@@ -177,9 +176,10 @@ declare class Account {
177
176
  /**
178
177
  * 为账户设置钱包
179
178
  */
180
- set wallet(wallet: WalletClient | string);
179
+ set address(address: string);
181
180
  get state$(): BehaviorSubject<AccountState>;
182
181
  get stateValue(): AccountState;
182
+ get accountId(): string | undefined;
183
183
  /**
184
184
  * set user positions count
185
185
  */
@@ -187,6 +187,7 @@ declare class Account {
187
187
  set orders(orders: string[]);
188
188
  private _checkAccount;
189
189
  private _checkAccountExist;
190
+ get signer(): Signer;
190
191
  private getAccountInfo;
191
192
  private getBalance;
192
193
  private _fetch;
@@ -320,4 +321,11 @@ declare namespace WSMessage {
320
321
  }
321
322
  }
322
323
 
323
- export { API, Account, AccountState, AccountStatusEnum, BaseSigner, ConfigStore, KeyStore, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, getDefaultSigner, getMockSigner, wallet };
324
+ declare class Web3WalletAdapter implements Web3WalletAdapter {
325
+ private readonly web3;
326
+ constructor(web3: any);
327
+ getBalance(address: string): Promise<any>;
328
+ deposit(from: string, to: string, amount: string): Promise<any>;
329
+ }
330
+
331
+ export { API, Account, AccountState, BaseKeyStore, BaseSigner, ConfigStore, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, WalletAdapter, Web3WalletAdapter, getDefaultSigner, getMockSigner };