@orderly.network/core 0.0.8 → 0.0.10

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
@@ -8,46 +8,50 @@ interface OrderlyKeyPair {
8
8
  }
9
9
  declare class BaseOrderlyKeyPair implements OrderlyKeyPair {
10
10
  secretKey: string;
11
+ private privateKey;
12
+ static generateKey(): OrderlyKeyPair;
11
13
  constructor(secretKey: string);
12
14
  sign(message: Uint8Array): Promise<Uint8Array>;
13
15
  getPublicKey(): Promise<string>;
14
16
  }
15
17
 
16
18
  interface OrderlyKeyStore {
17
- getOrderlyKey: () => OrderlyKeyPair;
18
- getAccountId: () => string | undefined;
19
- setAccountId: (accountId: string) => void;
20
- getAddress: () => string | undefined;
19
+ getOrderlyKey: (address?: string) => OrderlyKeyPair | null;
20
+ getAccountId: (address: string) => string | undefined | null;
21
+ setAccountId: (address: string, accountId: string) => void;
22
+ getAddress: () => string | undefined | null;
21
23
  setAddress: (address: string) => void;
22
24
  generateKey: () => OrderlyKeyPair;
23
- cleanKey: (key: string) => void;
24
- cleanAllKey: () => void;
25
- setKey: (orderlyKey: string, secretKey: string) => void;
25
+ cleanKey: (address: string, key: string) => void;
26
+ cleanAllKey: (address: string) => void;
27
+ setKey: (orderlyKey: string, secretKey: OrderlyKeyPair) => void;
26
28
  }
27
29
  declare abstract class BaseKeyStore implements OrderlyKeyStore {
28
30
  private readonly networkId;
29
- constructor(networkId: string);
30
- abstract getOrderlyKey(): OrderlyKeyPair;
31
- abstract getAccountId(): string | undefined;
32
- abstract setAccountId(accountId: string): void;
33
- abstract getAddress(): string | undefined;
31
+ constructor(networkId?: string);
32
+ abstract getOrderlyKey(address?: string): OrderlyKeyPair | null;
33
+ abstract getAccountId(address: string): string | undefined | null;
34
+ abstract setAccountId(address: string, accountId: string): void;
35
+ abstract getAddress(): string | undefined | null;
34
36
  abstract setAddress(address: string): void;
35
37
  abstract generateKey(): OrderlyKeyPair;
36
- abstract setKey(orderlyKey: string, secretKey: string): void;
37
- abstract cleanAllKey(): void;
38
- abstract cleanKey(key: string): void;
38
+ abstract setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
39
+ abstract cleanAllKey(address: string): void;
40
+ abstract cleanKey(address: string, key: string): void;
39
41
  protected get keyPrefix(): string;
40
42
  }
41
43
  declare class LocalStorageStore extends BaseKeyStore {
42
- getOrderlyKey(): OrderlyKeyPair;
43
- getAccountId(): string;
44
- setAccountId(accountId: string): void;
45
- getAddress(): string;
44
+ getOrderlyKey(address?: string): OrderlyKeyPair | null;
45
+ getAccountId(address: string): string | undefined | null;
46
+ setAccountId(address: string, accountId: string): void;
47
+ getAddress(): string | undefined | null;
46
48
  setAddress(address: string): void;
47
- generateKey(): BaseOrderlyKeyPair;
48
- setKey(orderlyKey: string, secretKey: string): void;
49
- cleanAllKey(): void;
50
- cleanKey(key: string): void;
49
+ generateKey(): OrderlyKeyPair;
50
+ setKey(address: string, orderlyKey: OrderlyKeyPair): void;
51
+ cleanAllKey(address: string): void;
52
+ cleanKey(address: string, key: string): void;
53
+ private setItem;
54
+ private getItem;
51
55
  }
52
56
  declare class MockKeyStore implements OrderlyKeyStore {
53
57
  private readonly secretKey;
@@ -58,7 +62,7 @@ declare class MockKeyStore implements OrderlyKeyStore {
58
62
  setAccountId(accountId: string): void;
59
63
  getAddress(): string;
60
64
  setAddress(address: string): void;
61
- setKey(orderlyKey: string, secretKey: string): void;
65
+ setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
62
66
  cleanAllKey(): void;
63
67
  cleanKey(key: string): void;
64
68
  }
@@ -72,6 +76,7 @@ type SignedMessagePayload = {
72
76
  "orderly-key": string;
73
77
  "orderly-timestamp": string;
74
78
  "orderly-signature": string;
79
+ "orderly-account-id"?: string;
75
80
  };
76
81
  /**
77
82
  * 签名
@@ -111,13 +116,21 @@ interface ConfigStore {
111
116
  clear(): void;
112
117
  }
113
118
  declare class MemoryConfigStore implements ConfigStore {
114
- private map;
119
+ protected map: Map<string, any>;
115
120
  constructor();
116
- private _restore;
121
+ protected _restore(): void;
117
122
  get<T>(key: string): T;
118
123
  set<T>(key: string, value: T): void;
119
124
  clear(): void;
120
125
  }
126
+ /**
127
+ *
128
+ */
129
+ declare class BaseConfigStore extends MemoryConfigStore {
130
+ private readonly configMap;
131
+ constructor(configMap: Record<string, any>);
132
+ protected _restore(): void;
133
+ }
121
134
 
122
135
  declare const getMockSigner: (secretKey?: string) => BaseSigner;
123
136
  declare const getDefaultSigner: () => BaseSigner;
@@ -137,6 +150,7 @@ declare class SimpleDI {
137
150
  interface WalletAdapter {
138
151
  getBalance: (address: string) => Promise<any>;
139
152
  deposit: (from: string, to: string, amount: string) => Promise<any>;
153
+ send: (method: string, params: Array<any> | Record<string, any>) => Promise<any>;
140
154
  }
141
155
 
142
156
  interface AccountState {
@@ -160,10 +174,14 @@ interface AccountState {
160
174
  declare class Account {
161
175
  private readonly configStore;
162
176
  private readonly keyStore;
163
- private readonly walletClient;
177
+ private readonly walletAdapterClass;
178
+ static instanceName: string;
164
179
  private _singer?;
165
180
  private _state$;
166
- constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, walletClient: WalletAdapter);
181
+ private walletClient?;
182
+ constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, walletAdapterClass: {
183
+ new (options: any): WalletAdapter;
184
+ });
167
185
  /**
168
186
  * 登录
169
187
  * @param address 钱包地址
@@ -173,10 +191,13 @@ declare class Account {
173
191
  /**
174
192
  * 连接钱包先用第三方的React版本,不用自己实现
175
193
  */
176
- /**
177
- * 为账户设置钱包
178
- */
179
- set address(address: string);
194
+ setAddress(address: string, wallet?: {
195
+ provider: any;
196
+ chain: {
197
+ id: string;
198
+ };
199
+ [key: string]: any;
200
+ }): Promise<AccountStatusEnum>;
180
201
  get state$(): BehaviorSubject<AccountState>;
181
202
  get stateValue(): AccountState;
182
203
  get accountId(): string | undefined;
@@ -187,10 +208,15 @@ declare class Account {
187
208
  set orders(orders: string[]);
188
209
  private _checkAccount;
189
210
  private _checkAccountExist;
211
+ createAccount(): Promise<any>;
212
+ createOrderlyKey(expiration: number): Promise<any>;
213
+ disconnect(): Promise<void>;
214
+ private _checkOrderlyKeyState;
190
215
  get signer(): Signer;
191
216
  private getAccountInfo;
192
217
  private getBalance;
193
- private _fetch;
218
+ private _getRegisterationNonce;
219
+ private _simpleFetch;
194
220
  }
195
221
 
196
222
  declare namespace API {
@@ -321,11 +347,34 @@ declare namespace WSMessage {
321
347
  }
322
348
  }
323
349
 
324
- declare class Web3WalletAdapter implements Web3WalletAdapter {
350
+ declare class Web3WalletAdapter implements WalletAdapter {
325
351
  private readonly web3;
326
352
  constructor(web3: any);
327
353
  getBalance(address: string): Promise<any>;
328
354
  deposit(from: string, to: string, amount: string): Promise<any>;
355
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
356
+ }
357
+
358
+ interface EtherAdapterOptions {
359
+ provider: any;
360
+ label?: string;
361
+ chain: {
362
+ id: string;
363
+ };
364
+ }
365
+ declare class EtherAdapter implements WalletAdapter {
366
+ private provider?;
367
+ private _chainId;
368
+ constructor(options: EtherAdapterOptions);
369
+ getBalance(address: string): Promise<any>;
370
+ deposit(from: string, to: string, amount: string): Promise<any>;
371
+ get chainId(): number;
372
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
373
+ verify(data: {
374
+ domain: any;
375
+ message: any;
376
+ types: any;
377
+ }, signature: string): Promise<void>;
329
378
  }
330
379
 
331
- export { API, Account, AccountState, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigStore, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, WalletAdapter, Web3WalletAdapter, getDefaultSigner, getMockSigner };
380
+ export { API, Account, AccountState, BaseConfigStore, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigStore, EtherAdapter, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, WalletAdapter, Web3WalletAdapter, getDefaultSigner, getMockSigner };
package/dist/index.d.ts CHANGED
@@ -8,46 +8,50 @@ interface OrderlyKeyPair {
8
8
  }
9
9
  declare class BaseOrderlyKeyPair implements OrderlyKeyPair {
10
10
  secretKey: string;
11
+ private privateKey;
12
+ static generateKey(): OrderlyKeyPair;
11
13
  constructor(secretKey: string);
12
14
  sign(message: Uint8Array): Promise<Uint8Array>;
13
15
  getPublicKey(): Promise<string>;
14
16
  }
15
17
 
16
18
  interface OrderlyKeyStore {
17
- getOrderlyKey: () => OrderlyKeyPair;
18
- getAccountId: () => string | undefined;
19
- setAccountId: (accountId: string) => void;
20
- getAddress: () => string | undefined;
19
+ getOrderlyKey: (address?: string) => OrderlyKeyPair | null;
20
+ getAccountId: (address: string) => string | undefined | null;
21
+ setAccountId: (address: string, accountId: string) => void;
22
+ getAddress: () => string | undefined | null;
21
23
  setAddress: (address: string) => void;
22
24
  generateKey: () => OrderlyKeyPair;
23
- cleanKey: (key: string) => void;
24
- cleanAllKey: () => void;
25
- setKey: (orderlyKey: string, secretKey: string) => void;
25
+ cleanKey: (address: string, key: string) => void;
26
+ cleanAllKey: (address: string) => void;
27
+ setKey: (orderlyKey: string, secretKey: OrderlyKeyPair) => void;
26
28
  }
27
29
  declare abstract class BaseKeyStore implements OrderlyKeyStore {
28
30
  private readonly networkId;
29
- constructor(networkId: string);
30
- abstract getOrderlyKey(): OrderlyKeyPair;
31
- abstract getAccountId(): string | undefined;
32
- abstract setAccountId(accountId: string): void;
33
- abstract getAddress(): string | undefined;
31
+ constructor(networkId?: string);
32
+ abstract getOrderlyKey(address?: string): OrderlyKeyPair | null;
33
+ abstract getAccountId(address: string): string | undefined | null;
34
+ abstract setAccountId(address: string, accountId: string): void;
35
+ abstract getAddress(): string | undefined | null;
34
36
  abstract setAddress(address: string): void;
35
37
  abstract generateKey(): OrderlyKeyPair;
36
- abstract setKey(orderlyKey: string, secretKey: string): void;
37
- abstract cleanAllKey(): void;
38
- abstract cleanKey(key: string): void;
38
+ abstract setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
39
+ abstract cleanAllKey(address: string): void;
40
+ abstract cleanKey(address: string, key: string): void;
39
41
  protected get keyPrefix(): string;
40
42
  }
41
43
  declare class LocalStorageStore extends BaseKeyStore {
42
- getOrderlyKey(): OrderlyKeyPair;
43
- getAccountId(): string;
44
- setAccountId(accountId: string): void;
45
- getAddress(): string;
44
+ getOrderlyKey(address?: string): OrderlyKeyPair | null;
45
+ getAccountId(address: string): string | undefined | null;
46
+ setAccountId(address: string, accountId: string): void;
47
+ getAddress(): string | undefined | null;
46
48
  setAddress(address: string): void;
47
- generateKey(): BaseOrderlyKeyPair;
48
- setKey(orderlyKey: string, secretKey: string): void;
49
- cleanAllKey(): void;
50
- cleanKey(key: string): void;
49
+ generateKey(): OrderlyKeyPair;
50
+ setKey(address: string, orderlyKey: OrderlyKeyPair): void;
51
+ cleanAllKey(address: string): void;
52
+ cleanKey(address: string, key: string): void;
53
+ private setItem;
54
+ private getItem;
51
55
  }
52
56
  declare class MockKeyStore implements OrderlyKeyStore {
53
57
  private readonly secretKey;
@@ -58,7 +62,7 @@ declare class MockKeyStore implements OrderlyKeyStore {
58
62
  setAccountId(accountId: string): void;
59
63
  getAddress(): string;
60
64
  setAddress(address: string): void;
61
- setKey(orderlyKey: string, secretKey: string): void;
65
+ setKey(orderlyKey: string, secretKey: OrderlyKeyPair): void;
62
66
  cleanAllKey(): void;
63
67
  cleanKey(key: string): void;
64
68
  }
@@ -72,6 +76,7 @@ type SignedMessagePayload = {
72
76
  "orderly-key": string;
73
77
  "orderly-timestamp": string;
74
78
  "orderly-signature": string;
79
+ "orderly-account-id"?: string;
75
80
  };
76
81
  /**
77
82
  * 签名
@@ -111,13 +116,21 @@ interface ConfigStore {
111
116
  clear(): void;
112
117
  }
113
118
  declare class MemoryConfigStore implements ConfigStore {
114
- private map;
119
+ protected map: Map<string, any>;
115
120
  constructor();
116
- private _restore;
121
+ protected _restore(): void;
117
122
  get<T>(key: string): T;
118
123
  set<T>(key: string, value: T): void;
119
124
  clear(): void;
120
125
  }
126
+ /**
127
+ *
128
+ */
129
+ declare class BaseConfigStore extends MemoryConfigStore {
130
+ private readonly configMap;
131
+ constructor(configMap: Record<string, any>);
132
+ protected _restore(): void;
133
+ }
121
134
 
122
135
  declare const getMockSigner: (secretKey?: string) => BaseSigner;
123
136
  declare const getDefaultSigner: () => BaseSigner;
@@ -137,6 +150,7 @@ declare class SimpleDI {
137
150
  interface WalletAdapter {
138
151
  getBalance: (address: string) => Promise<any>;
139
152
  deposit: (from: string, to: string, amount: string) => Promise<any>;
153
+ send: (method: string, params: Array<any> | Record<string, any>) => Promise<any>;
140
154
  }
141
155
 
142
156
  interface AccountState {
@@ -160,10 +174,14 @@ interface AccountState {
160
174
  declare class Account {
161
175
  private readonly configStore;
162
176
  private readonly keyStore;
163
- private readonly walletClient;
177
+ private readonly walletAdapterClass;
178
+ static instanceName: string;
164
179
  private _singer?;
165
180
  private _state$;
166
- constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, walletClient: WalletAdapter);
181
+ private walletClient?;
182
+ constructor(configStore: ConfigStore, keyStore: OrderlyKeyStore, walletAdapterClass: {
183
+ new (options: any): WalletAdapter;
184
+ });
167
185
  /**
168
186
  * 登录
169
187
  * @param address 钱包地址
@@ -173,10 +191,13 @@ declare class Account {
173
191
  /**
174
192
  * 连接钱包先用第三方的React版本,不用自己实现
175
193
  */
176
- /**
177
- * 为账户设置钱包
178
- */
179
- set address(address: string);
194
+ setAddress(address: string, wallet?: {
195
+ provider: any;
196
+ chain: {
197
+ id: string;
198
+ };
199
+ [key: string]: any;
200
+ }): Promise<AccountStatusEnum>;
180
201
  get state$(): BehaviorSubject<AccountState>;
181
202
  get stateValue(): AccountState;
182
203
  get accountId(): string | undefined;
@@ -187,10 +208,15 @@ declare class Account {
187
208
  set orders(orders: string[]);
188
209
  private _checkAccount;
189
210
  private _checkAccountExist;
211
+ createAccount(): Promise<any>;
212
+ createOrderlyKey(expiration: number): Promise<any>;
213
+ disconnect(): Promise<void>;
214
+ private _checkOrderlyKeyState;
190
215
  get signer(): Signer;
191
216
  private getAccountInfo;
192
217
  private getBalance;
193
- private _fetch;
218
+ private _getRegisterationNonce;
219
+ private _simpleFetch;
194
220
  }
195
221
 
196
222
  declare namespace API {
@@ -321,11 +347,34 @@ declare namespace WSMessage {
321
347
  }
322
348
  }
323
349
 
324
- declare class Web3WalletAdapter implements Web3WalletAdapter {
350
+ declare class Web3WalletAdapter implements WalletAdapter {
325
351
  private readonly web3;
326
352
  constructor(web3: any);
327
353
  getBalance(address: string): Promise<any>;
328
354
  deposit(from: string, to: string, amount: string): Promise<any>;
355
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
356
+ }
357
+
358
+ interface EtherAdapterOptions {
359
+ provider: any;
360
+ label?: string;
361
+ chain: {
362
+ id: string;
363
+ };
364
+ }
365
+ declare class EtherAdapter implements WalletAdapter {
366
+ private provider?;
367
+ private _chainId;
368
+ constructor(options: EtherAdapterOptions);
369
+ getBalance(address: string): Promise<any>;
370
+ deposit(from: string, to: string, amount: string): Promise<any>;
371
+ get chainId(): number;
372
+ send(method: string, params: Array<any> | Record<string, any>): Promise<any>;
373
+ verify(data: {
374
+ domain: any;
375
+ message: any;
376
+ types: any;
377
+ }, signature: string): Promise<void>;
329
378
  }
330
379
 
331
- export { API, Account, AccountState, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigStore, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, WalletAdapter, Web3WalletAdapter, getDefaultSigner, getMockSigner };
380
+ export { API, Account, AccountState, BaseConfigStore, BaseKeyStore, BaseOrderlyKeyPair, BaseSigner, ConfigStore, EtherAdapter, LocalStorageStore, MemoryConfigStore, MessageFactor, MockKeyStore, OrderlyKeyPair, OrderlyKeyStore, SignedMessagePayload, Signer, SimpleDI, WSMessage, WalletAdapter, Web3WalletAdapter, getDefaultSigner, getMockSigner };